diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index b4e8ff9..e128a67 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -5,10 +5,12 @@ hashcons Leijen lhs libz +olution OSX Preds rhs SChar SEmpty SText +ubmission Uniplate diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 1aebfcf..bec7945 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -58,7 +58,7 @@ jobs: run: | set -ex while IFS= read -r -d '' f; do - stack run -w run.yaml "$f" "examples/solutions/$(basename "$f")" + stack run -w run.yaml "$(basename "$f")" solution done < <(find examples/configs -type f -name '*.hs' -print0) set +ex env: diff --git a/README.md b/README.md index 01772fb..1553ba8 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Now to simulate the grading process: 1. Install the z3 theorem prover (`sudo apt-get install libz3-dev` or similar) 1. Install [Haskell Stack](https://docs.haskellstack.org/en/stable/#__tabbed_2_1) 1. Optionally set an alias for `stack run -w run.yaml` -1. Execute `stack run -w run.yaml examples/configs/ ` +1. Execute `stack run -w run.yaml <[submission|solution]>` (`solution` loads a sample solution) The submission will either be rejected or accepted and feedback be printed directly into the console. Running the stack command may take a while the first time, since a lot of dependencies will have to be installed. diff --git a/run-codeworld-tasks/app/Main.hs b/run-codeworld-tasks/app/Main.hs index 263a845..4a13f8c 100644 --- a/run-codeworld-tasks/app/Main.hs +++ b/run-codeworld-tasks/app/Main.hs @@ -6,6 +6,7 @@ module Main where import qualified Data.Text as T import qualified Data.Text.Lazy as LT +import Control.Monad (void) import Data.Text (Text) import Data.Text.Lazy.Builder (toLazyText) import Haskell.Template.Task (grade) @@ -29,9 +30,12 @@ import Rainbow ( import System.Directory (getTemporaryDirectory) import System.Exit (die, exitFailure, exitSuccess) import System.Environment (getArgs) -import System.FilePath ((-<.>)) +import System.FilePath ((), (-<.>)) import System.IO (readFile') +import Text.ParserCombinators.ReadP ((+++), char, choice, string) +import Text.ParserCombinators.ReadPrec (lift) import Text.PrettyPrint.Leijen.Text (Doc, SimpleDoc(..), renderPretty) +import Text.Read (Read(..), readMaybe) @@ -53,16 +57,32 @@ suggestionStyle :: Text -> Chunk suggestionStyle = bold . fore brightYellow . chunk +data Mode = Submission | Solution + + +instance Read Mode where + readPrec = lift $ do + void $ char 's' +++ char 'S' + choice [ + string "ubmission" >> pure Submission, + string "olution" >> pure Solution + ] + + main :: IO () main = do args <- getArgs case args of - [task,submission] -> do - taskContents <- openDotHs task - submissionContents <- openDotHs submission - runTemplateTask taskContents submissionContents - exitSuccess - _ -> die usage + [task,subMode] -> do + let openFileInDir dir = openDotHs $ "examples" dir task + taskContents <- openFileInDir "configs" + submissionContents <- maybe + modeHelp + (openFileInDir . modeToDir) + $ readMaybe subMode + runTemplateTask taskContents submissionContents + exitSuccess + _ -> usage runTemplateTask :: String -> String -> IO () @@ -80,12 +100,21 @@ runTemplateTask task submission = do putChunkLn $ statusLabel green "SUCCESS" +modeToDir :: Mode -> FilePath +modeToDir Submission = "tasks" +modeToDir Solution = "solutions" + + openDotHs :: FilePath -> IO String openDotHs path = readFile' $ path -<.> "hs" -usage :: String -usage = "usage: test-task " +modeHelp :: IO a +modeHelp = die "Parse error on submission mode. Try 'submission' or 'solution'" + + +usage :: IO a +usage = die "usage: test-task <[submission|solution]>" styleRejections :: Text -> Chunk