#!/bin/bash

task="$1"
input="$2"
output="$3"

# recolic: I edited class FuncDef so place target/assignment.jar before chocopy-ref.jar!
classPath="target/assignment.jar:chocopy-ref.jar"

if [[ "$task" = parse ]]; then
    java -cp "$classPath" chocopy.ChocoPy --pass=r --out "$output" "$input"
elif [[ "$task" = type ]]; then
    java -cp "$classPath" chocopy.ChocoPy --pass=.s --out "$output" "$input"
elif [[ "$task" = ass ]]; then
    java -cp "$classPath" chocopy.ChocoPy --pass=.s --dir src/test/data/pa2/sample --test | tee /tmp/cs164_ass.log
    # Should pass all positive test, else return error_code=2
    cat /tmp/cs164_ass.log | grep Test: | grep failed | grep -v sample/bad_ && exit 2 || exit 0
elif [[ "$task" = build ]]; then
    mvn clean package > /dev/null 2>&1 && echo success || echo failed
fi

exit $?


