diff options
Diffstat (limited to 'clang/tools/scan-build-py/tests/functional')
5 files changed, 85 insertions, 44 deletions
diff --git a/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py b/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py index 6d449ba39c0..c26fce0bbf8 100644 --- a/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py +++ b/clang/tools/scan-build-py/tests/functional/cases/test_create_cdb.py @@ -4,7 +4,7 @@ # This file is distributed under the University of Illinois Open Source # License. See LICENSE.TXT for details. -from ...unit import fixtures +import libear from . import make_args, silent_check_call, silent_call, create_empty_file import unittest @@ -28,13 +28,13 @@ class CompilationDatabaseTest(unittest.TestCase): return len(content) def test_successful_build(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: result = self.run_intercept(tmpdir, ['build_regular']) self.assertTrue(os.path.isfile(result)) self.assertEqual(5, self.count_entries(result)) def test_successful_build_with_wrapper(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: result = os.path.join(tmpdir, 'cdb.json') make = make_args(tmpdir) + ['build_regular'] silent_check_call(['intercept-build', '--cdb', result, @@ -44,14 +44,14 @@ class CompilationDatabaseTest(unittest.TestCase): @unittest.skipIf(os.getenv('TRAVIS'), 'ubuntu make return -11') def test_successful_build_parallel(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: result = self.run_intercept(tmpdir, ['-j', '4', 'build_regular']) self.assertTrue(os.path.isfile(result)) self.assertEqual(5, self.count_entries(result)) @unittest.skipIf(os.getenv('TRAVIS'), 'ubuntu env remove clang from path') def test_successful_build_on_empty_env(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: result = os.path.join(tmpdir, 'cdb.json') make = make_args(tmpdir) + ['CC=clang', 'build_regular'] silent_check_call(['intercept-build', '--cdb', result, @@ -60,13 +60,13 @@ class CompilationDatabaseTest(unittest.TestCase): self.assertEqual(5, self.count_entries(result)) def test_successful_build_all_in_one(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: result = self.run_intercept(tmpdir, ['build_all_in_one']) self.assertTrue(os.path.isfile(result)) self.assertEqual(5, self.count_entries(result)) def test_not_successful_build(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: result = os.path.join(tmpdir, 'cdb.json') make = make_args(tmpdir) + ['build_broken'] silent_call( @@ -84,12 +84,12 @@ class ExitCodeTest(unittest.TestCase): ['intercept-build', '--cdb', result] + make) def test_successful_build(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: exitcode = self.run_intercept(tmpdir, 'build_clean') self.assertFalse(exitcode) def test_not_successful_build(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: exitcode = self.run_intercept(tmpdir, 'build_broken') self.assertTrue(exitcode) @@ -110,7 +110,7 @@ class ResumeFeatureTest(unittest.TestCase): return len(content) def test_overwrite_existing_cdb(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: result = self.run_intercept(tmpdir, 'build_clean', []) self.assertTrue(os.path.isfile(result)) result = self.run_intercept(tmpdir, 'build_regular', []) @@ -118,7 +118,7 @@ class ResumeFeatureTest(unittest.TestCase): self.assertEqual(2, self.count_entries(result)) def test_append_to_existing_cdb(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: result = self.run_intercept(tmpdir, 'build_clean', []) self.assertTrue(os.path.isfile(result)) result = self.run_intercept(tmpdir, 'build_regular', ['--append']) @@ -138,7 +138,7 @@ class ResultFormatingTest(unittest.TestCase): return content def assert_creates_number_of_entries(self, command, count): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: filename = os.path.join(tmpdir, 'test.c') create_empty_file(filename) command.append(filename) @@ -153,7 +153,7 @@ class ResultFormatingTest(unittest.TestCase): self.assert_creates_number_of_entries(['cc', '-c', '-MM'], 0) def assert_command_creates_entry(self, command, expected): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: filename = os.path.join(tmpdir, command[-1]) create_empty_file(filename) cmd = ['sh', '-c', ' '.join(command)] diff --git a/clang/tools/scan-build-py/tests/functional/cases/test_exec_anatomy.py b/clang/tools/scan-build-py/tests/functional/cases/test_exec_anatomy.py index 329a477e03d..d58a61217b7 100644 --- a/clang/tools/scan-build-py/tests/functional/cases/test_exec_anatomy.py +++ b/clang/tools/scan-build-py/tests/functional/cases/test_exec_anatomy.py @@ -4,7 +4,7 @@ # This file is distributed under the University of Illinois Open Source # License. See LICENSE.TXT for details. -from ...unit import fixtures +import libear import unittest import os.path @@ -45,6 +45,6 @@ class ExecAnatomyTest(unittest.TestCase): def test_all_exec_calls(self): this_dir, _ = os.path.split(__file__) source_dir = os.path.normpath(os.path.join(this_dir, '..', 'exec')) - with fixtures.TempDir() as tmp_dir: + with libear.TemporaryDirectory() as tmp_dir: expected, result = run(source_dir, tmp_dir) self.assertEqualJson(expected, result) diff --git a/clang/tools/scan-build-py/tests/functional/cases/test_from_cdb.py b/clang/tools/scan-build-py/tests/functional/cases/test_from_cdb.py index c579020db22..50264005c81 100644 --- a/clang/tools/scan-build-py/tests/functional/cases/test_from_cdb.py +++ b/clang/tools/scan-build-py/tests/functional/cases/test_from_cdb.py @@ -4,13 +4,12 @@ # This file is distributed under the University of Illinois Open Source # License. See LICENSE.TXT for details. -from ...unit import fixtures +import libear from . import call_and_report import unittest import os.path import string -import subprocess import glob @@ -37,19 +36,19 @@ def run_analyzer(directory, cdb, args): class OutputDirectoryTest(unittest.TestCase): def test_regular_keeps_report_dir(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('regular', tmpdir) exit_code, reportdir = run_analyzer(tmpdir, cdb, []) self.assertTrue(os.path.isdir(reportdir)) def test_clear_deletes_report_dir(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('clean', tmpdir) exit_code, reportdir = run_analyzer(tmpdir, cdb, []) self.assertFalse(os.path.isdir(reportdir)) def test_clear_keeps_report_dir_when_asked(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('clean', tmpdir) exit_code, reportdir = run_analyzer(tmpdir, cdb, ['--keep-empty']) self.assertTrue(os.path.isdir(reportdir)) @@ -57,38 +56,38 @@ class OutputDirectoryTest(unittest.TestCase): class ExitCodeTest(unittest.TestCase): def test_regular_does_not_set_exit_code(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('regular', tmpdir) exit_code, __ = run_analyzer(tmpdir, cdb, []) self.assertFalse(exit_code) def test_clear_does_not_set_exit_code(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('clean', tmpdir) exit_code, __ = run_analyzer(tmpdir, cdb, []) self.assertFalse(exit_code) def test_regular_sets_exit_code_if_asked(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('regular', tmpdir) exit_code, __ = run_analyzer(tmpdir, cdb, ['--status-bugs']) self.assertTrue(exit_code) def test_clear_does_not_set_exit_code_if_asked(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('clean', tmpdir) exit_code, __ = run_analyzer(tmpdir, cdb, ['--status-bugs']) self.assertFalse(exit_code) def test_regular_sets_exit_code_if_asked_from_plist(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('regular', tmpdir) exit_code, __ = run_analyzer( tmpdir, cdb, ['--status-bugs', '--plist']) self.assertTrue(exit_code) def test_clear_does_not_set_exit_code_if_asked_from_plist(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('clean', tmpdir) exit_code, __ = run_analyzer( tmpdir, cdb, ['--status-bugs', '--plist']) @@ -105,7 +104,7 @@ class OutputFormatTest(unittest.TestCase): return len(glob.glob(os.path.join(directory, 'report-*.plist'))) def test_default_creates_html_report(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('regular', tmpdir) exit_code, reportdir = run_analyzer(tmpdir, cdb, []) self.assertTrue( @@ -114,7 +113,7 @@ class OutputFormatTest(unittest.TestCase): self.assertEqual(self.get_plist_count(reportdir), 0) def test_plist_and_html_creates_html_report(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('regular', tmpdir) exit_code, reportdir = run_analyzer(tmpdir, cdb, ['--plist-html']) self.assertTrue( @@ -123,7 +122,7 @@ class OutputFormatTest(unittest.TestCase): self.assertEqual(self.get_plist_count(reportdir), 5) def test_plist_does_not_creates_html_report(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('regular', tmpdir) exit_code, reportdir = run_analyzer(tmpdir, cdb, ['--plist']) self.assertFalse( @@ -134,14 +133,14 @@ class OutputFormatTest(unittest.TestCase): class FailureReportTest(unittest.TestCase): def test_broken_creates_failure_reports(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('broken', tmpdir) exit_code, reportdir = run_analyzer(tmpdir, cdb, []) self.assertTrue( os.path.isdir(os.path.join(reportdir, 'failures'))) def test_broken_does_not_creates_failure_reports(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('broken', tmpdir) exit_code, reportdir = run_analyzer( tmpdir, cdb, ['--no-failure-reports']) @@ -170,13 +169,13 @@ class TitleTest(unittest.TestCase): self.assertEqual(result['page'], expected) def test_default_title_in_report(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('broken', tmpdir) exit_code, reportdir = run_analyzer(tmpdir, cdb, []) self.assertTitleEqual(reportdir, 'src - analyzer results') def test_given_title_in_report(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: cdb = prepare_cdb('broken', tmpdir) exit_code, reportdir = run_analyzer( tmpdir, cdb, ['--html-title', 'this is the title']) diff --git a/clang/tools/scan-build-py/tests/functional/cases/test_from_cmd.py b/clang/tools/scan-build-py/tests/functional/cases/test_from_cmd.py index fe7ecf69915..0eee4bb928f 100644 --- a/clang/tools/scan-build-py/tests/functional/cases/test_from_cmd.py +++ b/clang/tools/scan-build-py/tests/functional/cases/test_from_cmd.py @@ -4,7 +4,7 @@ # This file is distributed under the University of Illinois Open Source # License. See LICENSE.TXT for details. -from ...unit import fixtures +import libear from . import make_args, check_call_and_report, create_empty_file import unittest @@ -22,19 +22,19 @@ class OutputDirectoryTest(unittest.TestCase): cmd) def test_regular_keeps_report_dir(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: make = make_args(tmpdir) + ['build_regular'] outdir = self.run_analyzer(tmpdir, [], make) self.assertTrue(os.path.isdir(outdir)) def test_clear_deletes_report_dir(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: make = make_args(tmpdir) + ['build_clean'] outdir = self.run_analyzer(tmpdir, [], make) self.assertFalse(os.path.isdir(outdir)) def test_clear_keeps_report_dir_when_asked(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: make = make_args(tmpdir) + ['build_clean'] outdir = self.run_analyzer(tmpdir, ['--keep-empty'], make) self.assertTrue(os.path.isdir(outdir)) @@ -47,7 +47,7 @@ class RunAnalyzerTest(unittest.TestCase): return len(glob.glob(os.path.join(directory, 'report-*.plist'))) def test_interposition_works(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: make = make_args(tmpdir) + ['build_regular'] outdir = check_call_and_report( ['scan-build', '--plist', '-o', tmpdir, '--override-compiler'], @@ -57,7 +57,7 @@ class RunAnalyzerTest(unittest.TestCase): self.assertEqual(self.get_plist_count(outdir), 5) def test_intercept_wrapper_works(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: make = make_args(tmpdir) + ['build_regular'] outdir = check_call_and_report( ['scan-build', '--plist', '-o', tmpdir, '--intercept-first', @@ -68,7 +68,7 @@ class RunAnalyzerTest(unittest.TestCase): self.assertEqual(self.get_plist_count(outdir), 5) def test_intercept_library_works(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: make = make_args(tmpdir) + ['build_regular'] outdir = check_call_and_report( ['scan-build', '--plist', '-o', tmpdir, '--intercept-first'], @@ -88,21 +88,21 @@ class RunAnalyzerTest(unittest.TestCase): return ['sh', '-c', command] def test_interposition_cc_works(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: outdir = check_call_and_report( ['scan-build', '--plist', '-o', tmpdir, '--override-compiler'], self.compile_empty_source_file(tmpdir, False)) self.assertEqual(self.get_plist_count(outdir), 1) def test_interposition_cxx_works(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: outdir = check_call_and_report( ['scan-build', '--plist', '-o', tmpdir, '--override-compiler'], self.compile_empty_source_file(tmpdir, True)) self.assertEqual(self.get_plist_count(outdir), 1) def test_intercept_cc_works(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: outdir = check_call_and_report( ['scan-build', '--plist', '-o', tmpdir, '--override-compiler', '--intercept-first'], @@ -110,7 +110,7 @@ class RunAnalyzerTest(unittest.TestCase): self.assertEqual(self.get_plist_count(outdir), 1) def test_intercept_cxx_works(self): - with fixtures.TempDir() as tmpdir: + with libear.TemporaryDirectory() as tmpdir: outdir = check_call_and_report( ['scan-build', '--plist', '-o', tmpdir, '--override-compiler', '--intercept-first'], diff --git a/clang/tools/scan-build-py/tests/functional/src/build/Makefile b/clang/tools/scan-build-py/tests/functional/src/build/Makefile new file mode 100644 index 00000000000..a8c0aafd0e5 --- /dev/null +++ b/clang/tools/scan-build-py/tests/functional/src/build/Makefile @@ -0,0 +1,42 @@ +SRCDIR := .. +OBJDIR := . + +CFLAGS = -Wall -DDEBUG -Dvariable="value with space" -I $(SRCDIR)/include +LDFLAGS = +PROGRAM = $(OBJDIR)/prg + +$(OBJDIR)/main.o: $(SRCDIR)/main.c + $(CC) $(CFLAGS) -c -o $@ $(SRCDIR)/main.c + +$(OBJDIR)/clean-one.o: $(SRCDIR)/clean-one.c + $(CC) $(CFLAGS) -c -o $@ $(SRCDIR)/clean-one.c + +$(OBJDIR)/clean-two.o: $(SRCDIR)/clean-two.c + $(CC) $(CFLAGS) -c -o $@ $(SRCDIR)/clean-two.c + +$(OBJDIR)/emit-one.o: $(SRCDIR)/emit-one.c + $(CC) $(CFLAGS) -c -o $@ $(SRCDIR)/emit-one.c + +$(OBJDIR)/emit-two.o: $(SRCDIR)/emit-two.c + $(CC) $(CFLAGS) -c -o $@ $(SRCDIR)/emit-two.c + +$(OBJDIR)/broken-one.o: $(SRCDIR)/broken-one.c + $(CC) $(CFLAGS) -c -o $@ $(SRCDIR)/broken-one.c + +$(OBJDIR)/broken-two.o: $(SRCDIR)/broken-two.c + $(CC) $(CFLAGS) -c -o $@ $(SRCDIR)/broken-two.c + +$(PROGRAM): $(OBJDIR)/main.o $(OBJDIR)/clean-one.o $(OBJDIR)/clean-two.o $(OBJDIR)/emit-one.o $(OBJDIR)/emit-two.o + $(CC) $(LDFLAGS) -o $@ $(OBJDIR)/main.o $(OBJDIR)/clean-one.o $(OBJDIR)/clean-two.o $(OBJDIR)/emit-one.o $(OBJDIR)/emit-two.o + +build_regular: $(PROGRAM) + +build_clean: $(OBJDIR)/main.o $(OBJDIR)/clean-one.o $(OBJDIR)/clean-two.o + +build_broken: $(OBJDIR)/main.o $(OBJDIR)/broken-one.o $(OBJDIR)/broken-two.o + +build_all_in_one: $(SRCDIR)/main.c $(SRCDIR)/clean-one.c $(SRCDIR)/clean-two.c $(SRCDIR)/emit-one.c $(SRCDIR)/emit-two.c + $(CC) $(CFLAGS) $(LDFLAGS) -o $(PROGRAM) $(SRCDIR)/main.c $(SRCDIR)/clean-one.c $(SRCDIR)/clean-two.c $(SRCDIR)/emit-one.c $(SRCDIR)/emit-two.c + +clean: + rm -f $(PROGRAM) $(OBJDIR)/*.o |