Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ hashcons
Leijen
lhs
libz
olution
OSX
Preds
rhs
SChar
SEmpty
SText
ubmission
Uniplate
2 changes: 1 addition & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<Task> <examples/tasks/<Task>`
1. Execute `stack run -w run.yaml <task name> <[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.
Expand Down
47 changes: 38 additions & 9 deletions run-codeworld-tasks/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)



Expand All @@ -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 ()
Expand All @@ -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 <config path> <solution path>"
modeHelp :: IO a
modeHelp = die "Parse error on submission mode. Try 'submission' or 'solution'"


usage :: IO a
usage = die "usage: test-task <task name> <[submission|solution]>"


styleRejections :: Text -> Chunk
Expand Down
Loading