diff --git a/test/CompilationDatabase/basic.py b/test/CompilationDatabase/basic.py index 2f7675276f..d86300a5c2 100644 --- a/test/CompilationDatabase/basic.py +++ b/test/CompilationDatabase/basic.py @@ -31,6 +31,27 @@ import os.path import TestSCons +def get_db(workdir, use_abspath, ccflags): + if use_abspath: + prefix = workdir + else: + prefix = '' + content = """[ + { + "command": "%s mygcc.py cc -o test_main.o %s test_main.c", + "directory": "%s", + "file": "%s", + "output": "%s" + } +]""" % (sys.executable, + ' '.join(['-c'] + ccflags), + workdir, + os.path.join(prefix, 'test_main.c'), + os.path.join(prefix, 'test_main.o')) + if sys.platform == 'win32': + content = content.replace('\\', '\\\\') + return content + test = TestSCons.TestSCons() test.file_fixture('mylink.py') @@ -56,35 +77,32 @@ 'compile_commands_over_abs_1.json', ] -example_rel_file = """[ - { - "command": "%s mygcc.py cc -o test_main.o -c test_main.c", - "directory": "%s", - "file": "test_main.c", - "output": "test_main.o" - } -]""" % (sys.executable, test.workdir) -if sys.platform == 'win32': - example_rel_file = example_rel_file.replace('\\', '\\\\') +example_rel_file = get_db(test.workdir, False, []) for f in rel_files: # print("Checking:%s" % f) test.must_exist(f) 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", - "output": "%s" - } -]""" % (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('\\', '\\\\') +example_abs_file = get_db(test.workdir, True, []) + +for f in abs_files: + test.must_exist(f) + test.must_match(f, example_abs_file, mode='r') + + +test.run(arguments='CCFLAGS=-g') + +example_rel_file = get_db(test.workdir, False, ['-g']) + +for f in rel_files: + test.must_exist(f) + test.must_match(f, example_rel_file, mode='r') + +example_abs_file = get_db(test.workdir, True, ['-g']) for f in abs_files: test.must_exist(f) diff --git a/test/CompilationDatabase/fixture/SConstruct b/test/CompilationDatabase/fixture/SConstruct index ea23bc3053..971e82156f 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++', + CCFLAGS=ARGUMENTS.get('CCFLAGS', ''), tools=['gcc','g++','gnulink'], ) env.Tool('compilation_db') diff --git a/test/fixture/mygcc.py b/test/fixture/mygcc.py index ceb10e5661..32a9fca32a 100644 --- a/test/fixture/mygcc.py +++ b/test/fixture/mygcc.py @@ -3,7 +3,7 @@ compiler = sys.argv[1] clen = len(compiler) + 1 -opts, args = getopt.getopt(sys.argv[2:], 'co:xf:K:') +opts, args = getopt.getopt(sys.argv[2:], 'co:xf:gK:') for opt, arg in opts: if opt == '-o': out = arg