cw5_marking/c4.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 / "mand.ll")) 
       
     8     os.proc("lli", "mand.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.split("\n").toList
       
    22   val s2a = s2.split("\n").toList
       
    23   for (n <- 0 to (s1a.length - 1)) {
       
    24     println(s"|${s1a(n)}|")
       
    25     println(s">${Try(s2a(n)).getOrElse("")}<")
       
    26   }
       
    27 }
       
    28 
       
    29 //println("TEST3")
       
    30 
       
    31 val out = os.read(os.pwd / "mand.out")
       
    32 
       
    33 //println("TEST4")
       
    34 
       
    35 Try(res.out.text()) match {
       
    36   case Success(v) if v == out => println(s"   Success. Printed out the correct picture.\n")
       
    37   case Success(v) => println(s"   Printed out wrong or no picture.\n${pp(v, out)}") ; throw new Exception("Wrong picture")
       
    38   case Failure(e) => println(s"   Fail. Printed ${res.out.text()} instead\n") ; throw(e)
       
    39 }
       
    40