Skip to content

Commit

Permalink
test: modernize tests (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
matslina authored Feb 20, 2024
1 parent ec18a5c commit 2c08e49
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion test/386_linux_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def run_program(self, path, input):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout, stderr = p.communicate(input)
self.assertEquals(p.returncode, 0)
self.assertEqual(p.returncode, 0)
return stdout

def test_deep_nested_loops(self):
Expand Down
4 changes: 2 additions & 2 deletions test/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def run_ir(self, code, input, expected_output, steps=5000000):

# compare output
for i, (o, e) in enumerate(zip(prog_out, expected_output)):
self.assertEquals(o, e, "outputs differ at position %d: "
self.assertEqual(o, e, "outputs differ at position %d: "
"expected %d, got %d" % (i, e, o))
self.assertEquals(len(prog_out), len(expected_output))
self.assertEqual(len(prog_out), len(expected_output))

def test_empty_program(self):
self.run_ir([],[],[])
Expand Down
24 changes: 12 additions & 12 deletions test/frontend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ def _check_post_condition(self, mem, code, target=None, maxdepth=None):
"""Checks frontend post execution memory against expected ir code."""

# sanity
self.assert_(len(mem) >= 6, "post exec memory must span at least 6 "
self.assertTrue(len(mem) >= 6, "post exec memory must span at least 6 "
"cells, only got %d" % len(mem))
if target is not None:
self.assertEquals(mem[0], target,
self.assertEqual(mem[0], target,
"bad target platform (%d!=%d)" % (mem[0],target))
else:
self.assert_(mem[0] in (_LANG_C, _386_LINUX),
self.assertTrue(mem[0] in (_LANG_C, _386_LINUX),
"frontend chose bad target platform T (=%d)" % mem[0])
self.assertEquals(mem[1], 0, "frontend should leave cell 1 blank")
self.assert_(mem[2], "frontend marked bytecode as not OK")
self.assertEqual(mem[1], 0, "frontend should leave cell 1 blank")
self.assertTrue(mem[2], "frontend marked bytecode as not OK")

# find end of compiled code block
i = 3
while i < len(mem) and mem[i] != 0:
i += 2

# more sanity
self.assert_( not (len(mem) < i+3), "maximum loop depth is missing")
self.assert_( not (len(mem) > i+3), "junk data beyond max loop depth")
self.assertTrue( not (len(mem) < i+3), "maximum loop depth is missing")
self.assertTrue( not (len(mem) > i+3), "junk data beyond max loop depth")
if maxdepth is not None:
Mm = mem[i+1]*0xff + mem[i+2]
self.assertEquals(Mm, maxdepth, "wrong max depth, got %d not %d" %
self.assertEqual(Mm, maxdepth, "wrong max depth, got %d not %d" %
(Mm, maxdepth))


Expand All @@ -69,7 +69,7 @@ def _check_post_condition(self, mem, code, target=None, maxdepth=None):
def _run_and_check_ir(self, program, ir, maxdepth=1):
out, mem = self.run_bf(self.code, program,
precondition=[1], steps=10000000)
self.assertEquals(out, [], "frontend should not produce output")
self.assertEqual(out, [], "frontend should not produce output")
self._check_post_condition(mem, ir, maxdepth=maxdepth)

def test_empty_input(self):
Expand Down Expand Up @@ -419,7 +419,7 @@ def _run_and_check_target(self, default_target, target, program, ir=[]):
default_target = 17 # some target
out, mem = self.run_bf(self.code, program,
precondition=[default_target], steps=500000)
self.assertEquals(out, [], "frontend should not produce output")
self.assertEqual(out, [], "frontend should not produce output")
self._check_post_condition(mem, ir, target=target)

def test_target_empty(self):
Expand Down Expand Up @@ -470,9 +470,9 @@ def test_target_386_linux(self):
def _run_and_check_mismatched(self, program):
out, mem = self.run_bf(self.code, program,
precondition=[1], steps=5000000)
self.assertEquals(''.join(chr(c) for c in out),
self.assertEqual(''.join(chr(c) for c in out),
'Error: unbalanced brackets!\n')
self.assertEquals(mem[2], 0, "code should not be marked as ok")
self.assertEqual(mem[2], 0, "code should not be marked as ok")

def test_unbalanced_loop(self):
self._run_and_check_mismatched("[")
Expand Down
2 changes: 1 addition & 1 deletion test/go_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def run_program(self, path, input):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout, stderr = p.communicate(input)
self.assertEquals(p.returncode, 0)
self.assertEqual(p.returncode, 0)
return stdout


Expand Down
2 changes: 1 addition & 1 deletion test/java_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def run_program(self, path, input):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout, stderr = p.communicate(input)
self.assertEquals(p.returncode, 0)
self.assertEqual(p.returncode, 0)
return stdout

def test_deep_nested_loops(self):
Expand Down
4 changes: 2 additions & 2 deletions test/lang_c_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, *args, **kwargs):

p = subprocess.Popen(['gcc', '-v'], stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
self.assertEquals(p.returncode, 0)
self.assertEqual(p.returncode, 0)

if "clang" in stderr.decode("utf-8"):
self.cc_flags = ["-fbracket-depth=512"]
Expand All @@ -27,7 +27,7 @@ def run_program(self, path, input):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout, stderr = p.communicate(input)
self.assertEquals(p.returncode, 0)
self.assertEqual(p.returncode, 0)
return stdout


Expand Down
7 changes: 6 additions & 1 deletion test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
suite = loader.discover('.', pattern='*_test.py')

runner = unittest.TextTestRunner()
runner.run(suite)
result = runner.run(suite)

if not result.wasSuccessful():
sys.exit(1)
else:
sys.exit(0)
2 changes: 1 addition & 1 deletion test/ruby_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def run_program(self, path, input):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout, stderr = p.communicate(input)
self.assertEquals(p.returncode, 0)
self.assertEqual(p.returncode, 0)
return stdout


Expand Down
2 changes: 1 addition & 1 deletion test/tcl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def run_program(self, path, input):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout, stderr = p.communicate(input)
self.assertEquals(p.returncode, 0)
self.assertEqual(p.returncode, 0)
return stdout


Expand Down

0 comments on commit 2c08e49

Please sign in to comment.