-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Move] Allow Bytecode Dependencies for Unit Testing (#15252)
* fix bytecode deps for unit tests * add tests * linter & remove debug print * reset Cargo.lock * add bytecode files * reset Cargo.lock * add .gitkeep for empty dir * address comments * resolve merge conflicts --------- Co-authored-by: Zekun Wang <[email protected]>
- Loading branch information
Showing
16 changed files
with
202 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
third_party/move/tools/move-unit-test/tests/packages/dep/Move.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "Dep" | ||
version = "1.0.0" | ||
authors = [] |
46 changes: 46 additions & 0 deletions
46
third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/BuildInfo.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: [] |
Binary file added
BIN
+118 Bytes
third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/bytecode_modules/foo.mv
Binary file not shown.
Empty file.
14 changes: 14 additions & 0 deletions
14
third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/Move.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
9 changes: 9 additions & 0 deletions
9
third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/sources/test.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module 0x42::test { | ||
#[test_only] | ||
use 0x42::foo; | ||
|
||
#[test] | ||
fun test() { | ||
assert!(foo::foo() == 42, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
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 std::path::PathBuf; | ||
use tempfile::tempdir; | ||
|
||
pub fn path_in_crate<S>(relative: S) -> PathBuf | ||
where | ||
S: Into<String>, | ||
{ | ||
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
path.push(relative.into()); | ||
path | ||
} | ||
|
||
fn run_tests_for_pkg(path_to_pkg: impl Into<String>, v2: bool) { | ||
let pkg_path = path_in_crate(path_to_pkg); | ||
|
||
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() { | ||
// 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); | ||
} |