cw2_marking/cw2_test.sh
changeset 1039 86d59b074abe
parent 980 4f422766763f
equal deleted inserted replaced
1038:34d2cfb7761a 1039:86d59b074abe
     1 #!/bin/zsh
     1 #!/bin/zsh -o pipefail
     2 
     2 
     3 # to make the script fail safely
     3 # to make the script fail safely
     4 set -euo pipefail
     4 #set -euo pipefail
     5 
     5 
     6 
     6 
     7 out=${1:-output}
     7 out=${1:-output}
     8 
     8 
     9 echo -e "" > $out
     9 echo -e "" > $out
    22 marks=$(( 0.0 ))
    22 marks=$(( 0.0 ))
    23 
    23 
    24 # compilation tests
    24 # compilation tests
    25 
    25 
    26 function scala_compile {
    26 function scala_compile {
    27   (ulimit -t 30; JAVA_OPTS="-Xmx1g" amm -s "$1" 2> c$out 1> c$out)
    27   (ulimit -t 30; JAVA_OPTS="-Xmx1g" amm -s "$1" 2> e$out 1> c$out)
    28 }
    28 }
    29 
    29 
    30 # functional tests
    30 # functional tests
    31 
    31 
    32 function scala_assert {
    32 function scala_assert {
    33   rm -rf /Users/cu/.ammonite/cache/3.*/* 2> /dev/null ;  
    33   rm -rf /Users/cu/.ammonite/cache/3.*/* 2> /dev/null ;  
    34   (ulimit -t 30; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm -s "$1" 1>> $out 2>> $out)
    34   (ulimit -t 30; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm --no-warn -s "$1" 1>> $out 2>> $out)
    35 }
    35 }
    36 
    36 
    37 function scala_fail {
    37 function scala_fail {
    38   #rm -rf /Users/cu/.ammonite/cache/3.0.0-M2/* 2> /dev/null ;  
    38   rm -rf /Users/cu/.ammonite/cache/3.*/* 2> /dev/null ;  
    39   (ulimit -t 30; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm -s "$1") # 1>> $out 2>> $out)
    39   (ulimit -t 30; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm --no-warn  -s "$1") # 1>> $out 2>> $out)
    40 }
    40 }
    41 
    41 
    42 
    42 # remove @main
       
    43 gsed -i -e "s|@main||g" cw02.sc
    43 
    44 
    44 ### compilation test
    45 ### compilation test
    45 
    46 
    46 echo -e "0) cw02.sc compiles?\n" | tee -a $out
    47 echo -e "0) cw02.sc compiles?\n" | tee -a $out
    47 
    48 
    49 then
    50 then
    50     echo -e "   --> yes cw02.sc compiles\n" | tee -a $out
    51     echo -e "   --> yes cw02.sc compiles\n" | tee -a $out
    51     tsts=$(( 0 ))
    52     tsts=$(( 0 ))
    52 else
    53 else
    53     echo -e "   --> AMM DID NOT compile cw02.sc\n" | tee -a $out
    54     echo -e "   --> AMM DID NOT compile cw02.sc\n" | tee -a $out
    54     cat c$out | tee -a $out
    55     tail -25 e$out | pr -to10 | tee -a $out
    55     echo -e "\n\n" >> $out
    56     echo -e "\n\n" | tee -a $out
    56     tsts=$(( 1 ))
    57     tsts=$(( 1 ))
    57 fi
    58 fi
    58 
    59 
    59 echo >> $out
    60 echo >> $out
    60 
    61 
    72 	marks=$(( marks + 3.0 ))
    73 	marks=$(( marks + 3.0 ))
    73     else
    74     else
    74 	echo -e "   --> FAILED\n" | tee -a $out
    75 	echo -e "   --> FAILED\n" | tee -a $out
    75 	echo -e "       instead it generates:\n" | tee -a $out
    76 	echo -e "       instead it generates:\n" | tee -a $out
    76 	(scala_fail "c1a.sc" || true) | tee -a $out
    77 	(scala_fail "c1a.sc" || true) | tee -a $out
    77 	echo -e "\n\n" >> $out
    78 	echo -e "\n\n" | tee -a $out
    78     fi
    79     fi
    79 fi
    80 fi
    80 
    81 
    81 ### tokenise test
    82 ### tokenise test
    82 echo >> $out
    83 echo >> $out
    83 #echo -e "\n\n\n" >> $out
    84 #echo -e "\n\n\n" >> $out
    84 
    85 
    85 if [ $tsts -eq 0 ]
    86 if [ $tsts -eq 0 ]
    86 then
    87 then
    87   echo -e "2) Tokenise test with example files (does it raise an exception):\n" | tee -a $out
    88   echo -e "2) Tokenise tests with example files (no exception is raised):\n" | tee -a $out
    88   cat cw02.sc c3_add.sc > cw023_add.sc  
    89   cat cw02.sc c3_add.sc > cw023_add.sc  
    89   if (scala_assert "c3.sc")
    90   if (scala_assert "c3.sc")
    90   then
    91   then
    91       echo -e "   --> success (+ 3.0 Marks)\n" | tee -a $out
    92       echo -e "   --> success (+ 3.0 Marks)\n" | tee -a $out
    92       marks=$(( marks + 3.0 ))
    93       marks=$(( marks + 3.0 ))
   119 #echo -e "\n\n\n" >> $out
   120 #echo -e "\n\n\n" >> $out
   120 
   121 
   121 if [ $tsts -eq 0 ]
   122 if [ $tsts -eq 0 ]
   122 then
   123 then
   123     echo -e "4) Are regex constructors all primitive?\n" | tee -a $out
   124     echo -e "4) Are regex constructors all primitive?\n" | tee -a $out
   124     echo -e "   For example, RANGE.toString == \"RANGE\"\n" | tee -a $out
   125     echo -e "   For example, PLUS.toString == \"PLUS\"" | tee -a $out
       
   126     echo -e "                NTIMES.toString == \"NTIMES\"\n" | tee -a $out  
   125     if (scala_assert "c5.sc")
   127     if (scala_assert "c5.sc")
   126     then
   128     then
   127 	echo -e "   --> FAILED\n" | tee -a $out
       
   128 	tail -25 $out | pr -to10
       
   129 	echo -e "\n\n" >> $out
       
   130     else
       
   131 	echo -e "   --> success (+ 2.0 Marks)\n" | tee -a $out
   129 	echo -e "   --> success (+ 2.0 Marks)\n" | tee -a $out
   132 	marks=$(( marks + 2.0 ))
   130 	marks=$(( marks + 2.0 ))
       
   131     else
       
   132 	echo -e "   --> FAILED\n" | tee -a $out
       
   133 	#tail -25 $out | pr -to10
       
   134 	#echo -e "\n\n" | tee -a $out
   133     fi
   135     fi
   134 fi
   136 fi
   135 
   137 
   136 
   138 
   137 ## final marks
   139 ## final marks