Fix passing spaces to tests on Windows, and add a test for it
authorIan Lynagh <igloo@earth.li>
Tue, 18 Oct 2011 20:50:12 +0000 (21:50 +0100)
committerIan Lynagh <igloo@earth.li>
Tue, 18 Oct 2011 20:50:12 +0000 (21:50 +0100)
testsuite/tests/driver/all.T
testsuite/tests/driver/spacesInArgs.hs [new file with mode: 0644]
testsuite/tests/driver/spacesInArgs.stdout [new file with mode: 0644]
testsuite/timeout/timeout.hs

index 73fbf2f..45e13ab 100644 (file)
@@ -351,3 +351,8 @@ test('T706',
       extra_clean(['T706.hs'])],
      run_command,
      ['$MAKE -s --no-print-directory T706'])
+test('spacesInArgs',
+     extra_run_opts('"a   b"   "c   d"   \'e   f\'   \'g   h\''),
+     compile_and_run,
+     [''])
+
diff --git a/testsuite/tests/driver/spacesInArgs.hs b/testsuite/tests/driver/spacesInArgs.hs
new file mode 100644 (file)
index 0000000..ba6f023
--- /dev/null
@@ -0,0 +1,10 @@
+
+import System.Environment
+
+main :: IO ()
+main = do args <- getArgs
+          mapM_ (putStrLn . f) args
+
+f :: String -> String
+f str = "Arg: " ++ show str
+
diff --git a/testsuite/tests/driver/spacesInArgs.stdout b/testsuite/tests/driver/spacesInArgs.stdout
new file mode 100644 (file)
index 0000000..7c7f692
--- /dev/null
@@ -0,0 +1,4 @@
+Arg: "a   b"
+Arg: "c   d"
+Arg: "e   f"
+Arg: "g   h"
index ca2eaf7..3a709b9 100644 (file)
@@ -104,12 +104,16 @@ ignoreIOExceptions io = io `catch` ((\_ -> return ()) :: IOException -> IO ())
 
 #else
 run secs cmd =
+    let escape '\\' = "\\\\"
+        escape '"'  = "\\\""
+        escape c    = [c]
+        cmd' = "sh -c \"" ++ concatMap escape cmd ++ "\"" in
     alloca $ \p_startupinfo ->
     alloca $ \p_pi ->
-    withTString ("sh -c \"" ++ cmd ++ "\"") $ \cmd' ->
+    withTString cmd' $ \cmd'' ->
     do job <- createJobObjectW nullPtr nullPtr
        let creationflags = 0
-       b <- createProcessW nullPtr cmd' nullPtr nullPtr True
+       b <- createProcessW nullPtr cmd'' nullPtr nullPtr True
                            creationflags
                            nullPtr nullPtr p_startupinfo p_pi
        unless b $ errorWin "createProcessW"