Skip to content

Commit

Permalink
removed local paths from snapshot files
Browse files Browse the repository at this point in the history
  • Loading branch information
mdgeorge4153 committed Jan 15, 2025
1 parent 206e541 commit 8aa065b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
20 changes: 15 additions & 5 deletions crates/sui-move/tests/cli_tests.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,24 +21,34 @@ 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 {
fs::copy(srcfile, dstfile)?;
}
}

// 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
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-move/tests/snapshots/cli_tests__bar__test.sh.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions crates/sui-move/tests/snapshots/cli_tests__echo.sh.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ 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
----- stdout -----
hello world
output.txt
file
../bin/sui-move

----- stderr -----
1 change: 1 addition & 0 deletions crates/sui-move/tests/tests/echo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ mkdir foo
echo "file" > foo/output.txt
ls foo
cat foo/output.txt
which sui-move

0 comments on commit 8aa065b

Please sign in to comment.