-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testscript: Add Chdir method to change directory
It is not currently possible for a custom testscript command to change the working directory of that script run. `TestScript.Exec` runs the command in a subprocess, so one cannot do `ts.Exec("cd", dir)`. This change adds a `Chdir` method to `TestScript` that allows changing the working directory of the script. The implementation is the same as the "cd" command, which now relies on `Chdir`. The availability of this function matches similar functionality in the [`State.Chdir` method of rsc.io/script][1]. (I ported some tests from rsc.io/script to testscript.) [1]: https://pkg.go.dev/rsc.io/script#State.Chdir
- Loading branch information
Showing
4 changed files
with
47 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Verify that a custom command can chdir. | ||
|
||
mkChdir foo | ||
exists $WORK/foo | ||
|
||
# Current directory is not $WORK. | ||
! exists foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters