diff --git a/src/GEval/Core.hs b/src/GEval/Core.hs index 275a305..c269904 100644 --- a/src/GEval/Core.hs +++ b/src/GEval/Core.hs @@ -82,6 +82,7 @@ data GEvalException = NoExpectedFile FilePath | TooFewLines | TooManyLines | EmptyOutput + | UnexpectedData String deriving (Eq) instance Exception GEvalException @@ -97,6 +98,7 @@ instance Show GEvalException where show TooFewLines = "Too few lines in the output file" show TooManyLines = "Too many lines in the output file" show EmptyOutput = "The output file is empty" + show (UnexpectedData message) = "Unexpected data [" ++ message ++ "]" somethingWrongWithFilesMessage :: String -> FilePath -> String somethingWrongWithFilesMessage msg filePath = Prelude.concat @@ -200,3 +202,4 @@ itemError (exp, out) = (exp-out)**2 getValue :: Either String (Double, Text) -> Double getValue (Right (x, _)) = x +getValue (Left s) = throw $ UnexpectedData s diff --git a/test/Spec.hs b/test/Spec.hs index 7f796fd..11f5c91 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -40,6 +40,8 @@ main = hspec $ do runGEvalTest "error-too-many-lines" `shouldThrow` (== TooManyLines) it "empty output is handled" $ do runGEvalTest "empty-output" `shouldThrow` (== EmptyOutput) + it "unexpected data is handled" $ + runGEvalTest "unexpected-data" `shouldThrow` (== UnexpectedData "input does not start with a digit") extractVal :: (Either (ParserResult GEvalOptions) (Maybe MetricValue)) -> IO MetricValue extractVal (Right (Just val)) = return val diff --git a/test/unexpected-data/unexpected-data-solution/test-A/out.tsv b/test/unexpected-data/unexpected-data-solution/test-A/out.tsv new file mode 100644 index 0000000..ed54de3 --- /dev/null +++ b/test/unexpected-data/unexpected-data-solution/test-A/out.tsv @@ -0,0 +1,4 @@ +2.0 +1.1 +xyz +2.1 diff --git a/test/unexpected-data/unexpected-data/config.txt b/test/unexpected-data/unexpected-data/config.txt new file mode 100644 index 0000000..e2faf3d --- /dev/null +++ b/test/unexpected-data/unexpected-data/config.txt @@ -0,0 +1 @@ +--metric MSE diff --git a/test/unexpected-data/unexpected-data/test-A/expected.tsv b/test/unexpected-data/unexpected-data/test-A/expected.tsv new file mode 100644 index 0000000..46dd6a0 --- /dev/null +++ b/test/unexpected-data/unexpected-data/test-A/expected.tsv @@ -0,0 +1,4 @@ +2.0 +-3.0 +1.0 +2.5 diff --git a/test/unexpected-data/unexpected-data/test-A/in.tsv b/test/unexpected-data/unexpected-data/test-A/in.tsv new file mode 100644 index 0000000..989d482 --- /dev/null +++ b/test/unexpected-data/unexpected-data/test-A/in.tsv @@ -0,0 +1,4 @@ +bla 2 +bar 3 +bla 3 +bar 3