File: samples_test.py

package info (click to toggle)
cppcheck 2.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,132 kB
  • sloc: cpp: 268,935; python: 20,890; ansic: 8,090; sh: 1,045; makefile: 1,008; xml: 1,005; cs: 291
file content (45 lines) | stat: -rw-r--r-- 1,724 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import sys

from testutils import cppcheck

__script_dir = os.path.dirname(os.path.abspath(__file__))
__root_dir = os.path.abspath(os.path.join(__script_dir, '..', '..'))


def test_samples():
    failures = {}

    samples_dir = os.path.join(__root_dir, 'samples')
    for entry in os.listdir(samples_dir):
        sample_dir = os.path.join(samples_dir, entry)
        if not os.path.isdir(sample_dir):
            continue

        with open(os.path.join(sample_dir, 'out.txt')) as out_in:
            out_txt = out_in.read()
        if sys.platform != 'win32':
            out_txt = out_txt.replace('\\', '/')

        if not os.path.exists(os.path.join(sample_dir, 'good.c')):
            good_src = os.path.join('samples', entry, 'good.cpp')
            bad_src = os.path.join('samples', entry, 'bad.cpp')
        else:
            good_src = os.path.join('samples', entry, 'good.c')
            bad_src = os.path.join('samples', entry, 'bad.c')

        # check that good input does not produce any warnings
        ret, _, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', good_src], cwd=__root_dir)
        if ret != 0:
            failures[good_src] = stderr

        # check that the bad inout produces a warning
        ret, _, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', bad_src], cwd=__root_dir)
        if ret != 1:
            failures[bad_src] = stderr

        # check that the bad input procudes the expected output
        if not stderr == out_txt:
            failures[bad_src] = stderr

    assert failures == {}