Testing: extract testcases, edit comparisons, run cppcheck, compare results
This commit is contained in:
parent
6313304f77
commit
c67776c04d
|
@ -148,9 +148,9 @@ static bool isVariableComparison(const Token *tok, const std::string &comp, cons
|
|||
// Invert comparator
|
||||
std::string s = tok->str();
|
||||
if (s[0] == '>')
|
||||
s[1] = '<';
|
||||
s[0] = '<';
|
||||
else if (s[0] == '<')
|
||||
s[1] = '>';
|
||||
s[0] = '>';
|
||||
if (s == comp) {
|
||||
*vartok = tok->astOperand2();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd ~/cppcheck
|
||||
rm -rf test1
|
||||
python tools/extracttests.py --code=test1 test/testleakautovar.cpp
|
||||
cd ~/cppcheck/test1
|
||||
~/cppcheck/tools/run_more_tests.sh
|
||||
|
|
@ -47,6 +47,7 @@ class Extract:
|
|||
|
||||
testclass = None
|
||||
functionName = None
|
||||
code = None
|
||||
|
||||
fin = open(filename, 'r')
|
||||
for line in fin:
|
||||
|
@ -76,19 +77,20 @@ class Extract:
|
|||
code = res.group(1)
|
||||
|
||||
# code..
|
||||
res = re.match('\\s+' + string, line)
|
||||
if res is not None:
|
||||
code = code + res.group(1)
|
||||
if code is not None:
|
||||
res = re.match('\\s+' + string, line)
|
||||
if res is not None:
|
||||
code = code + res.group(1)
|
||||
|
||||
# assert
|
||||
res = re.match('\\s+ASSERT_EQUALS\\(\\"([^"]*)\\",', line)
|
||||
if res is not None and len(code) > 10:
|
||||
if res is not None and code is not None:
|
||||
node = {'testclass': testclass,
|
||||
'functionName': functionName,
|
||||
'code': code,
|
||||
'expected': res.group(1)}
|
||||
self.nodes.append(node)
|
||||
code = ''
|
||||
code = None
|
||||
|
||||
# close test file
|
||||
fin.close()
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
#!/bin/bash
|
||||
|
||||
~/cppcheck/cppcheck -q . 2> 1.txt
|
||||
|
||||
|
||||
# (!x) => (x==0)
|
||||
sed -ri 's/([(&][ ]*)\!([a-z]+)([ ]*[&)])/\1\2==0\3/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (x==0) => (0==x)
|
||||
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*0([ ]*[&)])/\10==\2\3/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (0==x) => (!x)
|
||||
sed -ri 's/([(&][ ]*)0[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1!\2\3/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
|
||||
|
||||
|
||||
# if (x) => (x!=0)
|
||||
sed -ri 's/(if[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# while (x) => (x!=0)
|
||||
sed -ri 's/(while[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (x!=0) => (0!=x)
|
||||
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*!=[ ]*0([ ]*[&)])/\10!=\2\3/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (0!=x) => (x)
|
||||
sed -ri 's/([(&][ ]*)0[ ]*!=[ ]*([a-z]+[ ]*[&)])/\1\2/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
|
||||
# (x < 0) => (0 > x)
|
||||
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (x <= 0) => (0 >= x)
|
||||
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (x > 0) => (0 < x)
|
||||
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (x >= 0) => (0 <= x)
|
||||
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (x == 123) => (123 == x)
|
||||
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3==\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (x != 123) => (123 != x)
|
||||
sed -ri 's/([(&][ ]*)([a-z]+)[ ]*\!=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
|
||||
|
||||
# (0 < x) => (x > 0)
|
||||
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<[ ]*([a-z]+)([ ]*[&)])/\1\3>\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (0 <= x) => (x >= 0)
|
||||
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (0 > x) => (x < 0)
|
||||
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (0 >= x) => (x <= 0)
|
||||
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (123 == x) => (x == 123)
|
||||
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1\3==\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
# (123 != x) => (x <= 123)
|
||||
sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*\!=[ ]*([a-z]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp
|
||||
~/cppcheck/cppcheck -q . 2> 2.txt && diff 1.txt 2.txt
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue