improve test to not use hardcoded test directory
This commit is contained in:
parent
77d199e60d
commit
5df7c4d159
1 changed files with 14 additions and 5 deletions
|
|
@ -4,8 +4,10 @@ LLVM tests
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import math
|
import math
|
||||||
|
import shutil
|
||||||
import unittest
|
import unittest
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
is_py3k = bool(sys.version_info[0] == 3)
|
is_py3k = bool(sys.version_info[0] == 3)
|
||||||
|
|
||||||
|
|
@ -28,6 +30,12 @@ tests = []
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
class TestAsm(unittest.TestCase):
|
class TestAsm(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.tmpdir = tempfile.mkdtemp()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
shutil.rmtree(self.tmpdir)
|
||||||
|
|
||||||
def test_asm(self):
|
def test_asm(self):
|
||||||
# create a module
|
# create a module
|
||||||
m = Module.new('module1')
|
m = Module.new('module1')
|
||||||
|
|
@ -36,18 +44,18 @@ class TestAsm(unittest.TestCase):
|
||||||
# write it's assembly representation to a file
|
# write it's assembly representation to a file
|
||||||
asm = str(m)
|
asm = str(m)
|
||||||
|
|
||||||
with open("/tmp/testasm.ll", "w") as fout:
|
testasm_ll = os.path.join(self.tmpdir, 'testasm.ll')
|
||||||
|
with open(testasm_ll, "w") as fout:
|
||||||
fout.write(asm)
|
fout.write(asm)
|
||||||
|
|
||||||
# read it back into a module
|
# read it back into a module
|
||||||
with open("/tmp/testasm.ll") as fin:
|
with open(testasm_ll) as fin:
|
||||||
m2 = Module.from_assembly(fin)
|
m2 = Module.from_assembly(fin)
|
||||||
# The default `m.id` is '<string>'.
|
# The default `m.id` is '<string>'.
|
||||||
m2.id = m.id # Copy the name from `m`
|
m2.id = m.id # Copy the name from `m`
|
||||||
|
|
||||||
self.assertEqual(str(m2).strip(), asm.strip())
|
self.assertEqual(str(m2).strip(), asm.strip())
|
||||||
|
|
||||||
|
|
||||||
def test_bitcode(self):
|
def test_bitcode(self):
|
||||||
# create a module
|
# create a module
|
||||||
m = Module.new('module1')
|
m = Module.new('module1')
|
||||||
|
|
@ -56,11 +64,12 @@ class TestAsm(unittest.TestCase):
|
||||||
# write it's assembly representation to a file
|
# write it's assembly representation to a file
|
||||||
asm = str(m)
|
asm = str(m)
|
||||||
|
|
||||||
with open("/tmp/testasm.bc", "wb") as fout:
|
testasm_bc = os.path.join(self.tmpdir, 'testasm.bc')
|
||||||
|
with open(testasm_bc, "wb") as fout:
|
||||||
m.to_bitcode(fout)
|
m.to_bitcode(fout)
|
||||||
|
|
||||||
# read it back into a module
|
# read it back into a module
|
||||||
with open("/tmp/testasm.bc", "rb") as fin:
|
with open(testasm_bc, "rb") as fin:
|
||||||
m2 = Module.from_bitcode(fin)
|
m2 = Module.from_bitcode(fin)
|
||||||
# The default `m.id` is '<string>'.
|
# The default `m.id` is '<string>'.
|
||||||
m2.id = m.id # Copy the name from `m`
|
m2.id = m.id # Copy the name from `m`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue