diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4d36c3c5d0740..0192d2ed9e24f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -262,7 +262,7 @@ jobs: - uses: taiki-e/install-action@nextest - name: Run move tests run: | - cargo nextest run -p sui-framework-tests -- unit_tests:: + cargo nextest run -p sui-framework-tests --test move_tests # # Disabled # rosetta-validation: diff --git a/Cargo.lock b/Cargo.lock index 56bf0f8753d44..020a15af4122e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13089,6 +13089,7 @@ dependencies = [ name = "sui-framework-tests" version = "0.1.0" dependencies = [ + "datatest-stable", "move-bytecode-verifier", "move-bytecode-verifier-meter", "move-cli", diff --git a/crates/sui-framework-tests/Cargo.toml b/crates/sui-framework-tests/Cargo.toml index cb9cc2aec3529..ad593b3634716 100644 --- a/crates/sui-framework-tests/Cargo.toml +++ b/crates/sui-framework-tests/Cargo.toml @@ -7,7 +7,12 @@ description = "Runs Move tests for sui-framework" license = "Apache-2.0" publish = false +[[test]] +name = "move_tests" +harness = false + [dev-dependencies] +datatest-stable.workspace = true prometheus.workspace = true sui-framework.workspace = true diff --git a/crates/sui-framework-tests/src/lib.rs b/crates/sui-framework-tests/src/lib.rs index d41a90db7c637..9bc362dc24b5a 100644 --- a/crates/sui-framework-tests/src/lib.rs +++ b/crates/sui-framework-tests/src/lib.rs @@ -1,8 +1,5 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -#[cfg(test)] -mod unit_tests; - #[cfg(test)] mod metered_verifier; diff --git a/crates/sui-framework-tests/src/unit_tests.rs b/crates/sui-framework-tests/src/unit_tests.rs deleted file mode 100644 index c02aad95a77ee..0000000000000 --- a/crates/sui-framework-tests/src/unit_tests.rs +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -use move_cli::base::test::UnitTestResult; -use move_package::LintFlag; -use move_unit_test::UnitTestingConfig; -use std::{ - fs, io, - path::{Path, PathBuf}, -}; -use sui_move::unit_test::run_move_unit_tests; -use sui_move_build::BuildConfig; - -const FILTER_ENV: &str = "FILTER"; - -#[test] -#[cfg_attr(msim, ignore)] -fn run_move_stdlib_unit_tests() { - let mut buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - buf.extend(["..", "sui-framework", "packages", "move-stdlib"]); - check_move_unit_tests(&buf); -} - -#[test] -#[cfg_attr(msim, ignore)] -fn run_sui_framework_tests() { - let mut buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - buf.extend(["..", "sui-framework", "packages", "sui-framework"]); - check_move_unit_tests(&buf); -} - -#[test] -#[cfg_attr(msim, ignore)] -fn run_sui_system_tests() { - let mut buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - buf.extend(["..", "sui-framework", "packages", "sui-system"]); - check_move_unit_tests(&buf); -} - -#[test] -#[cfg_attr(msim, ignore)] -fn run_deepbook_tests() { - let mut buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - buf.extend(["..", "sui-framework", "packages", "deepbook"]); - check_move_unit_tests(&buf); -} -#[test] -#[cfg_attr(msim, ignore)] -fn run_bridge_tests() { - let mut buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - buf.extend(["..", "sui-framework", "packages", "bridge"]); - check_move_unit_tests(&buf); -} - -fn check_packages_recursively(path: &Path) -> io::Result<()> { - for entry in fs::read_dir(path).unwrap() { - let entry = entry?; - if entry.path().join("Move.toml").exists() { - check_package_builds(&entry.path()); - check_move_unit_tests(&entry.path()); - } else if entry.file_type()?.is_dir() { - check_packages_recursively(&entry.path())?; - } - } - Ok(()) -} - -#[test] -#[cfg_attr(msim, ignore)] -fn run_examples_move_unit_tests() -> io::Result<()> { - let examples = { - let mut buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - buf.extend(["..", "..", "examples"]); - buf - }; - - check_packages_recursively(&examples)?; - - Ok(()) -} - -/// Ensure packages build outside of test mode. -fn check_package_builds(path: &Path) { - let mut config = BuildConfig::new_for_testing(); - config.config.dev_mode = true; - config.run_bytecode_verifier = true; - config.print_diags_to_stderr = true; - config.config.warnings_are_errors = true; - config.config.silence_warnings = false; - config.config.lint_flag = LintFlag::LEVEL_DEFAULT; - config - .build(path) - .unwrap_or_else(|e| panic!("Building package {}.\nWith error {e}", path.display())); -} - -fn check_move_unit_tests(path: &Path) { - let mut config = BuildConfig::new_for_testing(); - // Make sure to verify tests - config.config.dev_mode = true; - config.config.test_mode = true; - config.run_bytecode_verifier = true; - config.print_diags_to_stderr = true; - config.config.warnings_are_errors = true; - config.config.silence_warnings = false; - config.config.lint_flag = LintFlag::LEVEL_DEFAULT; - let move_config = config.config.clone(); - let mut testing_config = UnitTestingConfig::default_with_bound(Some(3_000_000)); - testing_config.filter = std::env::var(FILTER_ENV).ok().map(|s| s.to_string()); - - assert_eq!( - run_move_unit_tests(path, move_config, Some(testing_config), false).unwrap(), - UnitTestResult::Success - ); -} diff --git a/crates/sui-framework-tests/tests/move_tests.rs b/crates/sui-framework-tests/tests/move_tests.rs new file mode 100644 index 0000000000000..f589f31e372ae --- /dev/null +++ b/crates/sui-framework-tests/tests/move_tests.rs @@ -0,0 +1,80 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +use std::path::Path; + +use move_cli::base::test::UnitTestResult; +use move_package::LintFlag; +use move_unit_test::UnitTestingConfig; +use sui_move::unit_test::run_move_unit_tests; +use sui_move_build::BuildConfig; + +pub(crate) const EXAMPLES: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../examples"); +pub(crate) const FRAMEWORK: &str = concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../crates/sui-framework/packages" +); + +/// Ensure packages build outside of test mode. +pub(crate) fn build(path: &Path) -> datatest_stable::Result<()> { + let Some(path) = path.parent() else { + panic!("No parent for Move.toml file at: {}", path.display()); + }; + + let mut config = BuildConfig::new_for_testing(); + config.config.dev_mode = true; + config.run_bytecode_verifier = true; + config.print_diags_to_stderr = true; + config.config.warnings_are_errors = true; + config.config.silence_warnings = false; + config.config.lint_flag = LintFlag::LEVEL_DEFAULT; + + config + .build(path) + .unwrap_or_else(|e| panic!("Building package {}.\nWith error {e}", path.display())); + + Ok(()) +} + +/// Ensure package sbuild under test mode and all the tests pass. +pub(crate) fn tests(path: &Path) -> datatest_stable::Result<()> { + let Some(path) = path.parent() else { + panic!("No parent for Move.toml file at: {}", path.display()); + }; + + let mut config = BuildConfig::new_for_testing(); + + config.config.dev_mode = true; + config.config.test_mode = true; + config.run_bytecode_verifier = true; + config.print_diags_to_stderr = true; + config.config.warnings_are_errors = true; + config.config.silence_warnings = false; + config.config.lint_flag = LintFlag::LEVEL_DEFAULT; + + let move_config = config.config.clone(); + let mut testing_config = UnitTestingConfig::default_with_bound(Some(3_000_000)); + testing_config.filter = std::env::var("FILTER").ok().map(|s| s.to_string()); + + assert_eq!( + run_move_unit_tests(path, move_config, Some(testing_config), false).unwrap(), + UnitTestResult::Success + ); + + Ok(()) +} + +datatest_stable::harness!( + build, + EXAMPLES, + r".*/Move.toml$", + tests, + EXAMPLES, + r".*/Move.toml$", + build, + FRAMEWORK, + r".*/Move.toml$", + tests, + FRAMEWORK, + r".*/Move.toml$", +);