Skip to content

Commit

Permalink
Disable pattern guards in codeworld-mode.
Browse files Browse the repository at this point in the history
Add an error sanitizer case to fix up the resulting errors.
Fix out-of-date unit tests, so they are all passing again.
Also, while I was here, prettify the script output using colors.

Fixes google#537
  • Loading branch information
cdsmith committed Sep 19, 2018
1 parent 3648844 commit e87aa85
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 35 deletions.
29 changes: 23 additions & 6 deletions base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ export PATH=$BUILD/bin:$PATH
export LANG=${LANG:-C.UTF-8}
export PREFIX=$BUILD

if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test "$ncolors" -ge 8; then
setnormal="$(tput sgr0)"
setred="$(tput setaf 1)"
setgreen="$(tput setaf 2)"
setyellow="$(tput setaf 3)"
fi
fi

function run {
local old_pwd=$PWD
local temp_pwd
Expand All @@ -33,16 +43,23 @@ function run {
shift

if [ $quiet -eq 0 ]; then
echo RUNNING: $@
if [[ ${temp_pwd} -ef . ]]; then
echo "${setgreen}===== RUNNING: ${setyellow}$@${setnormal}"
else
echo "${setgreen}===== IN ${setyellow}${temp_pwd}${setgreen}, RUNNING: ${setyellow}$@${setnormal}"
fi
fi

cd $temp_pwd
$@
if [ $? -ne 0 ]; then
echo ============================
echo = Aborting: Command failed =
echo ============================

exitcode=$?
if [ $exitcode -ne 0 ]; then
echo
echo "${setred}========== Aborting: Command failed. =========="
echo "${setred}DIRECTORY: ${setyellow}${temp_pwd}"
echo "${setred}COMMAND : ${setyellow}$@"
echo "${setred}EXIT CODE: ${setyellow}${exitcode}"
echo "${setred}===============================================${setnormal}"
exit 1
fi
cd $old_pwd
Expand Down
2 changes: 1 addition & 1 deletion codeworld-compiler/src/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ standardBuildArgs True =
, "-XLiberalTypeSynonyms"
, "-XNamedFieldPuns"
, "-XNoMonomorphismRestriction"
, "-XNoPatternGuards"
, "-XNoQuasiQuotes"
, "-XNoTemplateHaskell"
, "-XNoUndecidableInstances"
, "-XOverloadedStrings"
, "-XPackageImports"
, "-XParallelListComp"
, "-XPartialTypeSignatures"
, "-XPatternGuards"
, "-XRankNTypes"
, "-XRebindableSyntax"
, "-XRecordWildCards"
Expand Down
6 changes: 3 additions & 3 deletions codeworld-compiler/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ genTestCases (x) = map toTestCase x

toTestCase x =
x ~: do
err1 <- compileErrorOutput x
err2 <- savedErrorOutput x
assertEqual x err1 err2
actual <- compileErrorOutput x
expected <- savedErrorOutput x
assertEqual x expected actual

getTestCases :: FilePath -> IO Counts
getTestCases path = do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

program.hs:1:28: error:
program.hs:1:25: error:
• Couldn't match expected type Number -> Picture
with actual type Picture
• In the argument(s) of animationOf, namely (propellor)
Expand Down
2 changes: 1 addition & 1 deletion codeworld-compiler/test/testcase/test_animation/source.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
main = animationOf(propellor)
program = animationOf(propellor)
propellor = rotated(solidRectangle(10, 1), 60)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

program.hs:1:27: error:
program.hs:1:30: error:
• Couldn't match expected type (Number, Number)
with actual type (Number, Number, Number, Number)
• In the argument(s) of rectangle, namely (2, 2, 2, 2)
Expand Down
2 changes: 1 addition & 1 deletion codeworld-compiler/test/testcase/test_arguments/source.hs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
main = drawingOf(rectangle(2,2,2,2))
program = drawingOf(rectangle(2,2,2,2))
2 changes: 1 addition & 1 deletion codeworld-compiler/test/testcase/test_colorName/source.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
main = drawingOf(redWheel)
program = drawingOf(redWheel)
redWheel = colored(wheel, reds)
wheel = solidCircle(4)
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@

program.hs:1:20: error:
program.hs:1:23: error:
• Couldn't match expected type Picture
with actual type Number -> Picture
• Probable cause: a is missing arguments
In the argument(s) of (&), namely a
In the argument(s) of animationOf, namely (a & b)
In the expression: animationOf (a & b)

program.hs:1:20: error:
program.hs:1:23: error:
• Couldn't match expected type Number -> Picture
with actual type Picture
• Possible cause: (&) is applied to too many arguments
In the argument(s) of animationOf, namely (a & b)
In the expression: animationOf (a & b)
In an equation for program: program = animationOf (a & b)

program.hs:1:24: error:
program.hs:1:27: error:
• Couldn't match expected type Picture
with actual type Number -> Picture
• Probable cause: b is missing arguments
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
main = animationOf(a & b)
a(t) = rotated(solidRectangle(1, 1), 45 * t)
b(t) = circle(t)
program = animationOf(a & b)
a(t) = rotated(solidRectangle(1, 1), 45 * t)
b(t) = circle(t)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
main = drawingOf(thing(1) & thing(2))
program = drawingOf(thing(1) & thing(2))
thing(n) = if n > 1 rectangle(n, n) else circle(n)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
main = drawingOf(target)
program = drawingOf(target)
target = pictures([ circle(r) | r = [1, 2, 3, 4, 5] ])
Original file line number Diff line number Diff line change
@@ -1 +1 @@
main = drawingOf(circle(2)
program = drawingOf(circle(2)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

program.hs:1:18: error:
program.hs:1:21: error:
• Variable not in scope: diamond :: Picture
• Perhaps you meant diamonds (line 2)
2 changes: 1 addition & 1 deletion codeworld-compiler/test/testcase/test_nesting/source.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
main = drawingOf(diamond)
program = drawingOf(diamond)
diamonds = rotated(rectangle(2, 2), 45)
4 changes: 2 additions & 2 deletions codeworld-compiler/test/testcase/test_numberType/source.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main :: Program
main = drawingOf(wheel)
program :: Program
program = drawingOf(wheel)

wheel :: Picture
wheel = solidCircle(size)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
program.hs:1:18: error: Missing parentheses in function application


program.hs:7:7: error:
• Couldn't match type [Number] with (Number, Number)
Expected type: Point
Actual type: [Number]
• In the expression: [2, - 4]
In an equation for end: end = [2, - 4]


program.hs:1:21: warning: Missing parentheses in function application.
2 changes: 1 addition & 1 deletion codeworld-compiler/test/testcase/test_pointType/source.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
main = drawingOf(path[start, end])
program = drawingOf(path[start, end])

start :: Point
start = (0, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ program.hs:1:32: error:
(Number, Number) -> Picture)
• In the argument(s) of simulationOf, namely (step, picture)
In the expression: simulationOf (step, picture)
In an equation for program: program = simulationOf (step, picture)
In an equation for program:
program = simulationOf (step, picture)
2 changes: 1 addition & 1 deletion codeworld-compiler/test/testcase/test_simulation/source.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
main = simulationOf(step, picture)
program = simulationOf(step, picture)
step((x, y), dt) = (x - y * dt, y + x * dt)
picture(x, y) = translated(rectangle(1, 1), x, y)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

program.hs:1:18: error:
program.hs:1:21: error:
• Variable not in scope: circl :: Picture
• Perhaps you meant one of these:
circ (line 2), circle (defined in the standard library)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
main = drawingOf(circl)
program = drawingOf(circl)
circ = circle(2)
2 changes: 2 additions & 0 deletions codeworld-error-sanitizer/src/ErrorSanitizer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ filterStages =
, ("a pattern binding", "the definition")
, ("Use -v to see a list of the files searched for\\.", "")
, ("CallStack \\(from HasCallStack\\):", "When evaluating:")
, ("accepting non-standard pattern guards \\(use PatternGuards to suppress this message\\)",
"This arrow <- can't be used here. (To compare a negative number, add a space after <.)")
, ("\n\\s+\n", "\n")
]

Expand Down
2 changes: 2 additions & 0 deletions codeworld-prediction/codeworld-prediction.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Test-Suite test-prediction
Build-depends: base,
containers,
QuickCheck
default-language: Haskell2010

Test-Suite test-prediction-paper
Hs-source-dirs: tests, src
Expand All @@ -37,3 +38,4 @@ Test-Suite test-prediction-paper
Build-depends: base,
containers,
QuickCheck
default-language: Haskell2010

0 comments on commit e87aa85

Please sign in to comment.