Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Move/Examples] Switch to datatest #18813

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/sui-framework-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions crates/sui-framework-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
114 changes: 0 additions & 114 deletions crates/sui-framework-tests/src/unit_tests.rs

This file was deleted.

80 changes: 80 additions & 0 deletions crates/sui-framework-tests/tests/move_tests.rs
Original file line number Diff line number Diff line change
@@ -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$",
);
Loading