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

[test-infra][2/n] Replace Move's .exp tests with cargo-insta #21004

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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.

1 change: 1 addition & 0 deletions external-crates/move/Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ macro_rules! insta_assert {
settings.set_input_file(&i);
settings.set_snapshot_path(i.parent().unwrap());
if let Some(info) = info {
settings.set_info(info);
settings.set_info(&info);
}
if let Some(suffix) = suffix {
settings.set_snapshot_suffix(suffix);
Expand Down
2 changes: 1 addition & 1 deletion external-crates/move/crates/move-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serde_json.workspace = true
similar.workspace = true
stacker.workspace = true
vfs.workspace = true

insta.workspace = true

bcs.workspace = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
use std::{
collections::BTreeMap,
fs,
path::{self, Path, PathBuf},
path::{Path, PathBuf},
};

use move_command_line_common::{
env::read_bool_env_var,
files::MOVE_EXTENSION,
insta_assert,
testing::{read_env_update_baseline, InstaOptions, EXP_EXT, OUT_EXT},
testing::{read_env_update_baseline, InstaOptions, OUT_EXT},
};
use move_compiler::{
command_line::compiler::move_check_for_errors,
Expand Down Expand Up @@ -273,7 +273,14 @@ fn out_path(path: &Path, test_name: &str, test_kind: Option<&str>) -> PathBuf {
// Runs all tests under the test/testsuite directory.
pub fn run_test(path: &Path) -> datatest_stable::Result<()> {
let (test_kind, test_info, package_config, flags) = test_config(path);
let test_name: &str = path.file_name().unwrap().to_string_lossy().as_ref();
let migration_mode = package_config.edition == Edition::E2024_MIGRATION;
let p;
let test_name = {
p = path.with_extension("");
assert!(p.extension().is_none());
p.file_name().unwrap().to_string_lossy()
};
Comment on lines +182 to +187
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is equivalent to

let test_name = path.file_stem().unwrap().to_string_lossy().as_ref();

and that might be a bit cleaner?

let test_name: &str = test_name.as_ref();
let move_path = path.with_extension(MOVE_EXTENSION);
let out_path = out_path(path, test_name, test_kind);
let flavor = package_config.flavor;
Expand All @@ -284,7 +291,7 @@ pub fn run_test(path: &Path) -> datatest_stable::Result<()> {
paths: move_stdlib::move_stdlib_files(),
named_address_map: named_address_map.clone(),
}];
let target_name = if package_config.edition == Edition::E2024_MIGRATION {
let target_name = if migration_mode {
Some(("test".into(), package_config.clone()))
} else {
None
Expand Down Expand Up @@ -319,7 +326,7 @@ pub fn run_test(path: &Path) -> datatest_stable::Result<()> {

let has_diags = !diags.is_empty();
let diag_buffer = if has_diags {
if package_config.edition == Edition::E2024_MIGRATION {
if migration_mode {
report_migration_to_buffer(&files, diags)
} else {
report_diagnostics_to_buffer(&files, diags, /* ansi_color */ false)
Expand All @@ -329,7 +336,6 @@ pub fn run_test(path: &Path) -> datatest_stable::Result<()> {
};

let save_diags = read_bool_env_var(KEEP_TMP);
let update_baseline = read_env_update_baseline();

let rendered_diags = std::str::from_utf8(&diag_buffer)?;
if save_diags {
Expand Down