Skip to content

Commit 17c5874

Browse files
committed
Shell: Use "cmd /q /c" on Windows, not "sh".
1 parent 8db4f81 commit 17c5874

8 files changed

Lines changed: 67 additions & 34 deletions

File tree

fixtures/broken-specs/smoke.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ tests:
22
- name: no-command
33

44
- name: no-outputs
5-
command:
6-
- echo
5+
command: echo
76
args:
87
- input
98

109
- name: missing-input-file
11-
command:
12-
- echo
10+
command: echo
1311
args:
1412
- something
1513
stdin:
@@ -18,16 +16,14 @@ tests:
1816
output
1917
2018
- name: missing-output-file
21-
command:
22-
- echo
19+
command: echo
2320
args:
2421
- something
2522
stdout:
2623
file: io/missing.out
2724

2825
- name: missing-error-file
29-
command:
30-
- echo
26+
command: echo
3127
args:
3228
- something
3329
stderr:

fixtures/shell/local.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
tests:
2-
- name: use the default shell
2+
- name: use the default shell, on Unix or Windows
33
command: |
4-
echo 'Something.' >&2
4+
echo Something.>&2
55
false
6-
echo 'Something else.' >&2
6+
echo Something else.>&2
77
stderr: |
88
Something.
99
Something else.
@@ -41,7 +41,7 @@ tests:
4141
stderr: |
4242
Something else.
4343
44-
- name: pass args to a shell command
44+
- name: pass args to the default shell command
4545
command: |
4646
echo $1 $2 $3
4747
args:
@@ -53,7 +53,7 @@ tests:
5353
stdout: |
5454
a b c
5555
56-
- name: pass args to a shell command with a custom shell
56+
- name: pass args to a custom shell command
5757
command:
5858
shell:
5959
- ruby

package.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ library:
4040
ghc-options:
4141
- -Wall
4242
- -Werror
43+
when:
44+
condition: os(windows)
45+
then:
46+
source-dirs:
47+
- src/windows
48+
else:
49+
source-dirs:
50+
- src/unix
4351

4452
executables:
4553
smoke:

spec/io/shell.out-unix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ global/runs the command with a custom shell
22
succeeded
33
global/runs the filter with a custom shell
44
succeeded
5-
local/use the default shell
5+
local/use the default shell, on Unix or Windows
66
succeeded
77
local/pipe STDIN to the script
88
succeeded
99
local/use custom shell flags
1010
succeeded
1111
local/use a custom shell
1212
succeeded
13-
local/pass args to a shell command
13+
local/pass args to the default shell command
1414
succeeded
15-
local/pass args to a shell command with a custom shell
15+
local/pass args to a custom shell command
1616
succeeded
1717
local/use a custom shell with an absolute path
1818
succeeded

spec/io/shell.out-windows

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ global/runs the command with a custom shell
22
succeeded
33
global/runs the filter with a custom shell
44
succeeded
5-
local/use the default shell
5+
local/use the default shell, on Unix or Windows
66
succeeded
77
local/pipe STDIN to the script
88
succeeded
99
local/use custom shell flags
1010
succeeded
1111
local/use a custom shell
1212
succeeded
13-
local/pass args to a shell command
14-
succeeded
15-
local/pass args to a shell command with a custom shell
13+
local/pass args to the default shell command
14+
args: a
15+
b
16+
c
17+
d
18+
e
19+
stdout: @@ -1 +1 @@
20+
-a b c
21+
+$1 $2 $3
22+
local/pass args to a custom shell command
1623
succeeded
1724
local/use a custom shell with an absolute path
1825
The executable "bin\sh" could not be found.
@@ -21,4 +28,4 @@ local/use a shell that doesn't exist
2128
local/use a shell that isn't executable
2229
The file at "fixtures\non_executable_application" is not executable.
2330

24-
11 tests, 3 failures
31+
11 tests, 4 failures

src/Test/Smoke/Executable.hs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{-# LANGUAGE OverloadedStrings #-}
2-
31
module Test.Smoke.Executable where
42

53
import Control.Monad.Trans.Except (ExceptT)
@@ -12,18 +10,9 @@ import System.IO.Temp (withSystemTempFile)
1210
import System.Process (CreateProcess(..), proc)
1311
import System.Process.Text (readCreateProcessWithExitCode)
1412
import Test.Smoke.Paths
13+
import Test.Smoke.Shell
1514
import Test.Smoke.Types
1615

17-
defaultShell :: ExceptT PathError IO Shell
18-
defaultShell = do
19-
sh <- findExecutable $ parseFile "sh"
20-
return $ Shell sh mempty
21-
22-
shellFromCommandLine :: CommandLine -> ExceptT PathError IO Shell
23-
shellFromCommandLine (CommandLine shellName shellArgs) = do
24-
shellCommand <- findExecutable shellName
25-
return $ Shell shellCommand shellArgs
26-
2716
runExecutable ::
2817
Executable
2918
-> Args
@@ -38,7 +27,7 @@ runExecutable (ExecutableProgram executablePath executableArgs) args (StdIn stdI
3827
{cwd = toFilePath . unWorkingDirectory <$> workingDirectory})
3928
stdIn
4029
runExecutable (ExecutableScript (Shell shellPath shellArgs) (Script script)) args stdIn workingDirectory =
41-
withSystemTempFile "smoke.sh" $ \scriptPath scriptHandle -> do
30+
withSystemTempFile defaultShellScriptName $ \scriptPath scriptHandle -> do
4231
Text.IO.hPutStr scriptHandle script
4332
hClose scriptHandle
4433
let executableArgs = shellArgs <> Args (Vector.singleton scriptPath)
@@ -61,3 +50,8 @@ convertCommandToExecutable (Just shell) (CommandScript Nothing script) =
6150
convertCommandToExecutable _ (CommandScript (Just commandLine) script) = do
6251
shell <- shellFromCommandLine commandLine
6352
return $ ExecutableScript shell script
53+
54+
shellFromCommandLine :: CommandLine -> ExceptT PathError IO Shell
55+
shellFromCommandLine (CommandLine shellName shellArgs) = do
56+
shellCommand <- findExecutable shellName
57+
return $ Shell shellCommand shellArgs

src/unix/Test/Smoke/Shell.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Test.Smoke.Shell where
2+
3+
import Control.Monad.Trans.Except (ExceptT)
4+
import Test.Smoke.Paths
5+
import Test.Smoke.Types
6+
7+
defaultShellScriptName :: String
8+
defaultShellScriptName = "smoke.sh"
9+
10+
defaultShell :: ExceptT PathError IO Shell
11+
defaultShell = do
12+
sh <- findExecutable $ parseFile "sh"
13+
return $ Shell sh mempty

src/windows/Test/Smoke/Shell.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Test.Smoke.Shell where
2+
3+
import Control.Monad.Trans.Except (ExceptT)
4+
import qualified Data.Vector as Vector
5+
import Test.Smoke.Paths
6+
import Test.Smoke.Types
7+
8+
defaultShellScriptName :: String
9+
defaultShellScriptName = "smoke.bat"
10+
11+
defaultShell :: ExceptT PathError IO Shell
12+
defaultShell = do
13+
cmd <- findExecutable $ parseFile "cmd"
14+
let args = Args (Vector.fromList ["/q", "/c"])
15+
return $ Shell cmd args

0 commit comments

Comments
 (0)