From 8aa065b50aa2bbcb3cd5d8834af5170f65de233b Mon Sep 17 00:00:00 2001 From: Michael George Date: Wed, 15 Jan 2025 17:13:12 -0500 Subject: [PATCH] removed local paths from snapshot files --- crates/sui-move/tests/cli_tests.rs | 20 ++++++++++++++----- .../snapshots/cli_tests__bar__test.sh.snap | 4 ++-- .../tests/snapshots/cli_tests__echo.sh.snap | 5 +++-- crates/sui-move/tests/tests/echo.sh | 1 + 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/crates/sui-move/tests/cli_tests.rs b/crates/sui-move/tests/cli_tests.rs index 183e806a4d39e..85874bf9d11bc 100644 --- a/crates/sui-move/tests/cli_tests.rs +++ b/crates/sui-move/tests/cli_tests.rs @@ -1,7 +1,7 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -use insta_cmd::assert_cmd_snapshot; +use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; use std::fs; use std::path::Path; use std::process::Command; @@ -21,11 +21,12 @@ fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { // copy files into temporary directory let srcdir = path.parent().unwrap(); let tmpdir = tempfile::tempdir()?; + let sandbox = tmpdir.path().join("sandbox"); for entry in WalkDir::new(srcdir) { let entry = entry.unwrap(); let srcfile = entry.path(); - let dstfile = tmpdir.path().join(srcfile.strip_prefix(srcdir)?); + let dstfile = sandbox.join(srcfile.strip_prefix(srcdir)?); if srcfile.is_dir() { fs::create_dir_all(dstfile)?; } else { @@ -33,12 +34,21 @@ fn test_shell_snapshot(path: &Path) -> datatest_stable::Result<()> { } } + // Note: we need to create a symlink instead of just adding the bin dir to the path to prevent + // local pathnames from leaking into the snapshot files. + std::os::unix::fs::symlink( + get_cargo_bin("sui-move").parent().unwrap(), + tmpdir.path().join("bin"), + )?; + // set up command let mut shell = Command::new("bash"); shell - .env("PATH", format!("/bin:/usr/bin:{}", cargo_bin_path())) - .current_dir(tmpdir.path()) - .arg(path.canonicalize()?); + .env("PATH", "/bin:/usr/bin:../bin") + .current_dir(sandbox) + .arg(path.file_name().unwrap()); + + println!("{shell:?}"); // run it! let snapshot_name: String = path diff --git a/crates/sui-move/tests/snapshots/cli_tests__bar__test.sh.snap b/crates/sui-move/tests/snapshots/cli_tests__bar__test.sh.snap index d6fd05bef4cfd..01ca99623d7c0 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__bar__test.sh.snap +++ b/crates/sui-move/tests/snapshots/cli_tests__bar__test.sh.snap @@ -3,9 +3,9 @@ source: crates/sui-move/tests/cli_tests.rs info: program: bash args: - - /Users/mdgeorge/Mysten/move-tests-shell/crates/sui-move/tests/tests/bar/test.sh + - test.sh env: - PATH: "/bin:/usr/bin:/Users/mdgeorge/Mysten/move-tests-shell/target/debug" + PATH: "/bin:/usr/bin:../bin" --- success: true exit_code: 0 diff --git a/crates/sui-move/tests/snapshots/cli_tests__echo.sh.snap b/crates/sui-move/tests/snapshots/cli_tests__echo.sh.snap index fbb3258a68cd5..17dbadd0bb29c 100644 --- a/crates/sui-move/tests/snapshots/cli_tests__echo.sh.snap +++ b/crates/sui-move/tests/snapshots/cli_tests__echo.sh.snap @@ -3,9 +3,9 @@ source: crates/sui-move/tests/cli_tests.rs info: program: bash args: - - /Users/mdgeorge/Mysten/move-tests-shell/crates/sui-move/tests/tests/echo.sh + - echo.sh env: - PATH: "/bin:/usr/bin:/Users/mdgeorge/Mysten/move-tests-shell/target/debug" + PATH: "/bin:/usr/bin:../bin" --- success: true exit_code: 0 @@ -13,5 +13,6 @@ exit_code: 0 hello world output.txt file +../bin/sui-move ----- stderr ----- diff --git a/crates/sui-move/tests/tests/echo.sh b/crates/sui-move/tests/tests/echo.sh index 417eabe596f3d..3425df8a886b5 100644 --- a/crates/sui-move/tests/tests/echo.sh +++ b/crates/sui-move/tests/tests/echo.sh @@ -3,3 +3,4 @@ mkdir foo echo "file" > foo/output.txt ls foo cat foo/output.txt +which sui-move