Skip to content

Commit

Permalink
Shell: Use "cmd /q /c" on Windows, not "sh".
Browse files Browse the repository at this point in the history
  • Loading branch information
SamirTalwar committed Sep 28, 2019
1 parent 8db4f81 commit 17c5874
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 34 deletions.
12 changes: 4 additions & 8 deletions fixtures/broken-specs/smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ tests:
- name: no-command

- name: no-outputs
command:
- echo
command: echo
args:
- input

- name: missing-input-file
command:
- echo
command: echo
args:
- something
stdin:
Expand All @@ -18,16 +16,14 @@ tests:
output
- name: missing-output-file
command:
- echo
command: echo
args:
- something
stdout:
file: io/missing.out

- name: missing-error-file
command:
- echo
command: echo
args:
- something
stderr:
Expand Down
10 changes: 5 additions & 5 deletions fixtures/shell/local.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests:
- name: use the default shell
- name: use the default shell, on Unix or Windows
command: |
echo 'Something.' >&2
echo Something.>&2
false
echo 'Something else.' >&2
echo Something else.>&2
stderr: |
Something.
Something else.
Expand Down Expand Up @@ -41,7 +41,7 @@ tests:
stderr: |
Something else.
- name: pass args to a shell command
- name: pass args to the default shell command
command: |
echo $1 $2 $3
args:
Expand All @@ -53,7 +53,7 @@ tests:
stdout: |
a b c
- name: pass args to a shell command with a custom shell
- name: pass args to a custom shell command
command:
shell:
- ruby
Expand Down
8 changes: 8 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ library:
ghc-options:
- -Wall
- -Werror
when:
condition: os(windows)
then:
source-dirs:
- src/windows
else:
source-dirs:
- src/unix

executables:
smoke:
Expand Down
6 changes: 3 additions & 3 deletions spec/io/shell.out-unix
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ global/runs the command with a custom shell
succeeded
global/runs the filter with a custom shell
succeeded
local/use the default shell
local/use the default shell, on Unix or Windows
succeeded
local/pipe STDIN to the script
succeeded
local/use custom shell flags
succeeded
local/use a custom shell
succeeded
local/pass args to a shell command
local/pass args to the default shell command
succeeded
local/pass args to a shell command with a custom shell
local/pass args to a custom shell command
succeeded
local/use a custom shell with an absolute path
succeeded
Expand Down
17 changes: 12 additions & 5 deletions spec/io/shell.out-windows
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@ global/runs the command with a custom shell
succeeded
global/runs the filter with a custom shell
succeeded
local/use the default shell
local/use the default shell, on Unix or Windows
succeeded
local/pipe STDIN to the script
succeeded
local/use custom shell flags
succeeded
local/use a custom shell
succeeded
local/pass args to a shell command
succeeded
local/pass args to a shell command with a custom shell
local/pass args to the default shell command
args: a
b
c
d
e
stdout: @@ -1 +1 @@
-a b c
+$1 $2 $3
local/pass args to a custom shell command
succeeded
local/use a custom shell with an absolute path
The executable "bin\sh" could not be found.
Expand All @@ -21,4 +28,4 @@ local/use a shell that doesn't exist
local/use a shell that isn't executable
The file at "fixtures\non_executable_application" is not executable.

11 tests, 3 failures
11 tests, 4 failures
20 changes: 7 additions & 13 deletions src/Test/Smoke/Executable.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.Smoke.Executable where

import Control.Monad.Trans.Except (ExceptT)
Expand All @@ -12,18 +10,9 @@ import System.IO.Temp (withSystemTempFile)
import System.Process (CreateProcess(..), proc)
import System.Process.Text (readCreateProcessWithExitCode)
import Test.Smoke.Paths
import Test.Smoke.Shell
import Test.Smoke.Types

defaultShell :: ExceptT PathError IO Shell
defaultShell = do
sh <- findExecutable $ parseFile "sh"
return $ Shell sh mempty

shellFromCommandLine :: CommandLine -> ExceptT PathError IO Shell
shellFromCommandLine (CommandLine shellName shellArgs) = do
shellCommand <- findExecutable shellName
return $ Shell shellCommand shellArgs

runExecutable ::
Executable
-> Args
Expand All @@ -38,7 +27,7 @@ runExecutable (ExecutableProgram executablePath executableArgs) args (StdIn stdI
{cwd = toFilePath . unWorkingDirectory <$> workingDirectory})
stdIn
runExecutable (ExecutableScript (Shell shellPath shellArgs) (Script script)) args stdIn workingDirectory =
withSystemTempFile "smoke.sh" $ \scriptPath scriptHandle -> do
withSystemTempFile defaultShellScriptName $ \scriptPath scriptHandle -> do
Text.IO.hPutStr scriptHandle script
hClose scriptHandle
let executableArgs = shellArgs <> Args (Vector.singleton scriptPath)
Expand All @@ -61,3 +50,8 @@ convertCommandToExecutable (Just shell) (CommandScript Nothing script) =
convertCommandToExecutable _ (CommandScript (Just commandLine) script) = do
shell <- shellFromCommandLine commandLine
return $ ExecutableScript shell script

shellFromCommandLine :: CommandLine -> ExceptT PathError IO Shell
shellFromCommandLine (CommandLine shellName shellArgs) = do
shellCommand <- findExecutable shellName
return $ Shell shellCommand shellArgs
13 changes: 13 additions & 0 deletions src/unix/Test/Smoke/Shell.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Test.Smoke.Shell where

import Control.Monad.Trans.Except (ExceptT)
import Test.Smoke.Paths
import Test.Smoke.Types

defaultShellScriptName :: String
defaultShellScriptName = "smoke.sh"

defaultShell :: ExceptT PathError IO Shell
defaultShell = do
sh <- findExecutable $ parseFile "sh"
return $ Shell sh mempty
15 changes: 15 additions & 0 deletions src/windows/Test/Smoke/Shell.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Test.Smoke.Shell where

import Control.Monad.Trans.Except (ExceptT)
import qualified Data.Vector as Vector
import Test.Smoke.Paths
import Test.Smoke.Types

defaultShellScriptName :: String
defaultShellScriptName = "smoke.bat"

defaultShell :: ExceptT PathError IO Shell
defaultShell = do
cmd <- findExecutable $ parseFile "cmd"
let args = Args (Vector.fromList ["/q", "/c"])
return $ Shell cmd args

0 comments on commit 17c5874

Please sign in to comment.