Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
[move-compiler] Fixed the UnitTest module check (#17060)
Browse files Browse the repository at this point in the history
## Description 

The `UnitTest` module check should also take pre-compiled libraries into
consideration

## Test Plan 

Verified that the missing `UnitTest` module diag is no longer
incorrectly produced when pre-compiled libs are inspected
  • Loading branch information
awelc authored Apr 4, 2024
1 parent b4b9f1f commit 17965ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
6 changes: 5 additions & 1 deletion crates/move-compiler/src/command_line/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,11 @@ fn run(
match cur {
PassResult::Parser(prog) => {
let eprog = {
let prog = unit_test::filter_test_members::program(compilation_env, prog);
let prog = unit_test::filter_test_members::program(
compilation_env,
pre_compiled_lib.clone(),
prog,
);
let prog = verification_attribute_filter::program(compilation_env, prog);
expansion::translate::program(compilation_env, pre_compiled_lib.clone(), prog)
};
Expand Down
27 changes: 21 additions & 6 deletions crates/move-compiler/src/unit_test/filter_test_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use move_ir_types::location::{sp, Loc};
use move_symbol_pool::Symbol;

use crate::{
command_line::compiler::FullyCompiledProgram,
diag,
parser::{
ast::{self as P, NamePath, PathEntry},
Expand All @@ -14,6 +15,8 @@ use crate::{
shared::{known_attributes, CompilationEnv},
};

use std::sync::Arc;

struct Context<'env> {
env: &'env mut CompilationEnv,
is_source_def: bool,
Expand Down Expand Up @@ -84,8 +87,12 @@ const STDLIB_ADDRESS_NAME: Symbol = symbol!("std");
// This filters out all test, and test-only annotated module member from `prog` if the `test` flag
// in `compilation_env` is not set. If the test flag is set, no filtering is performed, and instead
// a test plan is created for use by the testing framework.
pub fn program(compilation_env: &mut CompilationEnv, prog: P::Program) -> P::Program {
if !check_has_unit_test_module(compilation_env, &prog) {
pub fn program(
compilation_env: &mut CompilationEnv,
pre_compiled_lib: Option<Arc<FullyCompiledProgram>>,
prog: P::Program,
) -> P::Program {
if !check_has_unit_test_module(compilation_env, pre_compiled_lib, &prog) {
return prog;
}

Expand All @@ -94,9 +101,8 @@ pub fn program(compilation_env: &mut CompilationEnv, prog: P::Program) -> P::Pro
filter_program(&mut context, prog)
}

fn check_has_unit_test_module(compilation_env: &mut CompilationEnv, prog: &P::Program) -> bool {
let has_unit_test_module = prog
.lib_definitions
fn has_unit_test_module(prog: &P::Program) -> bool {
prog.lib_definitions
.iter()
.chain(prog.source_definitions.iter())
.any(|pkg| match &pkg.def {
Expand All @@ -113,7 +119,16 @@ fn check_has_unit_test_module(compilation_env: &mut CompilationEnv, prog: &P::Pr
}
}
_ => false,
});
})
}

fn check_has_unit_test_module(
compilation_env: &mut CompilationEnv,
pre_compiled_lib: Option<Arc<FullyCompiledProgram>>,
prog: &P::Program,
) -> bool {
let has_unit_test_module = has_unit_test_module(prog)
|| pre_compiled_lib.is_some_and(|p| has_unit_test_module(&p.parser));

if !has_unit_test_module && compilation_env.flags().is_testing() {
if let Some(P::PackageDefinition { def, .. }) = prog
Expand Down

0 comments on commit 17965ca

Please sign in to comment.