# xth test script
#
# This file is a test script for xth (xic Test Harness).  It
# conforms to the following grammar:
#
#   ScriptFile      ::= Commands+
#   Command         ::= build
#                     | CompilerTest
#   CompilerTest    ::= TestKind (\(TestName\))? ([TestPath])? ("CmdLineArgs")?
#                           { (FileTest;)* }
#   TestKind        ::= xic
#   TestName        ::= LitString
#   FileTest        ::= Filenames Description? FailureSet?
#   Filenames       ::= Filename+
#   Description     ::= LitString
#   FailureSet      ::= Failure (, Failure)*
#   Failure         ::= \( ErrorKind \)
#                     | \( ErrorKind, LitString \)
#
#   TestPath        :   the path to the test files, enclosed in quotes,
#                       relative to the path given in xth's -testpath flag.
#   CmdLineArgs     :   command-line arguments for xic
#   Filename        :   the name of a file, interpreted from TestPath.
#   LitString       :   a literal string, enclosed in quotes.
#   ErrorKind       :   one of, or a unique prefix of one of the following
#                       strings: "Lexical Error", "Syntax Error", or
#                       "Semantic Error".
#
# xth runs the commands in order of appearance.

# build compiler first
build

xic ("Test --help") "--help" {
    ;
}

xic ("Test --lex") ["../pa1"] "--lex" {
    ex1.xi;
    ex2.xi (Lexical, "empty character literal");
    spec1.xi;
    spec2.xi;
    spec3.xi;
    gcd.xi;
    ratadd.xi;
    ratadduse.xi;
    insertionsort.xi;
    arrayinit.xi;
    arrayinit2.xi;
    mdarrays.xi;
    add.xi;
    beauty.xi;
}

xic ("Test --parse") ["../pa2"] "--parse" {
    ex1.xi;
    ex2.xi;
    ex3.xi (Syntax, "Unexpected token +");
    spec1.xi;
    spec2.xi;
    spec3.xi;
    gcd.xi;
    ratadd.xi;
    ratadduse.xi;
    insertionsort.xi;
    arrayinit.xi;
    arrayinit2.xi;
    mdarrays.xi;
    add.xi (Syntax, "Unexpected token +");
    beauty.xi (Syntax, "Unexpected token ==");
}

xic ("Test --typecheck") ["../pa3"] "-libpath $(testpath) --typecheck" {
    ex01.xi;
    ex02.xi;
    ex03.xi;
    ex04.xi (Semantic, "Cannot assign");
    ex05.xi (Semantic, "Operands");
    ex06.xi (Semantic, "Name .* cannot be resolved");
    ex07.xi (Semantic, "Expected .*, but found .*");
    ex08.xi (Semantic, "Missing return");
    ex09.xi (Semantic, "Expected function call");
    ex10.xi (Semantic, "Mismatched number of values");
    ex11.xi (Semantic, "Expected .*, but found .*");
    ex12.xi (Semantic, "not a function");
    spec1-full.xi;
    spec1.xi (Semantic, "Name .* cannot be resolved");
    spec2.xi (Semantic, "Name .* cannot be resolved");
    spec3.xi;
    gcd.xi;
    ratadd-full.xi;
    ratadd.xi (Semantic, "Name .* cannot be resolved");
    ratadduse-full.xi;
    ratadduse.xi (Semantic, "Name .* cannot be resolved");
    insertionsort.xi;
    arrayinit.xi;
    arrayinit2-full.xi;
    arrayinit2.xi (Semantic, "Name .* cannot be resolved");
    mdarrays.xi;
}

xic ("Test --irgen") "-libpath $(testpath) --irgen" {
    ex01.xi;
    ack.xi;
    primes.xi;
}

xic ("Test --irgen -O") "-libpath $(testpath) --irgen -O" {
    ex01.xi;
    ack.xi;
    primes.xi;
}
