-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test to make sure
samples
produce the expected output / adjus…
…ted `samples` output
- Loading branch information
Showing
5 changed files
with
58 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
samples\arrayIndexOutOfBounds_2\bad.c:6:10: error: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds] | ||
a[i] = 0; | ||
^ | ||
samples\arrayIndexOutOfBounds_2\bad.c:5:19: note: Assuming that condition 'i<3' is not redundant | ||
for (i = 0; i < 3; i++) | ||
^ | ||
samples\arrayIndexOutOfBounds_2\bad.c:6:10: note: Array index out of bounds | ||
a[i] = 0; | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
samples/memleak/bad.c:8:5: error: Memory leak: a [memleak] | ||
samples\memleak\bad.c:8:5: error: Memory leak: a [memleak] | ||
return result; | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 not 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, stdout, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', good_src], cwd=__root_dir) | ||
if not ret == 0: | ||
failures[good_src] = stderr | ||
|
||
# check that the bad inout produces a warning | ||
ret, stdout, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', bad_src], cwd=__root_dir) | ||
if not 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 == {} |