cw4_marking/c2.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 
       
     5 val res = {
       
     6   if (os.exists(os.pwd / "for.class")) 
       
     7     os.proc("java", "for").call(cwd = os.pwd)
       
     8   else if (os.exists(os.pwd / "for" / "for.class")) 
       
     9     os.proc("java", "for.for").call(cwd = os.pwd)
       
    10   else throw new Exception("No CLASS file found")
       
    11 }
       
    12 
       
    13 /*
       
    14 Try(test_string(ffile, "for")) match {
       
    15   case Success(v) => Console.println(s"   Generated a j-file.")
       
    16   case Failure(e) => Console.println(s"   Exception raised.") ; throw(e)
       
    17 }
       
    18 */
       
    19 
       
    20 if (res.exitCode != 0) {
       
    21   throw new Exception("Unsuccessful call")
       
    22 }
       
    23 
       
    24 Try(res.out.text().replace("\n", "") == "234") match {
       
    25   case Success(v) => Console.println(s"   Success. Printed ${res.out.text().replace("\n", "")}.")
       
    26   case Failure(e) => Console.println(s"   Fail. Printed ${res.out.text()} instead of \"2,3,4\"\n") ; throw(e)
       
    27 }
       
    28 
       
    29 
       
    30 //println(res.out.text())
       
    31 
       
    32 
       
    33 /*
       
    34 
       
    35 
       
    36 // for testing compilation
       
    37 import scala.util.{Try, Success, Failure}
       
    38 
       
    39 import $file.cw041_add
       
    40 import cw041_add._
       
    41 
       
    42 val res = 
       
    43   if (os.exists(os.pwd / "for.class")) {
       
    44 
       
    45   } else if (os.exists(os.pwd / for" / "for.class")) {
       
    46 
       
    47   } else 
       
    48     
       
    49 
       
    50 
       
    51 val ffile = os.read(os.pwd / "for.while")
       
    52 
       
    53 Try(test_string(ffile, "for")) match {
       
    54   case Success(v) => Console.println(s"   Generated a j-file.")
       
    55   case Failure(e) => Console.println(s"   Exception raised.") ; throw(e)
       
    56 }
       
    57 
       
    58 
       
    59 */