| 8 | |
| 9 | |
| 10 | def test_samples(): |
| 11 | failures = {} |
| 12 | |
| 13 | samples_dir = os.path.join(__root_dir, 'samples') |
| 14 | for entry in os.listdir(samples_dir): |
| 15 | sample_dir = os.path.join(samples_dir, entry) |
| 16 | if not os.path.isdir(sample_dir): |
| 17 | continue |
| 18 | |
| 19 | with open(os.path.join(sample_dir, 'out.txt')) as out_in: |
| 20 | out_txt = out_in.read() |
| 21 | if sys.platform != 'win32': |
| 22 | out_txt = out_txt.replace('\\', '/') |
| 23 | |
| 24 | if not os.path.exists(os.path.join(sample_dir, 'good.c')): |
| 25 | good_src = os.path.join('samples', entry, 'good.cpp') |
| 26 | bad_src = os.path.join('samples', entry, 'bad.cpp') |
| 27 | else: |
| 28 | good_src = os.path.join('samples', entry, 'good.c') |
| 29 | bad_src = os.path.join('samples', entry, 'bad.c') |
| 30 | |
| 31 | # check that good input does not produce any warnings |
| 32 | ret, _, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', good_src], cwd=__root_dir) |
| 33 | if ret != 0: |
| 34 | failures[good_src] = stderr |
| 35 | |
| 36 | # check that the bad inout produces a warning |
| 37 | ret, _, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', bad_src], cwd=__root_dir) |
| 38 | if ret != 1: |
| 39 | failures[bad_src] = stderr |
| 40 | |
| 41 | # check that the bad input procudes the expected output |
| 42 | if not stderr == out_txt: |
| 43 | failures[bad_src] = stderr |
| 44 | |
| 45 | assert failures == {} |