Merge branch 'user-dir-env'

This commit is contained in:
Chris Wanstrath 2026-03-12 14:22:19 -07:00
commit 36492fcc96
4 changed files with 16 additions and 2 deletions

View File

@ -45,6 +45,8 @@ Transcript-based shell integration test runner. Bun + TypeScript.
- Setup command failures abort the test with an error
- Each file runs in a fresh temp dir with a single `/bin/sh` session
- `$HOME` and `$SHOUT_DIR` are set to the temp dir automatically
- `$SHOUT_SOURCE_DIR` is set to the directory containing the `.shout` file
- `$SHOUT_PROJECT_DIR` is set to `cwd` where `shout` was invoked
- stdout and stderr are merged (`exec 2>&1`)
## Style

View File

@ -134,6 +134,8 @@ program
cleanEnv: opts.cleanEnv ?? false,
pathDirs: opts.path,
envVars,
sourceDir: resolve(dirname(filePath)),
projectDir: cwd,
timeout: timeoutMs,
verbose: opts.verbose ?? false,
onCommand: opts.verbose

View File

@ -21,6 +21,8 @@ type RunOptions = {
cleanEnv: boolean
pathDirs?: string[]
envVars?: Record<string, string>
sourceDir?: string
projectDir?: string
timeout: number
verbose: boolean
onCommand?: (cmd: Command) => void
@ -128,6 +130,12 @@ export async function runFile(
env["HOME"] = tmpDir
env["SHOUT_DIR"] = tmpDir
if (options.sourceDir) {
env["SHOUT_SOURCE_DIR"] = options.sourceDir
}
if (options.projectDir) {
env["SHOUT_PROJECT_DIR"] = options.projectDir
}
if (options.envVars) {
Object.assign(env, options.envVars)

View File

@ -238,6 +238,8 @@ Options:
<p>Shout sets these variables before running your commands:</p>
<pre><code><span class="bright">HOME</span> <span class="dim"></span> <span class="output">temp directory for this test file</span>
<span class="bright">SHOUT_DIR</span> <span class="dim"></span> <span class="output">same temp directory</span>
<span class="bright">SHOUT_SOURCE_DIR</span> <span class="dim"></span> <span class="output">directory containing the .shout file</span>
<span class="bright">SHOUT_PROJECT_DIR</span> <span class="dim"></span> <span class="output">directory where shout was invoked</span>
<span class="bright">PATH</span> <span class="dim"></span> <span class="output">prepended with --path dirs, if any</span></code></pre>
<p>Each file runs in its own temp directory. <code>--clean-env</code> starts with an empty environment instead of inheriting yours.</p>
</section>