diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 39e6b7d72977b568504b26e113a4e662cc2c6320..ec25d717790e18fa84ddd566b1f69f1891d8901f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,15 +24,16 @@ test-assignment: stage: test dependencies: - build-jdk8 - script: "java -cp chocopy-ref.jar:target/assignment.jar chocopy.ChocoPy --pass=.s --dir src/test/data/pa2/sample --test" + script: + - ./run.sh ass test-positive-whole: stage: test dependencies: - build-jdk8 script: - - java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=rs --out /tmp/out.o src/test/data/pa2/sample/ast_coverage.py - - diff /tmp/out.o src/test/data/pa2/sample/ast_coverage.py.ast.typed || echo 'Ignoring failed test...' + - ./run.sh type src/test/data/pa2/sample/ast_coverage.py /tmp/out.o + - diff /tmp/out.o src/test/data/pa2/sample/ast_coverage.py.ast.typed allow_failure: true code_quality: diff --git a/run.sh b/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..e42c38753af62fcadf5b338dac66de68550a8658 --- /dev/null +++ b/run.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +task="$1" +input="$2" +output="$3" + +if [[ "$task" = parse ]]; then + java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=r --out "$output" "$input" +elif [[ "$task" = type ]]; then + java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=.s --out "$output" "$input" +elif [[ "$task" = ass ]]; then + java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=.s --dir src/test/data/pa2/sample --test +fi + +exit $? + + diff --git a/src/main/java/chocopy/pa2/DeclarationAnalyzer.java b/src/main/java/chocopy/pa2/DeclarationAnalyzer.java index 92f02035d7cb4fad52e77efeb6bf4c488ea2415c..5f0814af62eaa370141cc59f11b2a6a4e7f84335 100644 --- a/src/main/java/chocopy/pa2/DeclarationAnalyzer.java +++ b/src/main/java/chocopy/pa2/DeclarationAnalyzer.java @@ -82,25 +82,25 @@ public class DeclarationAnalyzer extends AbstractNodeAnalyzer<SymbolType> { case ">=": case "<=": if(left_type != ValueType.INT_TYPE || right_type != ValueType.INT_TYPE) - throw new RuntimeException("Syntax Error: operand should be INT"); + node.setErrorMsg("Syntax Error: operand should be INT"); break; case "and": case "or": if(left_type != ValueType.BOOL_TYPE || right_type != ValueType.BOOL_TYPE) - throw new RuntimeException("Syntax Error: operand should be BOOL"); + node.setErrorMsg("Syntax Error: operand should be BOOL"); break; case "+": if(left_type != ValueType.INT_TYPE && left_type != ValueType.STR_TYPE && ! left_type.isListType()) - throw new RuntimeException("Syntax Error: operand of + should be INT or STR or LIST"); + node.setErrorMsg("Syntax Error: operand of + should be INT or STR or LIST"); // fallthrough case "==": case "!=": case "is": if(node.left.getInferredType() != node.right.getInferredType()) - throw new RuntimeException("Syntax Error: binary operator operand type mismatch"); + node.setErrorMsg("Syntax Error: binary operator operand type mismatch"); break; default: - throw new RuntimeException("Syntax Error: binary operator operand type not supported."); + node.setErrorMsg("Syntax Error: binary operator operand type not supported."); } // Now set target type.