Skip to content

Commit 3741fec

Browse files
committed
Convert from DOS to Unix newlines, no other changes.
1 parent 9f93cc5 commit 3741fec

File tree

8 files changed

+916
-916
lines changed

8 files changed

+916
-916
lines changed

haskell_edsl/README.md

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
# Checktestdata Haskell EDSL
2-
3-
This is a Haskell implementation of the checktestdata tool. The language is build as a Haskell EDSL which can be used to check a specific format of the data, as well as checking semantic correctness of the data. There is also an executable providing backwards compatibility with existing CTD scripts.
4-
5-
For building, a recent [Haskell compiler](https://www.haskell.org/ghc/) is needed, as well as a build tool such as [Cabal](https://www.haskell.org/cabal/) or [Stack](https://www.haskellstack.org/). For installing both the compiler and a build tool, [Haskell Platform](https://www.haskell.org/platform/) is recommended.
6-
7-
## Building with stack
8-
9-
For building with stack, run:
10-
```
11-
stack init
12-
stack build
13-
```
14-
15-
Then the executable can be run with:
16-
```
17-
stack exec checktestdata
18-
```
19-
20-
The tests can be run with:
21-
```
22-
stack test
23-
```
24-
25-
## Building with cabal
26-
27-
For building with cabal, run:
28-
```
29-
cabal install --only-dependencies
30-
cabal configure
31-
cabal build
32-
```
33-
34-
Then the executable can be run with:
35-
```
36-
dist/build/checktestdata/checktestdata
37-
```
38-
39-
The tests can be run with:
40-
```
41-
cabal test
42-
```
1+
# Checktestdata Haskell EDSL
2+
3+
This is a Haskell implementation of the checktestdata tool. The language is build as a Haskell EDSL which can be used to check a specific format of the data, as well as checking semantic correctness of the data. There is also an executable providing backwards compatibility with existing CTD scripts.
4+
5+
For building, a recent [Haskell compiler](https://www.haskell.org/ghc/) is needed, as well as a build tool such as [Cabal](https://www.haskell.org/cabal/) or [Stack](https://www.haskellstack.org/). For installing both the compiler and a build tool, [Haskell Platform](https://www.haskell.org/platform/) is recommended.
6+
7+
## Building with stack
8+
9+
For building with stack, run:
10+
```
11+
stack init
12+
stack build
13+
```
14+
15+
Then the executable can be run with:
16+
```
17+
stack exec checktestdata
18+
```
19+
20+
The tests can be run with:
21+
```
22+
stack test
23+
```
24+
25+
## Building with cabal
26+
27+
For building with cabal, run:
28+
```
29+
cabal install --only-dependencies
30+
cabal configure
31+
cabal build
32+
```
33+
34+
Then the executable can be run with:
35+
```
36+
dist/build/checktestdata/checktestdata
37+
```
38+
39+
The tests can be run with:
40+
```
41+
cabal test
42+
```

haskell_edsl/src-main/Test.hs

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
1-
module Main ( main ) where
2-
3-
import Checktestdata
4-
import Checktestdata.Script
5-
6-
import Control.Monad
7-
import Control.Exception
8-
9-
import System.Directory ( listDirectory )
10-
import Data.List ( isPrefixOf, isSuffixOf )
11-
12-
import System.Exit ( exitFailure )
13-
14-
testsdir :: String
15-
testsdir = "../tests/"
16-
17-
main :: IO ()
18-
main = do
19-
-- Read the tests directory
20-
allfiles <- listDirectory testsdir
21-
22-
-- Go over all regular test programs
23-
let isProg f = "testprog" `isPrefixOf` f && ".in" `isSuffixOf` f
24-
r1 <- forM (filter isProg allfiles) $ \prog -> do
25-
-- Get the test num
26-
let testnum = takeWhile (/='.') $ drop (length "testprog") prog
27-
28-
-- Go over the correct testdata files
29-
let isCorrect f = ("testdata"++ testnum ++ ".in") `isPrefixOf` f
30-
r2 <- forM (filter isCorrect allfiles) $ \dataf -> checkSuccess prog dataf
31-
32-
-- Go over the failure testdata files
33-
let isFailure f = ("testdata"++ testnum ++ ".err") `isPrefixOf` f
34-
r3 <- forM (filter isFailure allfiles) $ \dataf -> checkFailure prog dataf
35-
36-
return $ r2 ++ r3
37-
38-
-- Go over all test programs that should fail
39-
let isErrProg f = "testprog" `isPrefixOf` f && ".err" `isSuffixOf` f
40-
r4 <- forM (filter isErrProg allfiles) $ \prog -> do
41-
-- Get the test num
42-
let testnum = takeWhile (/='.') $ drop (length "testprog") prog
43-
44-
-- Go over the correct testdata files
45-
let isCorrect f = ("testdata"++ testnum ++ ".in") `isPrefixOf` f
46-
forM (filter isCorrect allfiles) $ \dataf -> checkFailure prog dataf
47-
48-
-- Check that all tests succeeded
49-
when (not $ and $ concat $ r1 ++ r4) $ exitFailure
50-
51-
-- | Run the prog on the given data file and ensure that it succeeded.
52-
checkSuccess :: FilePath -> FilePath -> IO Bool
53-
checkSuccess prog dataf = do
54-
res <- checkRun prog dataf
55-
case res of
56-
Right () -> return True
57-
Left _ -> do
58-
putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not succeed"
59-
return False
60-
61-
-- | Run the prog on the given data file and ensure that it failed
62-
checkFailure :: FilePath -> FilePath -> IO Bool
63-
checkFailure prog dataf = do
64-
res <- checkRun prog dataf
65-
case res of
66-
Left _ -> return True
67-
Right () -> do
68-
putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not fail"
69-
return False
70-
71-
-- | Run the prog on the given data file and return it's success or failure
72-
checkRun :: FilePath -> FilePath -> IO (Either String ())
73-
checkRun prog dataf = do
74-
res <- try $ do
75-
ctd <- parseScript $ testsdir ++ prog
76-
runCTDFile (interpret ctd) $ testsdir ++ dataf
77-
case res of
78-
Left e -> return $ Left $ show (e :: SomeException)
79-
Right (Left e) -> return $ Left e
80-
Right (Right _) -> return $ Right ()
1+
module Main ( main ) where
2+
3+
import Checktestdata
4+
import Checktestdata.Script
5+
6+
import Control.Monad
7+
import Control.Exception
8+
9+
import System.Directory ( listDirectory )
10+
import Data.List ( isPrefixOf, isSuffixOf )
11+
12+
import System.Exit ( exitFailure )
13+
14+
testsdir :: String
15+
testsdir = "../tests/"
16+
17+
main :: IO ()
18+
main = do
19+
-- Read the tests directory
20+
allfiles <- listDirectory testsdir
21+
22+
-- Go over all regular test programs
23+
let isProg f = "testprog" `isPrefixOf` f && ".in" `isSuffixOf` f
24+
r1 <- forM (filter isProg allfiles) $ \prog -> do
25+
-- Get the test num
26+
let testnum = takeWhile (/='.') $ drop (length "testprog") prog
27+
28+
-- Go over the correct testdata files
29+
let isCorrect f = ("testdata"++ testnum ++ ".in") `isPrefixOf` f
30+
r2 <- forM (filter isCorrect allfiles) $ \dataf -> checkSuccess prog dataf
31+
32+
-- Go over the failure testdata files
33+
let isFailure f = ("testdata"++ testnum ++ ".err") `isPrefixOf` f
34+
r3 <- forM (filter isFailure allfiles) $ \dataf -> checkFailure prog dataf
35+
36+
return $ r2 ++ r3
37+
38+
-- Go over all test programs that should fail
39+
let isErrProg f = "testprog" `isPrefixOf` f && ".err" `isSuffixOf` f
40+
r4 <- forM (filter isErrProg allfiles) $ \prog -> do
41+
-- Get the test num
42+
let testnum = takeWhile (/='.') $ drop (length "testprog") prog
43+
44+
-- Go over the correct testdata files
45+
let isCorrect f = ("testdata"++ testnum ++ ".in") `isPrefixOf` f
46+
forM (filter isCorrect allfiles) $ \dataf -> checkFailure prog dataf
47+
48+
-- Check that all tests succeeded
49+
when (not $ and $ concat $ r1 ++ r4) $ exitFailure
50+
51+
-- | Run the prog on the given data file and ensure that it succeeded.
52+
checkSuccess :: FilePath -> FilePath -> IO Bool
53+
checkSuccess prog dataf = do
54+
res <- checkRun prog dataf
55+
case res of
56+
Right () -> return True
57+
Left _ -> do
58+
putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not succeed"
59+
return False
60+
61+
-- | Run the prog on the given data file and ensure that it failed
62+
checkFailure :: FilePath -> FilePath -> IO Bool
63+
checkFailure prog dataf = do
64+
res <- checkRun prog dataf
65+
case res of
66+
Left _ -> return True
67+
Right () -> do
68+
putStrLn $ "Running " ++ prog ++ " on " ++ dataf ++ " did not fail"
69+
return False
70+
71+
-- | Run the prog on the given data file and return it's success or failure
72+
checkRun :: FilePath -> FilePath -> IO (Either String ())
73+
checkRun prog dataf = do
74+
res <- try $ do
75+
ctd <- parseScript $ testsdir ++ prog
76+
runCTDFile (interpret ctd) $ testsdir ++ dataf
77+
case res of
78+
Left e -> return $ Left $ show (e :: SomeException)
79+
Right (Left e) -> return $ Left e
80+
Right (Right _) -> return $ Right ()

haskell_edsl/src/Checktestdata.hs

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
1-
module Checktestdata (
2-
-- * Core representation
3-
CTD,
4-
runCTD,
5-
6-
-- * Main functionality
7-
ctdMain,
8-
runCTDFile,
9-
10-
-- * Primitives
11-
peekChar,
12-
nextChar,
13-
nextNat,
14-
nextHex,
15-
nextFloat,
16-
17-
-- * Input readers
18-
nextInt,
19-
int,
20-
float,
21-
space,
22-
newline,
23-
24-
-- * Utilities
25-
eof,
26-
isEOF,
27-
assert,
28-
unique) where
29-
30-
import Checktestdata.Core
31-
import Checktestdata.Derived
32-
33-
import System.Environment ( getArgs, getProgName )
34-
import System.Exit ( exitFailure, exitSuccess)
35-
import System.IO ( hPutStrLn, stderr)
36-
37-
import qualified Data.ByteString.Char8 as BS
38-
39-
-- | Run a checktestdata script on a file
40-
runCTDFile :: CTD a -> FilePath -> IO (Either String a)
41-
runCTDFile sc fp = do
42-
f <- BS.readFile fp
43-
return $ runCTD sc f
44-
45-
-- | Main function that reads the commandline arguments
46-
-- and takes either a filename or reads from stdin.
47-
ctdMain :: CTD a -> IO ()
48-
ctdMain sc = do
49-
args <- getArgs
50-
bs <- case args of
51-
[] -> BS.getContents
52-
["-"] -> BS.getContents
53-
[fp] -> BS.readFile fp
54-
_ -> do
55-
nm <- getProgName
56-
putStrLn $ "Usage:"
57-
putStrLn $ " " ++ nm ++ " data.in"
58-
putStrLn $ " " ++ nm ++ " < data.in"
59-
exitFailure
60-
case runCTD sc bs of
61-
Left err -> do
62-
hPutStrLn stderr err
63-
exitFailure
64-
Right _ -> do
65-
putStrLn "Testdata OK"
66-
exitSuccess
1+
module Checktestdata (
2+
-- * Core representation
3+
CTD,
4+
runCTD,
5+
6+
-- * Main functionality
7+
ctdMain,
8+
runCTDFile,
9+
10+
-- * Primitives
11+
peekChar,
12+
nextChar,
13+
nextNat,
14+
nextHex,
15+
nextFloat,
16+
17+
-- * Input readers
18+
nextInt,
19+
int,
20+
float,
21+
space,
22+
newline,
23+
24+
-- * Utilities
25+
eof,
26+
isEOF,
27+
assert,
28+
unique) where
29+
30+
import Checktestdata.Core
31+
import Checktestdata.Derived
32+
33+
import System.Environment ( getArgs, getProgName )
34+
import System.Exit ( exitFailure, exitSuccess)
35+
import System.IO ( hPutStrLn, stderr)
36+
37+
import qualified Data.ByteString.Char8 as BS
38+
39+
-- | Run a checktestdata script on a file
40+
runCTDFile :: CTD a -> FilePath -> IO (Either String a)
41+
runCTDFile sc fp = do
42+
f <- BS.readFile fp
43+
return $ runCTD sc f
44+
45+
-- | Main function that reads the commandline arguments
46+
-- and takes either a filename or reads from stdin.
47+
ctdMain :: CTD a -> IO ()
48+
ctdMain sc = do
49+
args <- getArgs
50+
bs <- case args of
51+
[] -> BS.getContents
52+
["-"] -> BS.getContents
53+
[fp] -> BS.readFile fp
54+
_ -> do
55+
nm <- getProgName
56+
putStrLn $ "Usage:"
57+
putStrLn $ " " ++ nm ++ " data.in"
58+
putStrLn $ " " ++ nm ++ " < data.in"
59+
exitFailure
60+
case runCTD sc bs of
61+
Left err -> do
62+
hPutStrLn stderr err
63+
exitFailure
64+
Right _ -> do
65+
putStrLn "Testdata OK"
66+
exitSuccess

0 commit comments

Comments
 (0)