create a challenge, cntd.

This commit is contained in:
Filip Gralinski 2015-08-23 17:47:40 +02:00 committed by Filip Gralinski
parent f6abc0f485
commit cf5e473eee
2 changed files with 14 additions and 1 deletions

View File

@ -5,6 +5,7 @@ module GEval.Core
MetricValue, MetricValue,
GEvalSpecification(..), GEvalSpecification(..),
GEvalOptions(..), GEvalOptions(..),
GEvalException(..),
defaultGEvalSpecification, defaultGEvalSpecification,
defaultOutDirectory, defaultOutDirectory,
defaultTestName, defaultTestName,
@ -67,6 +68,7 @@ data GEvalException = NoExpectedFile FilePath
| NoOutDirectory FilePath | NoOutDirectory FilePath
| NoExpectedTestDirectory FilePath | NoExpectedTestDirectory FilePath
| NoOutTestDirectory FilePath | NoOutTestDirectory FilePath
| FileAlreadyThere FilePath
instance Exception GEvalException instance Exception GEvalException
@ -77,7 +79,7 @@ instance Show GEvalException where
show (NoOutDirectory filePath) = somethingWrongWithFilesMessage "No directory with the test results" filePath show (NoOutDirectory filePath) = somethingWrongWithFilesMessage "No directory with the test results" filePath
show (NoExpectedTestDirectory filePath) = somethingWrongWithFilesMessage "No test subdirectory with the expected results" filePath show (NoExpectedTestDirectory filePath) = somethingWrongWithFilesMessage "No test subdirectory with the expected results" filePath
show (NoOutTestDirectory filePath) = somethingWrongWithFilesMessage "No test subdirectory with the results obtained" filePath show (NoOutTestDirectory filePath) = somethingWrongWithFilesMessage "No test subdirectory with the results obtained" filePath
show (FileAlreadyThere filePath) = somethingWrongWithFilesMessage "File already there" filePath
somethingWrongWithFilesMessage :: String -> FilePath -> String somethingWrongWithFilesMessage :: String -> FilePath -> String
somethingWrongWithFilesMessage msg filePath = Prelude.concat somethingWrongWithFilesMessage msg filePath = Prelude.concat

View File

@ -5,6 +5,17 @@ module GEval.CreateChallenge
where where
import GEval.Core import GEval.Core
import qualified System.Directory as D
import Control.Conditional (whenM)
import System.IO
import Control.Exception
import Control.Monad.Trans.Resource
createChallenge :: FilePath -> GEvalSpecification -> IO () createChallenge :: FilePath -> GEvalSpecification -> IO ()
createChallenge expectedDirectory spec = putStrLn "creating challange..." createChallenge expectedDirectory spec = putStrLn "creating challange..."
createFile :: FilePath -> String -> IO ()
createFile filePath contents = do
whenM (D.doesFileExist filePath) $ throwM $ FileAlreadyThere filePath
writeFile filePath contents