From 998113c9a0b91a1abb720f2779854b4a48e2d420 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Fri, 8 Nov 2024 13:01:42 -0500 Subject: [PATCH 1/9] fix bytecode deps for unit tests --- aptos-move/framework/src/built_package.rs | 6 ++--- .../move/move-compiler/src/unit_test/mod.rs | 21 ++++++++++++++++-- .../move/tools/move-cli/src/base/test.rs | 4 ++-- .../src/compilation/compiled_package.rs | 11 +++++----- .../tools/move-unit-test/src/test_reporter.rs | 22 ++++++++++++------- .../tools/move-unit-test/src/test_runner.rs | 7 ++++-- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/aptos-move/framework/src/built_package.rs b/aptos-move/framework/src/built_package.rs index 1a7d5edfb3d9f..76ec3bc7f9e98 100644 --- a/aptos-move/framework/src/built_package.rs +++ b/aptos-move/framework/src/built_package.rs @@ -18,7 +18,7 @@ use codespan_reporting::{ use itertools::Itertools; use move_binary_format::{file_format_common::VERSION_7, CompiledModule}; use move_command_line_common::files::MOVE_COMPILED_EXTENSION; -use move_compiler::compiled_unit::{CompiledUnit, NamedCompiledModule}; +use move_compiler::{compiled_unit::{CompiledUnit, NamedCompiledModule}, shared::NumericalAddress}; use move_compiler_v2::{external_checks::ExternalChecks, options::Options, Experiment}; use move_core_types::{language_storage::ModuleId, metadata::Metadata}; use move_model::{ @@ -507,8 +507,8 @@ impl BuiltPackage { self.package .bytecode_deps .iter() - .map(|(name, address)| PackageDep { - account: address.into_inner(), + .map(|(name, module)| PackageDep { + account: NumericalAddress::from_account_address(*module.self_addr()).into_inner(), package_name: name.as_str().to_string(), }), ) diff --git a/third_party/move/move-compiler/src/unit_test/mod.rs b/third_party/move/move-compiler/src/unit_test/mod.rs index 62c6380ef00b3..c12a270021966 100644 --- a/third_party/move/move-compiler/src/unit_test/mod.rs +++ b/third_party/move/move-compiler/src/unit_test/mod.rs @@ -7,10 +7,12 @@ use crate::{ diagnostics::FilesSourceText, shared::NumericalAddress, }; +use move_binary_format::CompiledModule; use move_core_types::{ account_address::AccountAddress, identifier::Identifier, language_storage::ModuleId, value::MoveValue, vm_status::StatusCode, }; +use move_symbol_pool::Symbol; use std::{collections::BTreeMap, fmt}; pub mod filter_test_members; @@ -18,11 +20,22 @@ pub mod plan_builder; pub type TestName = String; +#[derive(Debug, Clone)] +pub enum NamedOrBytecodeModule { + // Compiled from source + Named(NamedCompiledModule), + // Bytecode dependency + Bytecode(CompiledModule), +} + #[derive(Debug, Clone)] pub struct TestPlan { pub files: FilesSourceText, pub module_tests: BTreeMap, - pub module_info: BTreeMap, + // `NamedCompiledModule` for compiled modules with source, + // `CompiledModule` for modules with bytecode only + // pub module_info: BTreeMap>, + pub module_info: BTreeMap, } #[derive(Debug, Clone)] @@ -85,6 +98,7 @@ impl TestPlan { tests: Vec, files: FilesSourceText, units: Vec, + bytecode_modules: BTreeMap, ) -> Self { let module_tests: BTreeMap<_, _> = tests .into_iter() @@ -97,12 +111,15 @@ impl TestPlan { if let AnnotatedCompiledUnit::Module(annot_module) = unit { Some(( annot_module.named_module.module.self_id(), - annot_module.named_module, + NamedOrBytecodeModule::Named(annot_module.named_module), )) } else { None } }) + .chain(bytecode_modules.into_iter().map(|(_name, module)| { + (module.self_id(), NamedOrBytecodeModule::Bytecode(module)) + })) .collect(); Self { diff --git a/third_party/move/tools/move-cli/src/base/test.rs b/third_party/move/tools/move-cli/src/base/test.rs index 955e32a8ed8f0..2f65f94c2cba2 100644 --- a/third_party/move/tools/move-cli/src/base/test.rs +++ b/third_party/move/tools/move-cli/src/base/test.rs @@ -241,7 +241,7 @@ pub fn run_move_unit_tests_with_factory, /// Bytecode dependencies of this compiled package - pub bytecode_deps: BTreeMap, + pub bytecode_deps: BTreeMap, // Optional artifacts from compilation // @@ -809,8 +809,8 @@ impl CompiledPackage { .flat_map(|package| { let name = package.name.unwrap(); package.paths.iter().map(move |pkg_path| { - get_addr_from_module_in_package(name, pkg_path.as_str()) - .map(|addr| (name, addr)) + get_module_in_package(name, pkg_path.as_str()) + .map(|module| (name, module)) }) }) .try_collect()?, @@ -1166,8 +1166,8 @@ pub fn build_and_report_no_exit_v2_driver( )) } -/// Returns the address of the module -fn get_addr_from_module_in_package(pkg_name: Symbol, pkg_path: &str) -> Result { +/// Returns the deserialized module from the bytecode file +fn get_module_in_package(pkg_name: Symbol, pkg_path: &str) -> Result { // Read the bytecode file let mut bytecode = Vec::new(); std::fs::File::open(pkg_path) @@ -1183,5 +1183,4 @@ fn get_addr_from_module_in_package(pkg_name: Symbol, pkg_path: &str) -> Result return "\tmalformed stack trace (no module ID)".to_string(), }; let named_module = match test_plan.module_info.get(module_id) { - Some(v) => v, + Some(NamedOrBytecodeModule::Named(v)) => v, + Some(NamedOrBytecodeModule::Bytecode(_)) => { + return "\tno source map for bytecode module".to_string() + }, None => return "\tmalformed stack trace (no module)".to_string(), }; let function_source_map = @@ -408,12 +411,15 @@ impl TestFailure { let mut diags = match vm_error.location() { Location::Module(module_id) => { let diag_opt = vm_error.offsets().first().and_then(|(fdef_idx, offset)| { - let function_source_map = test_plan - .module_info - .get(module_id)? - .source_map - .get_function_source_map(*fdef_idx) - .ok()?; + let function_source_map = match test_plan.module_info.get(module_id)? { + NamedOrBytecodeModule::Named(named_compiled_module) => { + named_compiled_module + .source_map + .get_function_source_map(*fdef_idx) + .ok()? + }, + NamedOrBytecodeModule::Bytecode(_compiled_module) => return None, + }; let loc = function_source_map.get_code_location(*offset).unwrap(); let msg = format!("In this function in {}", format_module_id(module_id)); // TODO(tzakian) maybe migrate off of move-langs diagnostics? diff --git a/third_party/move/tools/move-unit-test/src/test_runner.rs b/third_party/move/tools/move-unit-test/src/test_runner.rs index 03ea88601103e..da74075141b32 100644 --- a/third_party/move/tools/move-unit-test/src/test_runner.rs +++ b/third_party/move/tools/move-unit-test/src/test_runner.rs @@ -13,7 +13,7 @@ use anyhow::Result; use colored::*; use move_binary_format::{errors::VMResult, file_format::CompiledModule}; use move_bytecode_utils::Modules; -use move_compiler::unit_test::{ExpectedFailure, ModuleTestPlan, TestCase, TestPlan}; +use move_compiler::unit_test::{ExpectedFailure, ModuleTestPlan, NamedOrBytecodeModule, TestCase, TestPlan}; use move_core_types::{ account_address::AccountAddress, effects::{ChangeSet, Op}, @@ -131,7 +131,10 @@ impl TestRunner { .values() .map(|(filepath, _)| filepath.to_string()) .collect(); - let modules = tests.module_info.values().map(|info| &info.module); + let modules = tests.module_info.values().map(|info| match info { + NamedOrBytecodeModule::Named(named_compiled_module) => &named_compiled_module.module, + NamedOrBytecodeModule::Bytecode(compiled_module) => compiled_module, + }); let mut starting_storage_state = setup_test_storage(modules)?; if let Some(genesis_state) = genesis_state { starting_storage_state.apply(genesis_state)?; From 31575798d838f12e5c394a84bc83bc94a492be28 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Wed, 13 Nov 2024 01:57:39 -0500 Subject: [PATCH 2/9] add tests --- Cargo.lock | 2 + .../move/move-compiler/src/unit_test/mod.rs | 6 +- .../move/tools/move-cli/src/base/test.rs | 2 +- .../move/tools/move-unit-test/Cargo.toml | 4 ++ .../move/tools/move-unit-test/src/lib.rs | 12 ++-- .../tests/packages/dep/Move.toml | 4 ++ .../tests/packages/one-bytecode-dep/Move.toml | 14 +++++ .../one-bytecode-dep/sources/test.move | 9 +++ .../tools/move-unit-test/tests/pkg_tests.rs | 61 +++++++++++++++++++ 9 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 third_party/move/tools/move-unit-test/tests/packages/dep/Move.toml create mode 100644 third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/Move.toml create mode 100644 third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/sources/test.move create mode 100644 third_party/move/tools/move-unit-test/tests/pkg_tests.rs diff --git a/Cargo.lock b/Cargo.lock index 6248ce77ab1d7..8734ed2660892 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11876,6 +11876,7 @@ dependencies = [ "itertools 0.13.0", "move-binary-format", "move-bytecode-utils", + "move-cli", "move-command-line-common", "move-compiler", "move-compiler-v2", @@ -11895,6 +11896,7 @@ dependencies = [ "primitive-types 0.10.1", "rayon", "regex", + "tempfile", ] [[package]] diff --git a/third_party/move/move-compiler/src/unit_test/mod.rs b/third_party/move/move-compiler/src/unit_test/mod.rs index c12a270021966..84218f05a7e9e 100644 --- a/third_party/move/move-compiler/src/unit_test/mod.rs +++ b/third_party/move/move-compiler/src/unit_test/mod.rs @@ -12,7 +12,6 @@ use move_core_types::{ account_address::AccountAddress, identifier::Identifier, language_storage::ModuleId, value::MoveValue, vm_status::StatusCode, }; -use move_symbol_pool::Symbol; use std::{collections::BTreeMap, fmt}; pub mod filter_test_members; @@ -34,7 +33,6 @@ pub struct TestPlan { pub module_tests: BTreeMap, // `NamedCompiledModule` for compiled modules with source, // `CompiledModule` for modules with bytecode only - // pub module_info: BTreeMap>, pub module_info: BTreeMap, } @@ -98,7 +96,7 @@ impl TestPlan { tests: Vec, files: FilesSourceText, units: Vec, - bytecode_modules: BTreeMap, + bytecode_modules: Vec, ) -> Self { let module_tests: BTreeMap<_, _> = tests .into_iter() @@ -117,7 +115,7 @@ impl TestPlan { None } }) - .chain(bytecode_modules.into_iter().map(|(_name, module)| { + .chain(bytecode_modules.into_iter().map(|module| { (module.self_id(), NamedOrBytecodeModule::Bytecode(module)) })) .collect(); diff --git a/third_party/move/tools/move-cli/src/base/test.rs b/third_party/move/tools/move-cli/src/base/test.rs index 2f65f94c2cba2..2241cbd7b0e90 100644 --- a/third_party/move/tools/move-cli/src/base/test.rs +++ b/third_party/move/tools/move-cli/src/base/test.rs @@ -306,7 +306,7 @@ pub fn run_move_unit_tests_with_factory, deps: Vec, ) -> Option { + println!("source_files: {:?}", source_files); + println!("deps: {:?}", deps); let addresses = verify_and_create_named_address_mapping(self.named_address_values.clone()).ok()?; let (test_plan, files, units) = if get_move_compiler_v2_from_env() { @@ -209,12 +211,10 @@ impl UnitTestingConfig { let compilation_result = compiler.at_cfgir(cfgir).build(); - let (units, warnings) = - diagnostics::unwrap_or_report_diagnostics(&files, compilation_result); - diagnostics::report_warnings(&files, warnings); - (test_plan, files, units) - }; - test_plan.map(|tests| TestPlan::new(tests, files, units)) + let (units, warnings) = + diagnostics::unwrap_or_report_diagnostics(&files, compilation_result); + diagnostics::report_warnings(&files, warnings); + test_plan.map(|tests| TestPlan::new(tests, files, units, Default::default())) } /// Build a test plan from a unit test config diff --git a/third_party/move/tools/move-unit-test/tests/packages/dep/Move.toml b/third_party/move/tools/move-unit-test/tests/packages/dep/Move.toml new file mode 100644 index 0000000000000..93fc7202832b3 --- /dev/null +++ b/third_party/move/tools/move-unit-test/tests/packages/dep/Move.toml @@ -0,0 +1,4 @@ +[package] +name = "Dep" +version = "1.0.0" +authors = [] diff --git a/third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/Move.toml b/third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/Move.toml new file mode 100644 index 0000000000000..baeb01824df07 --- /dev/null +++ b/third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/Move.toml @@ -0,0 +1,14 @@ +[package] +name = "unit-test" +version = "1.0.0" +authors = [] + +[addresses] + +[dev-addresses] + +[dependencies] +Dep = { local = "../dep" } +MoveStdlib = { local = "../../../../../../../aptos-move/framework/move-stdlib" } + +[dev-dependencies] diff --git a/third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/sources/test.move b/third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/sources/test.move new file mode 100644 index 0000000000000..8331d312bcc06 --- /dev/null +++ b/third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/sources/test.move @@ -0,0 +1,9 @@ +module 0x42::test { + #[test_only] + use 0x42::foo; + + #[test] + fun test() { + assert!(foo::foo() == 42, 0); + } +} diff --git a/third_party/move/tools/move-unit-test/tests/pkg_tests.rs b/third_party/move/tools/move-unit-test/tests/pkg_tests.rs new file mode 100644 index 0000000000000..bc1d3c17c80a6 --- /dev/null +++ b/third_party/move/tools/move-unit-test/tests/pkg_tests.rs @@ -0,0 +1,61 @@ +// Copyright (c) Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +use std::path::PathBuf; + +use move_cli::base::test::{run_move_unit_tests, UnitTestResult}; +use move_core_types::{account_address::AccountAddress, effects::ChangeSet}; +use move_model::metadata::CompilerVersion; +use move_package::CompilerConfig; +use move_stdlib::natives::{all_natives, GasParameters}; +use move_unit_test::UnitTestingConfig; +use tempfile::tempdir; + +pub fn path_in_crate(relative: S) -> PathBuf +where + S: Into, +{ + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.push(relative.into()); + path +} + +fn run_tests_for_pkg(path_to_pkg: impl Into, v2: bool) { + let pkg_path = path_in_crate(path_to_pkg); + println!("pkg_path: {:?}", pkg_path); + + let natives = all_natives( + AccountAddress::from_hex_literal("0x1").unwrap(), + GasParameters::zeros(), + ); + + let result = run_move_unit_tests( + &pkg_path, + move_package::BuildConfig { + test_mode: true, + install_dir: Some(tempdir().unwrap().path().to_path_buf()), + compiler_config: CompilerConfig { + compiler_version: if v2 { Some(CompilerVersion::latest()) } else { None }, + ..Default::default() + }, + ..Default::default() + }, + UnitTestingConfig::default(), + natives, + ChangeSet::new(), + /* gas_limit */ Some(100_000), + /* cost_table */ None, + /* compute_coverage */ false, + &mut std::io::stdout(), + ) + .unwrap(); + if result != UnitTestResult::Success { + panic!("aborting because of Move unit test failures"); + } +} + +#[test] +fn one_bytecode_dep() { + run_tests_for_pkg("tests/packages/one-bytecode-dep", true); + run_tests_for_pkg("tests/packages/one-bytecode-dep", false); +} From 65ded3e5a94ed478208360fc6094d37248644490 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Wed, 13 Nov 2024 02:07:31 -0500 Subject: [PATCH 3/9] linter & remove debug print --- aptos-move/framework/src/built_package.rs | 8 ++++++-- .../move/move-compiler/src/unit_test/mod.rs | 8 +++++--- .../move/tools/move-cli/src/base/test.rs | 7 ++++++- .../src/compilation/compiled_package.rs | 3 +-- .../tools/move-unit-test/src/test_runner.rs | 4 +++- .../tools/move-unit-test/tests/pkg_tests.rs | 18 ++++++++++-------- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/aptos-move/framework/src/built_package.rs b/aptos-move/framework/src/built_package.rs index 76ec3bc7f9e98..deed149e1b43a 100644 --- a/aptos-move/framework/src/built_package.rs +++ b/aptos-move/framework/src/built_package.rs @@ -18,7 +18,10 @@ use codespan_reporting::{ use itertools::Itertools; use move_binary_format::{file_format_common::VERSION_7, CompiledModule}; use move_command_line_common::files::MOVE_COMPILED_EXTENSION; -use move_compiler::{compiled_unit::{CompiledUnit, NamedCompiledModule}, shared::NumericalAddress}; +use move_compiler::{ + compiled_unit::{CompiledUnit, NamedCompiledModule}, + shared::NumericalAddress, +}; use move_compiler_v2::{external_checks::ExternalChecks, options::Options, Experiment}; use move_core_types::{language_storage::ModuleId, metadata::Metadata}; use move_model::{ @@ -508,7 +511,8 @@ impl BuiltPackage { .bytecode_deps .iter() .map(|(name, module)| PackageDep { - account: NumericalAddress::from_account_address(*module.self_addr()).into_inner(), + account: NumericalAddress::from_account_address(*module.self_addr()) + .into_inner(), package_name: name.as_str().to_string(), }), ) diff --git a/third_party/move/move-compiler/src/unit_test/mod.rs b/third_party/move/move-compiler/src/unit_test/mod.rs index 84218f05a7e9e..4751758ba6f53 100644 --- a/third_party/move/move-compiler/src/unit_test/mod.rs +++ b/third_party/move/move-compiler/src/unit_test/mod.rs @@ -115,9 +115,11 @@ impl TestPlan { None } }) - .chain(bytecode_modules.into_iter().map(|module| { - (module.self_id(), NamedOrBytecodeModule::Bytecode(module)) - })) + .chain( + bytecode_modules + .into_iter() + .map(|module| (module.self_id(), NamedOrBytecodeModule::Bytecode(module))), + ) .collect(); Self { diff --git a/third_party/move/tools/move-cli/src/base/test.rs b/third_party/move/tools/move-cli/src/base/test.rs index 2241cbd7b0e90..2c999c95f5069 100644 --- a/third_party/move/tools/move-cli/src/base/test.rs +++ b/third_party/move/tools/move-cli/src/base/test.rs @@ -306,7 +306,12 @@ pub fn run_move_unit_tests_with_factory(relative: S) -> PathBuf @@ -22,7 +21,6 @@ where fn run_tests_for_pkg(path_to_pkg: impl Into, v2: bool) { let pkg_path = path_in_crate(path_to_pkg); - println!("pkg_path: {:?}", pkg_path); let natives = all_natives( AccountAddress::from_hex_literal("0x1").unwrap(), @@ -34,10 +32,14 @@ fn run_tests_for_pkg(path_to_pkg: impl Into, v2: bool) { move_package::BuildConfig { test_mode: true, install_dir: Some(tempdir().unwrap().path().to_path_buf()), - compiler_config: CompilerConfig { - compiler_version: if v2 { Some(CompilerVersion::latest()) } else { None }, - ..Default::default() - }, + compiler_config: CompilerConfig { + compiler_version: if v2 { + Some(CompilerVersion::latest()) + } else { + None + }, + ..Default::default() + }, ..Default::default() }, UnitTestingConfig::default(), @@ -57,5 +59,5 @@ fn run_tests_for_pkg(path_to_pkg: impl Into, v2: bool) { #[test] fn one_bytecode_dep() { run_tests_for_pkg("tests/packages/one-bytecode-dep", true); - run_tests_for_pkg("tests/packages/one-bytecode-dep", false); + run_tests_for_pkg("tests/packages/one-bytecode-dep", false); } From c9868f8cda30c55130dc127c1d7b3215e63d4e56 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Wed, 13 Nov 2024 02:09:00 -0500 Subject: [PATCH 4/9] reset Cargo.lock --- Cargo.lock | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8734ed2660892..0d55f21370d6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11876,14 +11876,11 @@ dependencies = [ "itertools 0.13.0", "move-binary-format", "move-bytecode-utils", - "move-cli", "move-command-line-common", "move-compiler", "move-compiler-v2", "move-core-types", "move-ir-types", - "move-model", - "move-package", "move-resource-viewer", "move-stdlib", "move-symbol-pool", @@ -11896,7 +11893,6 @@ dependencies = [ "primitive-types 0.10.1", "rayon", "regex", - "tempfile", ] [[package]] From b2745496fe15d89168b11ee6df70dd91b7cffa50 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Wed, 13 Nov 2024 02:12:41 -0500 Subject: [PATCH 5/9] add bytecode files --- Cargo.lock | 4 ++ .../packages/dep/build/Dep/BuildInfo.yaml | 46 ++++++++++++++++++ .../dep/build/Dep/bytecode_modules/foo.mv | Bin 0 -> 118 bytes 3 files changed, 50 insertions(+) create mode 100644 third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/BuildInfo.yaml create mode 100644 third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/bytecode_modules/foo.mv diff --git a/Cargo.lock b/Cargo.lock index 0d55f21370d6b..8734ed2660892 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11876,11 +11876,14 @@ dependencies = [ "itertools 0.13.0", "move-binary-format", "move-bytecode-utils", + "move-cli", "move-command-line-common", "move-compiler", "move-compiler-v2", "move-core-types", "move-ir-types", + "move-model", + "move-package", "move-resource-viewer", "move-stdlib", "move-symbol-pool", @@ -11893,6 +11896,7 @@ dependencies = [ "primitive-types 0.10.1", "rayon", "regex", + "tempfile", ] [[package]] diff --git a/third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/BuildInfo.yaml b/third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/BuildInfo.yaml new file mode 100644 index 0000000000000..fd67676230af2 --- /dev/null +++ b/third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/BuildInfo.yaml @@ -0,0 +1,46 @@ +--- +compiled_package_info: + package_name: Dep + address_alias_instantiation: {} + source_digest: B01B575F8492F72C72DBF502E1F788F49A9CA8AC335FB9E52B0455ACA35677E0 + build_flags: + dev_mode: false + test_mode: false + override_std: ~ + generate_docs: false + generate_abis: false + generate_move_model: true + full_model_generation: false + install_dir: ~ + force_recompilation: false + additional_named_addresses: {} + architecture: ~ + fetch_deps_only: false + skip_fetch_latest_git_deps: false + compiler_config: + bytecode_version: 7 + known_attributes: + - bytecode_instruction + - deprecated + - event + - expected_failure + - "fmt::skip" + - legacy_entry_fun + - "lint::allow_unsafe_randomness" + - "lint::skip" + - "mutation::skip" + - native_interface + - randomness + - resource_group + - resource_group_member + - test + - test_only + - verify_only + - view + skip_attribute_checks: false + compiler_version: V2_0 + language_version: V2_1 + experiments: + - optimize=on +dependencies: [] +bytecode_deps: [] diff --git a/third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/bytecode_modules/foo.mv b/third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/bytecode_modules/foo.mv new file mode 100644 index 0000000000000000000000000000000000000000..50f81c51e974ecffa47bcab210c034614fae1f0f GIT binary patch literal 118 zcmZ1|^O~ETfq{#ik%5VsiH((mnVp-3gI_^FU!KR0lK})6L6C_#Ek7U3#Z5SgB Date: Wed, 13 Nov 2024 02:16:00 -0500 Subject: [PATCH 6/9] reset Cargo.lock --- Cargo.lock | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8734ed2660892..0d55f21370d6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11876,14 +11876,11 @@ dependencies = [ "itertools 0.13.0", "move-binary-format", "move-bytecode-utils", - "move-cli", "move-command-line-common", "move-compiler", "move-compiler-v2", "move-core-types", "move-ir-types", - "move-model", - "move-package", "move-resource-viewer", "move-stdlib", "move-symbol-pool", @@ -11896,7 +11893,6 @@ dependencies = [ "primitive-types 0.10.1", "rayon", "regex", - "tempfile", ] [[package]] From 898ee3a205c4aeac8197f345588c8d8d0b577230 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Wed, 13 Nov 2024 04:22:11 -0500 Subject: [PATCH 7/9] add .gitkeep for empty dir --- .../move/tools/move-unit-test/tests/packages/dep/sources/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 third_party/move/tools/move-unit-test/tests/packages/dep/sources/.gitkeep diff --git a/third_party/move/tools/move-unit-test/tests/packages/dep/sources/.gitkeep b/third_party/move/tools/move-unit-test/tests/packages/dep/sources/.gitkeep new file mode 100644 index 0000000000000..e69de29bb2d1d From 1e3e7e856420a0ea3d7e1b4fceb1ad869cdc113a Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Mon, 6 Jan 2025 12:06:59 -0500 Subject: [PATCH 8/9] address comments --- Cargo.lock | 4 ++++ third_party/move/tools/move-unit-test/src/lib.rs | 4 +--- third_party/move/tools/move-unit-test/tests/pkg_tests.rs | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0d55f21370d6b..8734ed2660892 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11876,11 +11876,14 @@ dependencies = [ "itertools 0.13.0", "move-binary-format", "move-bytecode-utils", + "move-cli", "move-command-line-common", "move-compiler", "move-compiler-v2", "move-core-types", "move-ir-types", + "move-model", + "move-package", "move-resource-viewer", "move-stdlib", "move-symbol-pool", @@ -11893,6 +11896,7 @@ dependencies = [ "primitive-types 0.10.1", "rayon", "regex", + "tempfile", ] [[package]] diff --git a/third_party/move/tools/move-unit-test/src/lib.rs b/third_party/move/tools/move-unit-test/src/lib.rs index f8477b915174f..5af0080a16e7b 100644 --- a/third_party/move/tools/move-unit-test/src/lib.rs +++ b/third_party/move/tools/move-unit-test/src/lib.rs @@ -159,8 +159,6 @@ impl UnitTestingConfig { source_files: Vec, deps: Vec, ) -> Option { - println!("source_files: {:?}", source_files); - println!("deps: {:?}", deps); let addresses = verify_and_create_named_address_mapping(self.named_address_values.clone()).ok()?; let (test_plan, files, units) = if get_move_compiler_v2_from_env() { @@ -214,7 +212,7 @@ impl UnitTestingConfig { let (units, warnings) = diagnostics::unwrap_or_report_diagnostics(&files, compilation_result); diagnostics::report_warnings(&files, warnings); - test_plan.map(|tests| TestPlan::new(tests, files, units, Default::default())) + test_plan.map(|tests| TestPlan::new(tests, files, units, vec![])) } /// Build a test plan from a unit test config diff --git a/third_party/move/tools/move-unit-test/tests/pkg_tests.rs b/third_party/move/tools/move-unit-test/tests/pkg_tests.rs index c7e2a64e0f6ea..2b0eebc7979ee 100644 --- a/third_party/move/tools/move-unit-test/tests/pkg_tests.rs +++ b/third_party/move/tools/move-unit-test/tests/pkg_tests.rs @@ -58,6 +58,7 @@ fn run_tests_for_pkg(path_to_pkg: impl Into, v2: bool) { #[test] fn one_bytecode_dep() { + // TODO: automatically discovers all Move packages under a package directory and runs unit tests for them run_tests_for_pkg("tests/packages/one-bytecode-dep", true); run_tests_for_pkg("tests/packages/one-bytecode-dep", false); } From 0876ea548452be8097c25c0c0011cfd097d149c6 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Mon, 6 Jan 2025 12:18:42 -0500 Subject: [PATCH 9/9] resolve merge conflicts --- third_party/move/tools/move-unit-test/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/third_party/move/tools/move-unit-test/src/lib.rs b/third_party/move/tools/move-unit-test/src/lib.rs index 5af0080a16e7b..fec940db1444c 100644 --- a/third_party/move/tools/move-unit-test/src/lib.rs +++ b/third_party/move/tools/move-unit-test/src/lib.rs @@ -209,9 +209,11 @@ impl UnitTestingConfig { let compilation_result = compiler.at_cfgir(cfgir).build(); - let (units, warnings) = - diagnostics::unwrap_or_report_diagnostics(&files, compilation_result); - diagnostics::report_warnings(&files, warnings); + let (units, warnings) = + diagnostics::unwrap_or_report_diagnostics(&files, compilation_result); + diagnostics::report_warnings(&files, warnings); + (test_plan, files, units) + }; test_plan.map(|tests| TestPlan::new(tests, files, units, vec![])) }