- Can record compilation behaviour.
expected_stderr = ''
expected_returncode = -1
+ build_expected_stdout = ''
+ build_expected_stderr = ''
+ build_expected_returncode = -1
+
def __init__(self, name):
self.name = name
else:
self.expected_returncode = int(self.expected_returncode)
+ self.build_expected_stdout = read_or_create_expected_file("build.out")
+ self.build_expected_stderr = read_or_create_expected_file("build.err")
+ self.build_expected_returncode = read_or_create_expected_file("build.code")
+ if self.build_expected_returncode == '':
+ self.build_expected_returncode = -1
+ else:
+ self.build_expected_returncode = int(self.build_expected_returncode)
+
# if self.expected_stdout: print(f"{self.name}.out.expected: {self.expected_stdout}")
# if self.expected_stderr: print(f"{self.name}.err.expected: {self.expected_stderr}")
def save_expected(self):
write_expected("err", self.expected_stderr)
write_expected("code", str(self.expected_returncode))
+ write_expected("build.out", self.build_expected_stdout)
+ write_expected("build.err", self.build_expected_stderr)
+ write_expected("build.code", str(self.build_expected_returncode))
+
def usage(program: str):
print(f"Usage: {program} <subcmd> [flags]")
def hhelp():
print('''
Subcommands:
- help - Prints this help message.
- build - Builds all the tests.
- run - Runs all the tests.
- record - Records the expected behaviour of all the tests.
+ help - Prints this help message.
+ build - Builds all the tests.
+ run - Runs all the tests.
+ record - Records the expected behaviour of all the tests.
+ record_build - Records the expected build behaviour of all the tests.
Flags:
-h - Same as the help subcommand.
current_test_id += 1
test = tests[test_name]
+ if test.build_expected_returncode == -1:
+ print(f"[WARNING] Test doesn't have any expected build returncode!")
+ print(f"[WARNING] Please record the expected build behaviour of the test using the 'record_build' subcommand!")
+ print(f"[SKIPPING]...")
+ continue
+
cmd = [COMPILER, f"{test_name}{SUFFIX}"]
vlog(verbose_output, f"[CMD] {cmd}")
- res = subprocess.run(cmd,
- capture_output = True,
- text = True)
+ res = subprocess.run(cmd, capture_output = True, text = True)
if res.returncode != 0:
print("[FAILED] ", end='')
if res.stderr:
print(f"+ Recording expected behaviour for '{test_name}'...")
test = tests[test_name]
+ res = subprocess.run([f"./{test_name}"], capture_output = True, text = True)
+
+ print(f"stdout: {res.stdout}")
+ print(f"stderr: {res.stderr}")
+ print(f"returncode: {res.returncode}")
+
prompt_msg = "Record current behaviour as the expected one? [y/N]"
ans = input(prompt_msg)
if ans.lower() == "y":
- res = subprocess.run([f"./{test_name}"],
- capture_output = True,
- text = True)
tests[test_name].expected_stdout = res.stdout
tests[test_name].expected_stderr = res.stderr
tests[test_name].expected_returncode = res.returncode
print('[SUCCESS] Recorded expected behaviour')
else:
print('[SKIP]')
+ elif subcmd == "record_build":
+ print(f'----- [RECORD_BUILD] -----')
+ for test_name in tests:
+ print(f"+ Recording expected build behaviour for '{test_name}'...")
+ test = tests[test_name]
+
+ cmd = [COMPILER, f"{test_name}{SUFFIX}"]
+ vlog(verbose_output, f"[CMD] {cmd}")
+ res = subprocess.run(cmd, capture_output = True, text = True)
+
+ print(f"stdout: {res.stdout}")
+ print(f"stderr: {res.stderr}")
+ print(f"returncode: {res.returncode}")
+
+ prompt_msg = "Record current build behaviour as the expected one? [y/N]"
+ ans = input(prompt_msg)
+
+ if ans.lower() == "y":
+
+ tests[test_name].build_expected_stdout = res.stdout
+ tests[test_name].build_expected_stderr = res.stderr
+ tests[test_name].build_expected_returncode = res.returncode
+ tests[test_name].save_expected()
+ print('[SUCCESS] Recorded expected behaviour')
+ else:
+ print('[SKIP]')
else:
print(f"[ERROR] Invalid subcommand '{subcmd}'", file=sys.stderr)
+++ /dev/null
-"Unterminated string
+++ /dev/null
-[ERROR] ./tests/01-unterminated-string.momo:1:21: Unterminated string!
+++ /dev/null
-"This is a long ass string"
+++ /dev/null
-"Token (String, 'This is a long ass string', ./tests/02-string.momo:1:0)"
+++ /dev/null
-
-
-"This is a long ass string"
+++ /dev/null
-("Token (String, 'This is a long ass string', "
- './tests/03-whitespaced-string.momo:3:0)')
+++ /dev/null
-"Token (Ident, 'foo', ./tests/04-identifier.momo:1:4)"
+++ /dev/null
- foo
-bar baz
+++ /dev/null
-"Token (Ident, 'foo', ./tests/05-multiple-identifiers.momo:1:3)"
-"Token (Ident, 'bar', ./tests/05-multiple-identifiers.momo:2:1)"
-"Token (Ident, 'baz', ./tests/05-multiple-identifiers.momo:2:5)"
+++ /dev/null
-() {} [] ->
-- + / * %
-= !
->= > < <= != ==
-, : ; .
-
-& | ~
-
-&& ||
-
+++ /dev/null
-"Token (Left Paren, '(', ./tests/06-symbols.momo:1:0)"
-"Token (Right Paren, ')', ./tests/06-symbols.momo:1:1)"
-"Token (Left Brace, '{', ./tests/06-symbols.momo:1:3)"
-"Token (Right Brace, '}', ./tests/06-symbols.momo:1:4)"
-"Token (Left Square Brace, '[', ./tests/06-symbols.momo:1:6)"
-"Token (Right Square Brace, ']', ./tests/06-symbols.momo:1:7)"
-"Token (Returner, '->', ./tests/06-symbols.momo:1:9)"
-"Token (Minus, '-', ./tests/06-symbols.momo:2:0)"
-"Token (Plus, '+', ./tests/06-symbols.momo:2:2)"
-"Token (Divide, '/', ./tests/06-symbols.momo:2:4)"
-"Token (Multiply, '*', ./tests/06-symbols.momo:2:6)"
-"Token (Modulus, '%', ./tests/06-symbols.momo:2:8)"
-"Token (Equal, '=', ./tests/06-symbols.momo:3:0)"
-"Token (Not, '!', ./tests/06-symbols.momo:3:2)"
-"Token (Greater Than or Equal, '>=', ./tests/06-symbols.momo:4:0)"
-"Token (Greater Than, '>', ./tests/06-symbols.momo:4:3)"
-"Token (Less Than, '<', ./tests/06-symbols.momo:4:5)"
-"Token (Less Than or Equal, '<=', ./tests/06-symbols.momo:4:7)"
-"Token (Not Equal, '!=', ./tests/06-symbols.momo:4:10)"
-"Token (Equal Equal, '==', ./tests/06-symbols.momo:4:13)"
-"Token (Comma, ',', ./tests/06-symbols.momo:5:0)"
-"Token (Colon, ':', ./tests/06-symbols.momo:5:2)"
-"Token (Semicolon, ';', ./tests/06-symbols.momo:5:4)"
-"Token (Dot, '.', ./tests/06-symbols.momo:5:6)"
-"Token (Binary And, '&', ./tests/06-symbols.momo:7:0)"
-"Token (Binary Or, '|', ./tests/06-symbols.momo:7:2)"
-"Token (Binary Not, '~', ./tests/06-symbols.momo:7:4)"
-"Token (Logical And, '&&', ./tests/06-symbols.momo:9:0)"
-"Token (Logical Or, '||', ./tests/06-symbols.momo:9:3)"
+++ /dev/null
-"Token (Int, '69', ./tests/07-numbers.momo:1:1)"
-"Token (Int, '100', ./tests/07-numbers.momo:3:1)"
+++ /dev/null
-69.0
-100.15134324
-420.11
+++ /dev/null
-"Token (Float, '69.0', ./tests/08-floating-point-numbers.momo:1:1)"
-"Token (Float, '100.15134324', ./tests/08-floating-point-numbers.momo:2:1)"
-"Token (Float, '420.11', ./tests/08-floating-point-numbers.momo:3:1)"
--- /dev/null
+0
\ No newline at end of file
--- /dev/null
+identifiers.momo:1:0 [IDENT] 'foo'
+identifiers.momo:2:1 [IDENT] 'bar'
+identifiers.momo:2:5 [IDENT] 'baz'
+identifiers.momo:8:0 [IDENT] 'A'
+identifiers.momo:8:2 [IDENT] 'B'
+identifiers.momo:8:4 [IDENT] 'C'
+identifiers.momo:10:0 [IDENT] '_D'
+identifiers.momo:10:3 [IDENT] 'eE'
+identifiers.momo:10:6 [IDENT] '_F'
+identifiers.momo:10:9 [IDENT] '_G'
+[INFO] OK
--- /dev/null
+-1
\ No newline at end of file
--- /dev/null
+foo
+ bar baz
+
+
+
+
+
+A B C
+
+_D eE _F _G
--- /dev/null
+0
\ No newline at end of file
--- /dev/null
+operators.momo:1:7 [MINUS] '-'
+operators.momo:2:0 [MINUS_MINUS] '--'
+operators.momo:3:0 [RETURNER] '->'
+operators.momo:4:0 [PLUS] '+'
+operators.momo:5:0 [PLUS_PLUS] '++'
+operators.momo:6:0 [PLUS_EQUAL] '+='
+operators.momo:7:0 [DIVIDE] '/'
+operators.momo:8:0 [DIVIDE_EQUAL] '/='
+operators.momo:9:0 [MULTIPLY] '*'
+operators.momo:10:0 [POWER] '**'
+operators.momo:11:0 [MULTIPLY_EQUAL] '*='
+operators.momo:12:0 [MODULUS] '%'
+operators.momo:13:0 [MODULUS_EQUAL] '%='
+operators.momo:15:0 [BITWISE_AND] '&'
+operators.momo:16:0 [BITWISE_AND_EQUAL] '&='
+operators.momo:17:0 [BITWISE_XOR] '^'
+operators.momo:18:0 [BITWISE_XOR_EQUAL] '^='
+operators.momo:19:0 [BITWISE_NOT] '~'
+operators.momo:20:0 [BITWISE_OR] '|'
+operators.momo:21:0 [BITWISE_OR_EQUAL] '|='
+operators.momo:23:0 [NOT] '!'
+operators.momo:24:0 [NOT_EQUAL] '!='
+operators.momo:25:0 [LOGICAL_AND] '&&'
+operators.momo:26:0 [LOGICAL_OR] '||'
+operators.momo:28:0 [EQUAL] '='
+operators.momo:29:0 [EQUAL_EQUAL] '=='
+[INFO] OK
--- /dev/null
+-1
\ No newline at end of file
--- /dev/null
+ -
+--
+->
++
+++
++=
+/
+/=
+*
+**
+*=
+%
+%=
+
+&
+&=
+^
+^=
+~
+|
+|=
+
+!
+!=
+&&
+||
+
+=
+==
--- /dev/null
+0
\ No newline at end of file
--- /dev/null
+strings.momo:1:1 [STRING] 'This is a string!'
+strings.momo:4:9 [STRING] 'This too is a string!'
+[INFO] OK
--- /dev/null
+-1
\ No newline at end of file
--- /dev/null
+"This is a string!"
+
+
+ "This too is a string!"