2015-07-22 09:52:24 +02:00
|
|
|
#!/bin/bash
|
2018-02-02 11:27:38 +01:00
|
|
|
# Script Used by generate_and_run_more_tests.sh
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-02 20:54:30 +01:00
|
|
|
# "gsed" is a GNU compatible version of "sed" on MacOS
|
|
|
|
SED_CMD=$(command -v gsed || command -v sed)
|
|
|
|
|
2021-10-30 22:13:58 +02:00
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
2015-07-22 12:31:18 +02:00
|
|
|
set -e
|
|
|
|
|
2021-10-30 22:13:58 +02:00
|
|
|
CPPCHECK=$(pwd)/cppcheck
|
|
|
|
|
|
|
|
if test -f ./bin/cppcheck; then
|
|
|
|
CPPCHECK=$(pwd)/bin/cppcheck
|
|
|
|
fi
|
|
|
|
|
2022-05-22 15:27:32 +02:00
|
|
|
python3 $DIR/extracttests.py --code=$(pwd)/test1 $1
|
2015-07-22 13:44:08 +02:00
|
|
|
|
|
|
|
cd test1
|
|
|
|
|
2023-12-17 15:42:17 +01:00
|
|
|
$CPPCHECK -q --template=cppcheck1 --suppress="*" .
|
|
|
|
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 1.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(!x) => (x==0)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)\!([a-z]+)([ ]*[&)])/\1\2==0\3/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(x==0) => (0==x)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*0([ ]*[&)])/\10==\2\3/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(0==x) => (!x)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)0[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1!\2\3/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "if (x) => (x!=0)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/(if[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "while (x) => (x!=0)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/(while[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(x!=0) => (0!=x)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*!=[ ]*0([ ]*[&)])/\10!=\2\3/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(0!=x) => (x)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)0[ ]*!=[ ]*([a-z]+[ ]*[&)])/\1\2/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(x < 0) => (0 > x)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(x <= 0) => (0 >= x)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(x > 0) => (0 < x)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(x >= 0) => (0 <= x)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(x == 123) => (123 == x)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3==\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(x != 123) => (123 != x)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*\!=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(0 < x) => (x > 0)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<[ ]*([a-z]+)([ ]*[&)])/\1\3>\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(0 <= x) => (x >= 0)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(0 > x) => (x < 0)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(0 >= x) => (x <= 0)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(123 == x) => (x == 123)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1\3==\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2023-03-24 13:31:26 +01:00
|
|
|
echo "(123 != x) => (x <= 123)"
|
2023-03-02 20:54:30 +01:00
|
|
|
$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*\!=[ ]*([a-z]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp
|
2021-10-30 22:13:58 +02:00
|
|
|
$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
|
2015-07-22 09:52:24 +02:00
|
|
|
|
|
|
|
|
2015-07-22 13:44:08 +02:00
|
|
|
cd ..
|
2015-07-22 09:52:24 +02:00
|
|
|
|
2015-07-22 13:44:08 +02:00
|
|
|
rm -rf test1
|