diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CompilationDatabase/basic.py | 27 | ||||
-rw-r--r-- | test/CompilationDatabase/fixture/SConstruct | 1 | ||||
-rw-r--r-- | test/fixture/mylink.py | 52 |
3 files changed, 57 insertions, 23 deletions
diff --git a/test/CompilationDatabase/basic.py b/test/CompilationDatabase/basic.py index b06098b..2f76752 100644 --- a/test/CompilationDatabase/basic.py +++ b/test/CompilationDatabase/basic.py @@ -27,15 +27,13 @@ and values of COMPILATIONDB_USE_ABSPATH """ import sys +import os +import os.path import TestSCons test = TestSCons.TestSCons() -if sys.platform == 'win32': - test.file_fixture('mylink_win32.py', 'mylink.py') -else: - test.file_fixture('mylink.py') - +test.file_fixture('mylink.py') test.file_fixture('mygcc.py') test.verbose_set(1) @@ -63,27 +61,34 @@ example_rel_file = """[ "command": "%s mygcc.py cc -o test_main.o -c test_main.c", "directory": "%s", "file": "test_main.c", - "target": "test_main.o" + "output": "test_main.o" } ]""" % (sys.executable, test.workdir) +if sys.platform == 'win32': + example_rel_file = example_rel_file.replace('\\', '\\\\') + for f in rel_files: # print("Checking:%s" % f) test.must_exist(f) - test.must_match(f, example_rel_file) + test.must_match(f, example_rel_file, mode='r') example_abs_file = """[ { "command": "%s mygcc.py cc -o test_main.o -c test_main.c", "directory": "%s", - "file": "%s/test_main.c", - "target": "%s/test_main.o" + "file": "%s", + "output": "%s" } -]""" % (sys.executable, test.workdir, test.workdir, test.workdir) +]""" % (sys.executable, test.workdir, os.path.join(test.workdir, 'test_main.c'), os.path.join(test.workdir, 'test_main.o')) + +if sys.platform == 'win32': + example_abs_file = example_abs_file.replace('\\', '\\\\') + for f in abs_files: test.must_exist(f) - test.must_match(f, example_abs_file) + test.must_match(f, example_abs_file, mode='r') test.pass_test() diff --git a/test/CompilationDatabase/fixture/SConstruct b/test/CompilationDatabase/fixture/SConstruct index 4043b5a..ea23bc3 100644 --- a/test/CompilationDatabase/fixture/SConstruct +++ b/test/CompilationDatabase/fixture/SConstruct @@ -7,6 +7,7 @@ env = Environment( LINKFLAGS=[], CC='$PYTHON mygcc.py cc', CXX='$PYTHON mygcc.py c++', + tools=['gcc','g++','gnulink'], ) env.Tool('compilation_db') diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py index fe4af58..19969f0 100644 --- a/test/fixture/mylink.py +++ b/test/fixture/mylink.py @@ -1,15 +1,43 @@ +""" +Dummy linker for use by tests" +""" import getopt import sys -opts, args = getopt.getopt(sys.argv[1:], 'o:s:') -for opt, arg in opts: - if opt == '-o': - out = arg - -with open(out, 'w') as ofp: - for f in args: - with open(f, 'r') as ifp: - for line in ifp.readlines(): - if line[:5] != '#link': - ofp.write(line) -sys.exit(0) +def fake_link(): + opts, args = getopt.getopt(sys.argv[1:], 'o:s:') + for opt, arg in opts: + if opt == '-o': + out = arg + + with open(out, 'w') as ofp: + for f in args: + with open(f, 'r') as ifp: + for line in ifp.readlines(): + if line[:5] != '#link': + ofp.write(line) + sys.exit(0) + +def fake_win32_link(): + args = sys.argv[1:] + while args: + a = args[0] + if a == '-o': + out = args[1] + args = args[2:] + continue + if not a[0] in '/-': + break + args = args[1:] + if a[:5].lower() == '/out:': out = a[5:] + with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp: + for line in ifp.readlines(): + if not line.startswith(b'#link'): + ofp.write(line) + sys.exit(0) + +if __name__ == '__main__': + if sys.platform == 'win32': + fake_win32_link() + else: + fake_link() |