# test_cliexec.py
# This contains some tests to make sure that the cliexec runner hasn't been
# broken by some change.

# This also contains other tests so that new files don't have to be created
# for really short tests.

import subprocess, sys

tests = [
    {
     "command": """  integer a = 10\na = "10" """,
     "message": "Make sure that stack trace numbers are sane",
     "stderr": """\
ErrSyntax: Cannot assign type 'string' to type 'integer'.\n\
Where: File "<str>" at line 2\n""",
     "stdout": ""
    },
    {
     "command": """  @>  """,
     "message": "Make sure @> is a parse error if not parsing tags",
     "stderr": """\
ErrSyntax: Found @> but not expecting tags.\n\
Where: File "<str>" at line 1\n""",
     "stdout": ""
    },
    {
     "command": """  \n\n\nif __line__ == 4: print("ok") else: print("failed")  """,
     "message": "Make sure __line__ is right",
     "stderr": "",
     "stdout": "ok"
    },
    {
     "command": """  1  """,
     "message": "Make sure integers can start an expression",
     "stderr": "",
     "stdout": ""
    },
    {
     "command": """  "1"  """,
     "message": "Make sure strings can start an expression",
     "stderr": "",
     "stdout": ""
    },
    {
     "command": """  11.5  """,
     "message": "Make sure numbers can start an expression",
     "stderr": "",
     "stdout": ""
    },
    {
     "command": """  (1)  """,
     "message": "Make sure parentheses can start an expression",
     "stderr": "",
     "stdout": ""
    },
    {
     "command": """  [1, 2, 3].size()  """,
     "message": "Make sure static lists can start an expression",
     "stderr": "",
     "stdout": ""
    },
    {
     "command": """  __line__  """,
     "message": "Make sure __line__ can start an expression",
     "stderr": "",
     "stdout": ""
    },
    {
     "command": """  string s = <[1, "2"]> [1]  """
     "message": "Make sure tuple subscripts know the type",
     "stderr": "",
     "stdout": ""
    },
    {
     "command": """  string s = <[1, "2"]> [3]"""
     "message": "Make sure tuple subscripts don't overflow",
     "stderr": """\
ErrSyntax: Index 3 is out of range for tuple[integer, string].\n\

",
     "stdout": ""
    }
]

test_number = 1
test_total = len(tests)
exit_code = 0

for t in tests:
    sys.stdout.write("[%d of %d] Test: %s..." % (test_number, \
        test_number, t["message"]))

    subp = subprocess.Popen(["./lily_cliexec '%s'" % (t["command"])], \
        stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

    (subp_stdout, subp_stderr) = subp.communicate()
    subp.wait()
    if (subp_stderr != t["stderr"]) or (subp_stdout != t["stdout"]):
        print("failed.\n(Unexpected output). Stopping.\n")
        sys.exit(1)
    else:
        print("passed.")

    test_number += 1

@@ -2173,14 +2173,201 @@
 ing%5D
-.
 %5Cn%5C%0A
-%0A
+Where: File %22%3Cstr%3E%22 at line 1%5Cn%22%22%22,%0A     %22stdout%22: %22%22%0A    %7D%0A    %7B%0A     %22command%22: %22%22%22  %3C%5B1, %221%22%5D%3E == %3C%5B1, %221%22%5D%3E %22%22%22%0A     %22message%22: %22Make sure tuple literals can compare.%22,%0A     %22stderr%22: %22
 %22,%0A 

Fix test_cliexec.py for last commit. Oops.