test-sandbox 0.0.1.2 → 0.0.1.3
raw patch · 2 files changed
+23/−11 lines, 2 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Test.Sandbox.Internals: isValidProcessName :: String -> Bool
Files
- src/Test/Sandbox/Internals.hs +21/−9
- test-sandbox.cabal +2/−2
src/Test/Sandbox/Internals.hs view
@@ -90,10 +90,11 @@ header :: SandboxState -> String header te =- "##------------------------------------------------------------------------------\n\+ "\n\+ \##------------------------------------------------------------------------------\n\ \ ## " ++ title ++ replicate (72 - length title) ' ' ++ " --\n\ \## ##---------------------------------------------------------------------------\n"- where title = ssName te ++ " end-to-end test environment"+ where title = ssName te ++ " system test environment" footer :: String footer =@@ -110,6 +111,10 @@ String -> FilePath -> [String] -> Maybe Int -> Maybe Capture -> Sandbox SandboxedProcess registerProcess name bin args wait capture = do+ -- Validate process name+ unless (isValidProcessName name) $+ throwError $ "Invalid process name: " ++ name ++ "."+ -- Register into the environment env <- get if isJust (M.lookup name (ssProcesses env)) then throwError $ "Process " ++ name ++ " is already registered in the test environment."@@ -118,6 +123,12 @@ , ssProcessOrder = ssProcessOrder env ++ [name] } return sp +isValidProcessName :: String -> Bool+isValidProcessName s = not (null s)+ && isAlpha (head s)+ && all isAllowed (tail s)+ where isAllowed c = isAlphaNum c || c == '_'+ getProcess :: String -> Sandbox SandboxedProcess getProcess name = do env <- Sandbox get@@ -300,14 +311,15 @@ findExecutables :: [FilePath] -> IO [FilePath] findExecutables paths =- liftM catMaybes $ join $ liftM (mapM tryBinary) $ mapM expand paths+ liftM catMaybes $ mapM tryBinary paths tryBinary :: FilePath -> IO (Maybe FilePath)-tryBinary bin = do- bin' <- tryIOError . canonicalizePath =<< expand bin- case bin' of- Left _ -> findExecutable bin- Right bin'' -> findExecutable bin''+tryBinary path = do+ expandedPath <- expand path+ canonicalizedPath <- tryIOError $ canonicalizePath expandedPath+ case canonicalizedPath of+ Left _ -> findExecutable expandedPath+ Right realPath -> findExecutable realPath getProcessCandidateBinaries :: SandboxedProcess -> [FilePath] getProcessCandidateBinaries sp =@@ -315,7 +327,7 @@ where binary = spBinary sp pathBinary = takeFileName binary cwdBinary = "." </> pathBinary- userBinary = '$' : map toUpper (spName sp ++ "_bin")+ userBinary = "${" ++ map toUpper (spName sp ++ "_bin") ++ "}" expand :: String -> IO String expand s =
test-sandbox.cabal view
@@ -1,5 +1,5 @@ Name: test-sandbox-Version: 0.0.1.2+Version: 0.0.1.3 Cabal-Version: >= 1.14 Category: Testing Synopsis: Sandbox for system tests@@ -25,7 +25,7 @@ Source-Repository this Type: git Location: https://github.com/gree/haskell-test-sandbox- Tag: 0.0.1.2+ Tag: 0.0.1.3 Library Exposed-modules: Test.Sandbox