Skip to content

Commit 3a5a690

Browse files
committed
feat(test): set environment variables for test subprocesses
1 parent a3236fc commit 3a5a690

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

git-branchless-test/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,9 @@ fn test_commit(
24392439
command
24402440
.arg("-c")
24412441
.arg(&options.command)
2442-
.current_dir(working_directory);
2442+
.current_dir(working_directory)
2443+
.env("BRANCHLESS_TEST_COMMIT", commit.get_oid().to_string())
2444+
.env("BRANCHLESS_TEST_COMMAND", options.command.clone());
24432445

24442446
if options.interactive {
24452447
let commit_desc = effects

git-branchless-test/tests/test_test.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,3 +1625,38 @@ fi
16251625

16261626
Ok(())
16271627
}
1628+
1629+
#[test]
1630+
fn test_test_sets_env_vars() -> eyre::Result<()> {
1631+
let git = make_git()?;
1632+
git.init_repo()?;
1633+
1634+
git.write_file(
1635+
"test.sh",
1636+
r#"#!/bin/sh
1637+
echo "Commit is: $BRANCHLESS_TEST_COMMIT"
1638+
echo "Command is: $BRANCHLESS_TEST_COMMAND"
1639+
"#,
1640+
)?;
1641+
{
1642+
let (stdout, _stderr) =
1643+
git.branchless("test", &["run", "--exec", "bash test.sh", "HEAD", "-vv"])?;
1644+
insta::assert_snapshot!(stdout, @r###"
1645+
branchless: running command: <git-executable> diff --quiet
1646+
Calling Git for on-disk rebase...
1647+
branchless: running command: <git-executable> rebase --continue
1648+
Using test execution strategy: working-copy
1649+
branchless: running command: <git-executable> rebase --abort
1650+
✓ Passed: f777ecc create initial.txt
1651+
Stdout: <repo-path>/.git/branchless/test/d32758e20028dd1cffc2b359bc3766f80a258ee5/bash__test.sh/stdout
1652+
Commit is: f777ecc9b0db5ed372b2615695191a8a17f79f24
1653+
Command is: bash test.sh
1654+
Stderr: <repo-path>/.git/branchless/test/d32758e20028dd1cffc2b359bc3766f80a258ee5/bash__test.sh/stderr
1655+
<no output>
1656+
Tested 1 commit with bash test.sh:
1657+
1 passed, 0 failed, 0 skipped
1658+
"###);
1659+
}
1660+
1661+
Ok(())
1662+
}

0 commit comments

Comments
 (0)