cw5_marking/c6.sc
changeset 978 8778d23fef92
equal deleted inserted replaced
977:1e6eca42d90b 978:8778d23fef92
       
     1 // for testing compilation
       
     2 import scala.util.{Try, Success, Failure}
       
     3 
       
     4 //println("TEST1")
       
     5 
       
     6 val res = {
       
     7   if (os.exists(os.pwd / "sqr.ll")) 
       
     8     os.proc("lli", "sqr.ll").call(cwd = os.pwd, check = false)
       
     9   else throw new Exception("No CLASS file found")
       
    10 }
       
    11 
       
    12 //println("TEST2")
       
    13 
       
    14 /*
       
    15 if (res.exitCode != 0) {
       
    16   throw new Exception("Unsuccessful call")
       
    17 }
       
    18 */
       
    19 
       
    20 def pp(s1: String, s2: String) = {
       
    21   val s1a = s1.replace("\n","").replace(" ","")
       
    22   val s2a = s2.replace("\n","")
       
    23   s1a == s2a
       
    24 }
       
    25 
       
    26 //println("TEST3")
       
    27 
       
    28 val out = "Squares0149162536496481100"
       
    29 val out2 = "\"Squares\"0149162536496481100"
       
    30 
       
    31 
       
    32 //println("TEST4")
       
    33 
       
    34 Try(res.out.text()) match {
       
    35   case Success(v) if (pp(v, out) || pp(v, out2)) => println(s"   Success. Printed out the correct output.\n")
       
    36   case Success(v) => println(s"   Printed out wrong or no output.\n${v}") ; throw new Exception("Wrong Output")
       
    37   case Failure(e) => println(s"   Fail. Printed ${res.out.text()} instead\n") ; throw(e)
       
    38 }
       
    39