arion 0.1.0.5 → 0.1.0.6
raw patch · 4 files changed
+17/−28 lines, 4 files
Files
- arion.cabal +1/−1
- src/Arion/EventProcessor.hs +7/−7
- src/Arion/Runner.hs +4/−4
- src/Arion/Types.hs +5/−16
arion.cabal view
@@ -1,5 +1,5 @@ name: arion-version: 0.1.0.5+version: 0.1.0.6 synopsis: Watcher and runner for Hspec description: Watcher and runner for Hspec license: MIT
src/Arion/EventProcessor.hs view
@@ -10,19 +10,19 @@ import qualified Data.Map as M import Arion.Help -processEvent :: SourceTestMap -> String -> Event -> [Command]-processEvent sourceToTestFileMap sourceFolder (Modified filePath _) = commands sourceToTestFileMap sourceFolder (encodeString filePath)-processEvent sourceToTestFileMap sourceFolder (Added filePath _) = commands sourceToTestFileMap sourceFolder (encodeString filePath)-processEvent _ _ _ = []+processEvent :: SourceTestMap -> String -> String -> Event -> [Command]+processEvent sourceToTestFileMap sourceFolder testFolder (Modified filePath _) = commands sourceToTestFileMap sourceFolder testFolder (encodeString filePath)+processEvent sourceToTestFileMap sourceFolder testFolder (Added filePath _) = commands sourceToTestFileMap sourceFolder testFolder (encodeString filePath)+processEvent _ _ _ _ = [] -commands :: SourceTestMap -> String -> FilePath -> [Command]-commands sourceToTestFileMap sourceFolder filePath+commands :: SourceTestMap -> String -> String -> FilePath -> [Command]+commands sourceToTestFileMap sourceFolder testFolder filePath | isSuffixOf "hs" filePath = let fileType = typeOf filePath commandCandidates = case fileType of Source -> let testFiles = M.lookup filePath sourceToTestFileMap in toCommandCandidates testFiles Test -> [filePath]- in Echo (filePath ++ " changed") : map (CabalExec . RunHaskell sourceFolder) commandCandidates+ in Echo (filePath ++ " changed") : map (CabalExec . RunHaskell sourceFolder testFolder ) commandCandidates | otherwise = [] toCommandCandidates :: Maybe [TestFile] -> [String]
src/Arion/Runner.hs view
@@ -35,7 +35,7 @@ let sourceFiles = map (uncurry toSourceFile) sourceFilePathAndContent let testFiles = map (uncurry toTestFile) testFilePathAndContent let sourceToTestFileMap = associate sourceFiles testFiles- _ <- watchTree manager (fromText $ pack path) (const True) (eventHandler sourceToTestFileMap sourceFolder)+ _ <- watchTree manager (fromText $ pack path) (const True) (eventHandler sourceToTestFileMap sourceFolder testFolder) forever $ threadDelay maxBound filePathAndContent :: String -> IO (FilePath, FileContent)@@ -47,9 +47,9 @@ findHaskellFiles :: String -> IO [String] findHaskellFiles = find always (extension ==? ".hs" ||? extension ==? ".lhs") -eventHandler :: SourceTestMap -> String -> Event -> IO ()-eventHandler sourceToTestFileMap sourceFolder event = let commands = processEvent sourceToTestFileMap sourceFolder event- in mapM_ executeCommand commands+eventHandler :: SourceTestMap -> String -> String -> Event -> IO ()+eventHandler sourceToTestFileMap sourceFolder testFolder event = let commands = processEvent sourceToTestFileMap sourceFolder testFolder event+ in mapM_ executeCommand commands executeCommand :: Command -> IO () executeCommand command = let process = (try . callCommand) (show command) :: IO (Either SomeException ())
src/Arion/Types.hs view
@@ -15,12 +15,12 @@ import Text.Regex.Posix ((=~), getAllTextMatches) import Data.Map (Map) -data Command = RunHaskell { sourceFolder :: String, commandString :: String } |+data Command = RunHaskell { sourceFolder :: String, testFolder :: String, commandString :: String } | Echo String | CabalExec { command :: Command } deriving (Eq) instance Show Command where- show (RunHaskell sourceFolder commandString) = "runhaskell -- -i" ++ sourceFolder ++ " " ++ commandString+ show (RunHaskell sourceFolder testFolder commandString) = "runhaskell -- -i" ++ sourceFolder ++ " -i" ++ testFolder ++ " " ++ commandString show (Echo stringToEcho) = "echo " ++ stringToEcho show (CabalExec command) = "cabal exec " ++ show command @@ -32,18 +32,12 @@ sourceFilePath :: String, moduleName :: String, importedModules :: [String]-} deriving (Eq, Ord)+} deriving (Eq, Ord, Show) data TestFile = TestFile { testFilePath :: String, imports :: [String]-} deriving (Eq, Ord)--instance Show SourceFile where- show sourceFile = moduleName sourceFile--instance Show TestFile where- show testFile = testFilePath testFile+} deriving (Eq, Ord, Show) data FileType = Source | Test @@ -70,13 +64,8 @@ getImports :: FileContent -> [String] getImports fileContent = let importLines = getAllTextMatches $ fileContent =~ "import.*" :: [String]- imports = map (importedModule . splitOn " ") importLines+ imports = map ((\(_:x:_) -> x) . filter (not . (`elem` ["","qualified"])) . splitOn " ") importLines in imports--importedModule :: [String] -> String-importedModule [_, moduleName] = moduleName-importedModule [_, _, moduleName, _, _] = moduleName-importedModule _ = "" getModuleName :: FileContent -> String getModuleName fileContent = let moduleLine = fileContent =~ "(module\\s+.*\\s+.*)" :: String