@@ -52,7 +52,7 @@ func TestWALDirectory(t *testing.T) {
5252
5353func TestBashHalt (t * testing.T ) {
5454 t .Run ("NoPipeline" , func (t * testing.T ) {
55- cmd := exec .Command ( "bash" )
55+ cmd := exec .CommandContext ( t . Context (), "bash" )
5656 cmd .Args = append (cmd .Args , "-c" , "--" , bashHalt + `; halt ab cd e` )
5757
5858 var exit * exec.ExitError
@@ -64,7 +64,7 @@ func TestBashHalt(t *testing.T) {
6464 })
6565
6666 t .Run ("PipelineZeroStatus" , func (t * testing.T ) {
67- cmd := exec .Command ( "bash" )
67+ cmd := exec .CommandContext ( t . Context (), "bash" )
6868 cmd .Args = append (cmd .Args , "-c" , "--" , bashHalt + `; true && halt message` )
6969
7070 var exit * exec.ExitError
@@ -76,7 +76,7 @@ func TestBashHalt(t *testing.T) {
7676 })
7777
7878 t .Run ("PipelineNonZeroStatus" , func (t * testing.T ) {
79- cmd := exec .Command ( "bash" )
79+ cmd := exec .CommandContext ( t . Context (), "bash" )
8080 cmd .Args = append (cmd .Args , "-c" , "--" , bashHalt + `; (exit 99) || halt $'multi\nline'` )
8181
8282 var exit * exec.ExitError
@@ -88,7 +88,7 @@ func TestBashHalt(t *testing.T) {
8888 })
8989
9090 t .Run ("Subshell" , func (t * testing.T ) {
91- cmd := exec .Command ( "bash" )
91+ cmd := exec .CommandContext ( t . Context (), "bash" )
9292 cmd .Args = append (cmd .Args , "-c" , "--" , bashHalt + `; (halt 'err') || echo 'after'` )
9393
9494 stderr := new (bytes.Buffer )
@@ -104,7 +104,7 @@ func TestBashHalt(t *testing.T) {
104104
105105func TestBashPermissions (t * testing.T ) {
106106 // macOS `stat` takes different arguments than BusyBox and GNU coreutils.
107- if output , err := exec .Command ( "stat" , "--help" ).CombinedOutput (); err != nil {
107+ if output , err := exec .CommandContext ( t . Context (), "stat" , "--help" ).CombinedOutput (); err != nil {
108108 t .Skip (`requires "stat" executable` )
109109 } else if ! strings .Contains (string (output ), "%A" ) {
110110 t .Skip (`requires "stat" with access format sequence` )
@@ -116,7 +116,7 @@ func TestBashPermissions(t *testing.T) {
116116 assert .NilError (t , os .WriteFile (filepath .Join (dir , "sub" , "fn" ), nil , 0o624 )) // #nosec G306 OK permissions for a temp dir in a test
117117 assert .NilError (t , os .Chmod (filepath .Join (dir , "sub" , "fn" ), 0o624 ))
118118
119- cmd := exec .Command ( "bash" )
119+ cmd := exec .CommandContext ( t . Context (), "bash" )
120120 cmd .Args = append (cmd .Args , "-c" , "--" ,
121121 bashPermissions + `; permissions "$@"` , "-" ,
122122 filepath .Join (dir , "sub" , "fn" ))
@@ -131,7 +131,7 @@ func TestBashPermissions(t *testing.T) {
131131
132132func TestBashRecreateDirectory (t * testing.T ) {
133133 // macOS `stat` takes different arguments than BusyBox and GNU coreutils.
134- if output , err := exec .Command ( "stat" , "--help" ).CombinedOutput (); err != nil {
134+ if output , err := exec .CommandContext ( t . Context (), "stat" , "--help" ).CombinedOutput (); err != nil {
135135 t .Skip (`requires "stat" executable` )
136136 } else if ! strings .Contains (string (output ), "%a" ) {
137137 t .Skip (`requires "stat" with access format sequence` )
@@ -143,7 +143,7 @@ func TestBashRecreateDirectory(t *testing.T) {
143143 assert .NilError (t , os .WriteFile (filepath .Join (dir , "d" , "file" ), nil , 0o644 )) // #nosec G306 OK permissions for a temp dir in a test
144144
145145 stat := func (args ... string ) string {
146- cmd := exec .Command ( "stat" , "-c" , "%i %#a %N" )
146+ cmd := exec .CommandContext ( t . Context (), "stat" , "-c" , "%i %#a %N" )
147147 cmd .Args = append (cmd .Args , args ... )
148148 out , err := cmd .CombinedOutput ()
149149
@@ -160,7 +160,7 @@ func TestBashRecreateDirectory(t *testing.T) {
160160 filepath .Join (dir , "d" , "file" ),
161161 )
162162
163- cmd := exec .Command ( "bash" )
163+ cmd := exec .CommandContext ( t . Context (), "bash" )
164164 cmd .Args = append (cmd .Args , "-ceu" , "--" ,
165165 bashRecreateDirectory + ` recreate "$@"` , "-" ,
166166 filepath .Join (dir , "d" ), "0740" )
@@ -199,15 +199,15 @@ func TestBashRecreateDirectory(t *testing.T) {
199199
200200func TestBashSafeLink (t * testing.T ) {
201201 // macOS `mv` takes different arguments than GNU coreutils.
202- if output , err := exec .Command ( "mv" , "--help" ).CombinedOutput (); err != nil {
202+ if output , err := exec .CommandContext ( t . Context (), "mv" , "--help" ).CombinedOutput (); err != nil {
203203 t .Skip (`requires "mv" executable` )
204204 } else if ! strings .Contains (string (output ), "no-target-directory" ) {
205205 t .Skip (`requires "mv" that overwrites a directory symlink` )
206206 }
207207
208208 // execute calls the bash function with args.
209209 execute := func (args ... string ) (string , error ) {
210- cmd := exec .Command ( "bash" )
210+ cmd := exec .CommandContext ( t . Context (), "bash" )
211211 cmd .Args = append (cmd .Args , "-ceu" , "--" , bashSafeLink + `safelink "$@"` , "-" )
212212 cmd .Args = append (cmd .Args , args ... )
213213 output , err := cmd .CombinedOutput ()
@@ -474,7 +474,7 @@ func TestStartupCommand(t *testing.T) {
474474 assert .NilError (t , os .WriteFile (file , []byte (script ), 0o600 ))
475475
476476 // Expect shellcheck to be happy.
477- cmd := exec .Command ( shellcheck , "--enable=all" , file )
477+ cmd := exec .CommandContext ( t . Context (), shellcheck , "--enable=all" , file )
478478 output , err := cmd .CombinedOutput ()
479479 assert .NilError (t , err , "%q\n %s" , cmd .Args , output )
480480
0 commit comments