rogpeppe / go-internal

Selected Go-internal packages factored out from the standard library
BSD 3-Clause "New" or "Revised" License
823 stars 67 forks source link

testscript: Add Chdir method to change directory #247

Closed abhinav closed 2 months ago

abhinav commented 4 months ago

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. (I ported some tests from rsc.io/script to testscript.)

abhinav commented 3 months ago

Gentle bump, @mvdan @rogpeppe. Any interest in this PR?