cw4_marking/cw4_test.sh
changeset 978 8778d23fef92
equal deleted inserted replaced
977:1e6eca42d90b 978:8778d23fef92
       
     1 #!/bin/zsh
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 
       
     7 out=${1:-output}
       
     8 
       
     9 echo -e "" > $out
       
    10 
       
    11 echo `date` | tee -a $out
       
    12 echo "" >> $out
       
    13 echo "Below is the feedback and provisional marks for your CW 4 submission." >> $out
       
    14 echo "Please note all marks are provisional until ratified by the" >> $out
       
    15 echo "assessment board -- this is not an official results transcript." >> $out
       
    16 echo "" >> $out
       
    17 
       
    18 echo "The feedback for your submission for cw04.sc" >> $out
       
    19 echo "" >> $out
       
    20 
       
    21 # marks for CW 4
       
    22 marks=$(( 0.0 ))
       
    23 
       
    24 # compilation tests
       
    25 
       
    26 function scala_compile {
       
    27   (ulimit -t 30; JAVA_OPTS="-Xmx1g" amm -s "$1" 2> c$out 1> c$out)
       
    28 }
       
    29 
       
    30 # functional tests
       
    31 
       
    32 function scala_assert {
       
    33   rm -rf /Users/cu/.ammonite/cache/3.0.0-M2/* 2> /dev/null ;  
       
    34   (ulimit -t 30; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm -s "$1" 1>> $out 2>> $out)
       
    35 }
       
    36 
       
    37 function scala_fail {
       
    38   (ulimit -t 30; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm -s "$1" 1>> $out 2>> $out)
       
    39 }
       
    40 
       
    41 
       
    42 ### compilation test
       
    43 
       
    44 echo -e "0) cw04.sc compiles?" | tee -a $out
       
    45 
       
    46 if (scala_compile "c.sc")
       
    47 then
       
    48     echo -e "    --> yes cw04.sc compiles\n" | tee -a $out
       
    49     tsts=$(( 0 ))
       
    50 else
       
    51     echo -e "    --> AMM DID NOT compile cw04.sc\n" | tee -a $out
       
    52     cat c$out | tee -a $out
       
    53     tsts=$(( 1 ))
       
    54 fi
       
    55 
       
    56 ### fib.j test
       
    57 echo >> $out
       
    58 #echo -e "\n\n\n" >> $out
       
    59 
       
    60 if [ $tsts -eq 0 ]
       
    61 then
       
    62     echo -e "1.1) fib.j is not empty?" | tee -a $out
       
    63 
       
    64     if [ -s fib.j ]
       
    65     then
       
    66         echo -e "  --> success" | tee -a $out
       
    67         tstsA=$(( 0 ))
       
    68     else
       
    69         echo -e "  --> FAIL\n" | tee -a $out
       
    70         tstsA=$(( 1 ))
       
    71     fi
       
    72 fi
       
    73 
       
    74 echo >> $out
       
    75 
       
    76 if [ $tstsA -eq 0 ]
       
    77 then
       
    78     echo -e "1.2) Generating a class-file for fib.j:" | tee -a $out
       
    79     echo -e "   java -jar jasmin.jar fib.j\n" | tee -a $out
       
    80 
       
    81     java -jar /Users/cu/jasmin.jar fib.j 1> /dev/null 2> outj
       
    82 
       
    83     if [ -s outj ]
       
    84     then
       
    85         echo -e "  --> The jasmin assembler generated the following error message:\n" | tee -a $out
       
    86         cat outj >> $out
       
    87     else
       
    88 	echo -e "   --> success (+ 5.0 Marks)\n" | tee -a $out
       
    89         marks=$(( marks + 5.0 ))
       
    90     fi
       
    91 fi
       
    92 
       
    93 ### for test
       
    94 echo >> $out
       
    95 #echo -e "\n\n\n" >> $out
       
    96 
       
    97 if [ $tsts -eq 0 ]
       
    98 then
       
    99     echo -e "2.1) Generating j-file for the file:\n" | tee -a $out
       
   100     cat "for.while" | pr -to10 >> $out
       
   101     echo >> $out
       
   102     cat cw04.sc c1_add.sc > cw041_add.sc
       
   103     
       
   104     if (scala_assert "c1.sc")
       
   105     then
       
   106         echo -e "  --> success" | tee -a $out
       
   107         tstsB=$(( 0 ))
       
   108     else
       
   109         echo -e "  --> FAIL\n" | tee -a $out
       
   110         cat c$out >> $out
       
   111 	tail -25 $out | pr -to10
       
   112         tstsB=$(( 1 ))
       
   113     fi
       
   114 fi
       
   115 
       
   116 echo >> $out
       
   117 
       
   118 if [ $tstsB -eq 0 ]
       
   119 then
       
   120     echo -e "2.2) Generating a class-file for this file:" | tee -a $out
       
   121     echo -e "   java -jar jasmin.jar for.j\n" | tee -a $out
       
   122     java -jar /Users/cu/jasmin.jar for.j 1> /dev/null 2> outj
       
   123 
       
   124     if [ -s outj ]
       
   125     then
       
   126         echo -e "  --> The jasmin assembler generated the following error message:\n" | tee -a $out
       
   127         cat outj >> $out
       
   128 	tstsB=$(( 1 ))
       
   129     else
       
   130 	echo -e "   --> success\n" | tee -a $out
       
   131 	tstsB=$(( 0 ))
       
   132     fi
       
   133 fi
       
   134 
       
   135 if [ $tstsB -eq 0 ]
       
   136 then
       
   137     echo -e "2.3) Running for.j" | tee -a $out
       
   138     if (scala_assert "c2.sc")
       
   139     then
       
   140         echo -e "  --> success (+ 5.0 Marks)\n" | tee -a $out
       
   141 	marks=$(( marks + 5.0 ))
       
   142     else
       
   143         echo -e "  --> FAIL\n" | tee -a $out
       
   144 	tail -25 $out | pr -to10
       
   145         cat c$out >> $out
       
   146     fi
       
   147 fi
       
   148 
       
   149 ##############################
       
   150 
       
   151 ### break test
       
   152 echo >> $out
       
   153 #echo -e "\n\n\n" >> $out
       
   154 
       
   155 if [ $tsts -eq 0 ]
       
   156 then
       
   157     echo -e "3.1) Generating j-file for the file:\n" | tee -a $out
       
   158     cat "br.while" | pr -to10 >> $out
       
   159     echo >> $out
       
   160     cat cw04.sc c1_add.sc > cw041_add.sc
       
   161     
       
   162     if (scala_assert "c3.sc")
       
   163     then
       
   164         echo -e "  --> success" | tee -a $out
       
   165         tstsC=$(( 0 ))
       
   166     else
       
   167         echo -e "  --> FAIL\n" | tee -a $out
       
   168         cat c$out >> $out
       
   169 	tail -25 $out | pr -to10
       
   170         tstsC=$(( 1 ))
       
   171     fi
       
   172 fi
       
   173 
       
   174 echo >> $out
       
   175 
       
   176 if [ $tstsC -eq 0 ]
       
   177 then
       
   178     echo -e "3.2) Generating a class-file for this file:" | tee -a $out
       
   179     echo -e "   java -jar jasmin.jar br.j\n" | tee -a $out
       
   180     java -jar /Users/cu/jasmin.jar br.j 1> /dev/null 2> outj
       
   181 
       
   182     if [ -s outj ]
       
   183     then
       
   184         echo -e "  --> The jasmin assembler generated the following error message:\n" | tee -a $out
       
   185         cat outj >> $out
       
   186 	tstsC=$(( 1 ))
       
   187     else
       
   188 	echo -e "   --> success\n" | tee -a $out
       
   189 	tstsC=$(( 0 ))
       
   190     fi
       
   191 fi
       
   192 
       
   193 if [ $tstsC -eq 0 ]
       
   194 then
       
   195     echo -e "3.3) Running br.j" | tee -a $out
       
   196     if (scala_assert "c4.sc")
       
   197     then
       
   198         echo -e "  --> success (+ 5.0 Marks)\n" | tee -a $out
       
   199 	marks=$(( marks + 5.0 ))
       
   200     else
       
   201         echo -e "  --> FAIL\n" | tee -a $out
       
   202 	tail -25 $out | pr -to10
       
   203         cat c$out >> $out
       
   204     fi
       
   205 fi
       
   206 
       
   207 
       
   208 
       
   209 
       
   210 
       
   211 
       
   212 echo >> $out
       
   213 
       
   214 ## final marks
       
   215 echo >> $out
       
   216 echo "Overall mark for CW 4" | tee -a $out
       
   217 printf " %0.2f\n" $marks | tee -a $out
       
   218 
       
   219 
       
   220