From 394528241947800a0ac881b8890e5af387e0e9d7 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 1 Aug 2019 13:45:45 -0400 Subject: make dist: only include files from practracker dir intentionally. Previously, we included temporary files and whatnot, which is not good. Fixes bug 31311; bugfix on 0.4.1.1-alpha. --- Makefile.am | 9 ++++++--- changes/ticket31311 | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 changes/ticket31311 diff --git a/Makefile.am b/Makefile.am index 3f3de34ceb..10bd4b45c2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -165,9 +165,12 @@ EXTRA_DIST+= \ README \ ReleaseNotes \ scripts/maint/checkIncludes.py \ - scripts/maint/checkSpace.pl \ - scripts/maint/practracker - + scripts/maint/checkSpace.pl \ + scripts/maint/practracker/exceptions.txt \ + scripts/maint/practracker/metrics.py \ + scripts/maint/practracker/practracker.py \ + scripts/maint/practracker/problem.py \ + scripts/maint/practracker/util.py ## This tells etags how to find mockable function definitions. AM_ETAGSFLAGS=--regex='{c}/MOCK_IMPL([^,]+,\W*\([a-zA-Z0-9_]+\)\W*,/\1/s' diff --git a/changes/ticket31311 b/changes/ticket31311 new file mode 100644 index 0000000000..88dfb85736 --- /dev/null +++ b/changes/ticket31311 @@ -0,0 +1,3 @@ + o Minor bugfixes (distribution): + - Do not ship any temporary files found in the scripts/maint/practracker + directory. Fixes bug 31311; bugfix on 0.4.1.1-alpha. -- cgit v1.2.3-54-g00ecf From 30da1b61c66794fa3b321573ef7b871081cf8eff Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 1 Aug 2019 13:59:26 -0400 Subject: Distribute practracker unit and integration tests. --- Makefile.am | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Makefile.am b/Makefile.am index 9d3fd97f60..4199ae83cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -171,7 +171,17 @@ EXTRA_DIST+= \ scripts/maint/practracker/exceptions.txt \ scripts/maint/practracker/metrics.py \ scripts/maint/practracker/practracker.py \ + scripts/maint/practracker/practracker_tests.py \ scripts/maint/practracker/problem.py \ + scripts/maint/practracker/testdata/a.c \ + scripts/maint/practracker/testdata/b.c \ + scripts/maint/practracker/testdata/ex0-expected.txt \ + scripts/maint/practracker/testdata/ex0.txt \ + scripts/maint/practracker/testdata/ex1-expected.txt \ + scripts/maint/practracker/testdata/ex1.txt \ + scripts/maint/practracker/testdata/ex.txt \ + scripts/maint/practracker/testdata/not_c_file \ + scripts/maint/practracker/test_practracker.sh \ scripts/maint/practracker/util.py ## This tells etags how to find mockable function definitions. -- cgit v1.2.3-54-g00ecf From 5d98b54725efb15e904ea7abacdfe85da2a82bc5 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 1 Aug 2019 14:00:48 -0400 Subject: Port practracker unit tests to python 3 --- scripts/maint/practracker/practracker_tests.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/maint/practracker/practracker_tests.py b/scripts/maint/practracker/practracker_tests.py index 865f68d186..45719d6cb7 100755 --- a/scripts/maint/practracker/practracker_tests.py +++ b/scripts/maint/practracker/practracker_tests.py @@ -4,7 +4,12 @@ import unittest -import StringIO +try: + # python 2 names the module this way... + from StringIO import StringIO +except ImportError: + # python 3 names the module this way. + from io import StringIO import metrics @@ -38,7 +43,7 @@ fun,( class TestFunctionLength(unittest.TestCase): def test_function_length(self): - funcs = StringIO.StringIO(function_file) + funcs = StringIO(function_file) # All functions should have length 2 for name, lines in metrics.get_function_lines(funcs): self.assertEqual(name, "fun") @@ -50,7 +55,7 @@ class TestFunctionLength(unittest.TestCase): class TestIncludeCount(unittest.TestCase): def test_include_count(self): - f = StringIO.StringIO(""" + f = StringIO(""" # include # include "def.h" #include "ghi.h" -- cgit v1.2.3-54-g00ecf From fa60fee8d56af01f6fefca17f945bdd00d195571 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 1 Aug 2019 14:01:43 -0400 Subject: practracker: Add unit tests to test script, and test script to makefile This makes all of the practracker tests get run by make check, and hence by our CI. Closes ticket 31304. --- changes/ticket31304 | 3 +++ scripts/maint/practracker/test_practracker.sh | 4 ++++ src/test/include.am | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changes/ticket31304 diff --git a/changes/ticket31304 b/changes/ticket31304 new file mode 100644 index 0000000000..ca60148b0c --- /dev/null +++ b/changes/ticket31304 @@ -0,0 +1,3 @@ + o Minor features (tests): + - The practracker tests are now run as part of the Tor test suite. + Closes ticket 31304. diff --git a/scripts/maint/practracker/test_practracker.sh b/scripts/maint/practracker/test_practracker.sh index 590525660b..c7be227702 100755 --- a/scripts/maint/practracker/test_practracker.sh +++ b/scripts/maint/practracker/test_practracker.sh @@ -29,6 +29,10 @@ run_practracker() { "${DATA}/" "$@"; } +echo "unit tests:" + +"${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker_tests.py" || exit 1 + echo "ex0:" run_practracker --exceptions "${DATA}/ex0.txt" > "${TMPDIR}/ex0-received.txt" diff --git a/src/test/include.am b/src/test/include.am index 0ec4d96ad4..7cd1ecae36 100644 --- a/src/test/include.am +++ b/src/test/include.am @@ -31,7 +31,11 @@ TESTSCRIPTS += \ endif if USEPYTHON -TESTSCRIPTS += src/test/test_ntor.sh src/test/test_hs_ntor.sh src/test/test_bt.sh +TESTSCRIPTS += \ + src/test/test_ntor.sh \ + src/test/test_hs_ntor.sh \ + src/test/test_bt.sh \ + scripts/maint/practracker/test_practracker.sh if COVERAGE_ENABLED # ... -- cgit v1.2.3-54-g00ecf From 1440c2cb340f904cafb402474b538725abdeb04f Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 1 Aug 2019 15:05:34 -0400 Subject: Adjust test_practracker.sh to work on windows The required change is to ignore trailing CRs when diffing files. --- scripts/maint/practracker/test_practracker.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/maint/practracker/test_practracker.sh b/scripts/maint/practracker/test_practracker.sh index c7be227702..c878ca5580 100755 --- a/scripts/maint/practracker/test_practracker.sh +++ b/scripts/maint/practracker/test_practracker.sh @@ -28,6 +28,17 @@ run_practracker() { --max-include-count=0 --max-file-size=0 --max-function-size=0 --terse \ "${DATA}/" "$@"; } +compare() { + # we can't use cmp because we need to use -b for windows + diff -b -u "$@" > "${TMPDIR}/test-diff" + if test -z "$(cat "${TMPDIR}"/test-diff)"; then + echo "OK" + else + cat "${TMPDIR}/test-diff" + echo "FAILED" + exit 1 + fi +} echo "unit tests:" @@ -37,18 +48,10 @@ 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 +compare "${TMPDIR}/ex0-received.txt" "${DATA}/ex0-expected.txt" 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 +compare "${TMPDIR}/ex1-received.txt" "${DATA}/ex1-expected.txt" -- cgit v1.2.3-54-g00ecf