| 3430 | assert stderr.splitlines() == [] # no error since the unused templates are not being checked |
| 3431 | |
| 3432 | def __test_clang_tidy(tmpdir, use_compdb): |
| 3433 | test_file = os.path.join(tmpdir, 'test.cpp') |
| 3434 | with open(test_file, 'wt') as f: |
| 3435 | f.write( |
| 3436 | """static void foo() // NOLINT(misc-use-anonymous-namespace) |
| 3437 | { |
| 3438 | (void)(*((int*)nullptr)); |
| 3439 | }""") |
| 3440 | |
| 3441 | project_file = __write_compdb(tmpdir, test_file) if use_compdb else None |
| 3442 | |
| 3443 | args = [ |
| 3444 | '-q', |
| 3445 | '--template=simple', |
| 3446 | '--clang-tidy' |
| 3447 | ] |
| 3448 | if project_file: |
| 3449 | args += ['--project={}'.format(project_file)] |
| 3450 | else: |
| 3451 | args += [str(test_file)] |
| 3452 | exitcode, stdout, stderr = cppcheck(args) |
| 3453 | assert exitcode == 0, stdout |
| 3454 | assert stdout.splitlines() == [ |
| 3455 | ] |
| 3456 | assert stderr.splitlines() == [ |
| 3457 | '{}:3:14: error: Null pointer dereference: (int*)nullptr [nullPointer]'.format(test_file), |
| 3458 | '{}:3:14: style: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [clang-tidy-google-readability-casting]'.format(test_file) |
| 3459 | ] |
| 3460 | |
| 3461 | |
| 3462 | @pytest.mark.skipif(not __has_clang_tidy, reason='clang-tidy is not available') |