Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 54 lines (37 sloc) 1.479 kb
5973f27 Anton Barkovsky Add tests that only check if assembly is successful
swarmer authored
1 import nose.tools as nose
2 import os
3 import subprocess
4
5
6 ASSEMBLY_OUTPUT = "__test_output.obj"
7 SOURCE_DIR = "examples"
57b841c Anton Barkovsky Add comparison with prebuilt binaries
swarmer authored
8 BINARY_DIR = "test_binaries"
5973f27 Anton Barkovsky Add tests that only check if assembly is successful
swarmer authored
9
326bd0b Anton Barkovsky Refactor tests
swarmer authored
10 def tearDownModule():
5973f27 Anton Barkovsky Add tests that only check if assembly is successful
swarmer authored
11 if os.path.exists(ASSEMBLY_OUTPUT):
12 os.remove(ASSEMBLY_OUTPUT)
13
14 def example(name):
15 return os.path.join(SOURCE_DIR, name + ".asm")
16
326bd0b Anton Barkovsky Refactor tests
swarmer authored
17 def check_path(assembler, path):
18 code = subprocess.call([assembler, path, ASSEMBLY_OUTPUT])
206bcd4 Anton Barkovsky Improve messaged in tests
swarmer authored
19 nose.assert_equal(code, 0, "Assembly of {0} failed!".format(path))
57b841c Anton Barkovsky Add comparison with prebuilt binaries
swarmer authored
20
21 assert path.endswith(".asm")
22 binary = os.path.join(BINARY_DIR, os.path.basename(path)[:-4] + ".bin")
23 if os.path.exists(binary):
24 with open(ASSEMBLY_OUTPUT, "rb") as testing, open(binary, "rb") as tested:
206bcd4 Anton Barkovsky Improve messaged in tests
swarmer authored
25 nose.assert_equal(testing.read(), tested.read(), "Produced and tested binaries differ!")
af04fe7 Anton Barkovsky More tests
swarmer authored
26
27
28 # asm.py
29 def test_example_asm():
326bd0b Anton Barkovsky Refactor tests
swarmer authored
30 check_path("./asm.py", "example.asm")
5973f27 Anton Barkovsky Add tests that only check if assembly is successful
swarmer authored
31
af04fe7 Anton Barkovsky More tests
swarmer authored
32 def test_hello_asm():
326bd0b Anton Barkovsky Refactor tests
swarmer authored
33 check_path("./asm.py", example("hello"))
af04fe7 Anton Barkovsky More tests
swarmer authored
34
35 def test_hello2_asm():
326bd0b Anton Barkovsky Refactor tests
swarmer authored
36 check_path("./asm.py", example("hello2"))
af04fe7 Anton Barkovsky More tests
swarmer authored
37
38 def test_fibonacci_asm():
326bd0b Anton Barkovsky Refactor tests
swarmer authored
39 check_path("./asm.py", example("ique_fibonacci"))
40
af04fe7 Anton Barkovsky More tests
swarmer authored
41
42 # asm_pyparsing.py
43 def test_example_pyparsing():
326bd0b Anton Barkovsky Refactor tests
swarmer authored
44 check_path("./asm_pyparsing.py", "example.asm")
af04fe7 Anton Barkovsky More tests
swarmer authored
45
46 def test_hello_pyparsing():
326bd0b Anton Barkovsky Refactor tests
swarmer authored
47 check_path("./asm_pyparsing.py", example("hello"))
5973f27 Anton Barkovsky Add tests that only check if assembly is successful
swarmer authored
48
af04fe7 Anton Barkovsky More tests
swarmer authored
49 def test_hello2_pyparsing():
326bd0b Anton Barkovsky Refactor tests
swarmer authored
50 check_path("./asm_pyparsing.py", example("hello2"))
5973f27 Anton Barkovsky Add tests that only check if assembly is successful
swarmer authored
51
af04fe7 Anton Barkovsky More tests
swarmer authored
52 def test_fibonacci_pyparsing():
326bd0b Anton Barkovsky Refactor tests
swarmer authored
53 check_path("./asm_pyparsing.py", example("ique_fibonacci"))
Something went wrong with that request. Please try again.