Skip to content

Commit f4bcdf9

Browse files
committed
feat(test): set environment variables for test subprocesses
1 parent 8990683 commit f4bcdf9

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
@@ -1637,3 +1637,38 @@ fi
16371637

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

0 commit comments

Comments
 (0)