misc/parser.sh
changeset 342 aa47abb9e723
equal deleted inserted replaced
341:e9d5287c3107 342:aa47abb9e723
       
     1 #!/bin/bash
       
     2 
       
     3 # to make the script fail safely
       
     4 set -euo pipefail
       
     5 
       
     6 
       
     7 out=${1:-output}
       
     8 
       
     9 # compilation tests
       
    10 
       
    11 function scala_compile {
       
    12   (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> ptmp 1> ptmp)
       
    13 }
       
    14 
       
    15 # purity test
       
    16 
       
    17 function scala_vars {
       
    18    (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|new Array' ptmp 2> /dev/null 1> /dev/null)
       
    19 }
       
    20 
       
    21 
       
    22 ### compilation test
       
    23 
       
    24 echo "collatz.scala runs?" | tee -a $out
       
    25 
       
    26 if (scala_compile collatz.scala)
       
    27 then
       
    28   echo "  --> success" | tee -a $out
       
    29   tsts0=$(( 0 ))
       
    30 else
       
    31   echo "  --> scala collatz.scala did not run successfully" | tee -a $out
       
    32   tsts0=$(( 1 )) 
       
    33 fi
       
    34 
       
    35 # var, .par return, ListBuffer test
       
    36 #
       
    37 
       
    38 if  [ $tsts0 -eq 0 ]
       
    39 then
       
    40   echo "collatz.scala does not contain var, return etc?" | tee -a $out
       
    41 
       
    42   if (scala_vars tmp)
       
    43   then
       
    44     echo "  --> test failed" | tee -a $out
       
    45     tsts=$(( 1 ))
       
    46   else
       
    47     echo "  --> success" | tee -a $out
       
    48     tsts=$(( 0 )) 
       
    49   fi
       
    50 fi  
       
    51 
       
    52 ###rm tmp
       
    53 
       
    54