Skip to content

Commit 81f4793

Browse files
committed
feat(test): set environment variables for test subprocesses
1 parent 7ff263f commit 81f4793

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

git-branchless-test/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2444,7 +2444,9 @@ fn test_commit(
24442444
command
24452445
.arg("-c")
24462446
.arg(&options.command)
2447-
.current_dir(working_directory);
2447+
.current_dir(working_directory)
2448+
.env("BRANCHLESS_TEST_COMMIT", commit.get_oid().to_string())
2449+
.env("BRANCHLESS_TEST_COMMAND", options.command.clone());
24482450

24492451
if options.interactive {
24502452
let commit_desc = effects

git-branchless-test/tests/test_test.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,3 +1637,39 @@ fi
16371637

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

0 commit comments

Comments
 (0)