mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 04:13:28 +01:00
Practracker: add an integration test.
This test runs practracker with a set of 0 thresholds, to make sure that it enumerates all its values right. It tries running with an empty exceptions file, and with an exceptions file that covers _some_ of the data, and it makes sure that the outputs are as expected.
This commit is contained in:
parent
a79e2c2975
commit
8d3f3e5d30
50
scripts/maint/practracker/test_practracker.sh
Executable file
50
scripts/maint/practracker/test_practracker.sh
Executable file
@ -0,0 +1,50 @@
|
||||
#!/bin/sh
|
||||
|
||||
umask 077
|
||||
|
||||
TMPDIR=""
|
||||
clean () {
|
||||
if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
|
||||
rm -rf "$TMPDIR"
|
||||
fi
|
||||
}
|
||||
trap clean EXIT HUP INT TERM
|
||||
|
||||
if test "${PRACTRACKER_DIR}" = "" ||
|
||||
test ! -e "${PRACTRACKER_DIR}/practracker.py" ; then
|
||||
PRACTRACKER_DIR=$(dirname "$0")
|
||||
fi
|
||||
|
||||
TMPDIR="$(mktemp -d -t pracktracker.test.XXXXXX)"
|
||||
if test -z "${TMPDIR}" || test ! -d "${TMPDIR}" ; then
|
||||
echo >&2 "mktemp failed."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
DATA="${PRACTRACKER_DIR}/testdata"
|
||||
|
||||
run_practracker() {
|
||||
"${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker.py" \
|
||||
--max-include-count=0 --max-file-size=0 --max-function-size=0 --terse \
|
||||
"${DATA}/" "$@";
|
||||
}
|
||||
|
||||
echo "ex0:"
|
||||
|
||||
run_practracker --exceptions "${DATA}/ex0.txt" > "${TMPDIR}/ex0-received.txt"
|
||||
|
||||
if cmp "${TMPDIR}/ex0-received.txt" "${DATA}/ex0-expected.txt" ; then
|
||||
echo " OK"
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "ex1:"
|
||||
|
||||
run_practracker --exceptions "${DATA}/ex1.txt" > "${TMPDIR}/ex1-received.txt"
|
||||
|
||||
if cmp "${TMPDIR}/ex1-received.txt" "${DATA}/ex1-expected.txt" ;then
|
||||
echo " OK"
|
||||
else
|
||||
exit 1
|
||||
fi
|
38
scripts/maint/practracker/testdata/a.c
vendored
Normal file
38
scripts/maint/practracker/testdata/a.c
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
#include "one.h"
|
||||
#include "two.h"
|
||||
#incldue "three.h"
|
||||
|
||||
# include "four.h"
|
||||
|
||||
int
|
||||
i_am_a_function(void)
|
||||
{
|
||||
call();
|
||||
call();
|
||||
/* comment
|
||||
|
||||
another */
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
# include "five.h"
|
||||
|
||||
long
|
||||
another_function(long x,
|
||||
long y)
|
||||
{
|
||||
int abcd;
|
||||
|
||||
abcd = x+y;
|
||||
abcd *= abcd;
|
||||
|
||||
/* comment here */
|
||||
|
||||
return abcd +
|
||||
abcd +
|
||||
abcd;
|
||||
}
|
||||
|
||||
/* And a comment to grow! */
|
15
scripts/maint/practracker/testdata/b.c
vendored
Normal file
15
scripts/maint/practracker/testdata/b.c
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
MOCK_IMPL(int,
|
||||
foo,(void))
|
||||
{
|
||||
// blah1
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOCK_IMPL(int,
|
||||
bar,( long z))
|
||||
{
|
||||
// blah2
|
||||
|
||||
return (int)(z+2);
|
||||
}
|
0
scripts/maint/practracker/testdata/ex.txt
vendored
Normal file
0
scripts/maint/practracker/testdata/ex.txt
vendored
Normal file
7
scripts/maint/practracker/testdata/ex0-expected.txt
vendored
Normal file
7
scripts/maint/practracker/testdata/ex0-expected.txt
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
problem file-size a.c 38
|
||||
problem include-count a.c 4
|
||||
problem function-size a.c:i_am_a_function() 9
|
||||
problem function-size a.c:another_function() 12
|
||||
problem file-size b.c 15
|
||||
problem function-size b.c:foo() 4
|
||||
problem function-size b.c:bar() 5
|
0
scripts/maint/practracker/testdata/ex0.txt
vendored
Normal file
0
scripts/maint/practracker/testdata/ex0.txt
vendored
Normal file
3
scripts/maint/practracker/testdata/ex1-expected.txt
vendored
Normal file
3
scripts/maint/practracker/testdata/ex1-expected.txt
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
problem function-size a.c:i_am_a_function() 9
|
||||
(warning) problem function-size a.c:another_function() 12
|
||||
problem function-size b.c:foo() 4
|
11
scripts/maint/practracker/testdata/ex1.txt
vendored
Normal file
11
scripts/maint/practracker/testdata/ex1.txt
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
problem file-size a.c 38
|
||||
problem include-count a.c 4
|
||||
# this problem will produce an error
|
||||
problem function-size a.c:i_am_a_function() 8
|
||||
# this problem will produce a warning
|
||||
problem function-size a.c:another_function() 11
|
||||
problem file-size b.c 15
|
||||
# This is removed, and so will produce an error.
|
||||
# problem function-size b.c:foo() 4
|
||||
problem function-size b.c:bar() 5
|
2
scripts/maint/practracker/testdata/not_c_file
vendored
Normal file
2
scripts/maint/practracker/testdata/not_c_file
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
This isn't a C file, so practracker shouldn't care about it.
|
Loading…
Reference in New Issue
Block a user