summaryrefslogtreecommitdiff
path: root/tests/lib/test_assert.py
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2021-03-16 11:03:44 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2021-05-02 16:27:17 +0200
commit64dd77361f7ab97365d264408afb538097c0339c (patch)
treefb9350dd6f43fae80b8d3e67cbb285901f42e125 /tests/lib/test_assert.py
parent642ac49da40a196c4e4ad74128de2056237d3cb4 (diff)
lib: rework how we "override" assert()
The previous method, using zassert.h and hoping nothing includes assert.h (which, on glibc at least, just does "#undef assert" and puts its own definition in...) was fragile - and actually broke undetected. Just provide our own assert.h and control overriding by putting it in a separate directory to add to the include path (or not.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'tests/lib/test_assert.py')
-rw-r--r--tests/lib/test_assert.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/lib/test_assert.py b/tests/lib/test_assert.py
new file mode 100644
index 0000000000..67c88e6220
--- /dev/null
+++ b/tests/lib/test_assert.py
@@ -0,0 +1,56 @@
+import frrtest
+import os
+import re
+import subprocess
+import inspect
+
+basedir = os.path.dirname(__file__)
+program = os.path.join(basedir, "test_assert")
+
+
+def check(number, rex=None):
+ proc = subprocess.Popen(
+ [frrtest.binpath(program), str(number)],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ )
+ out, err = proc.communicate()
+ exitcode = proc.wait()
+
+ if rex is None:
+ assert exitcode == 0
+ else:
+ assert exitcode != 0
+
+ text = out.decode("US-ASCII") + err.decode("US-ASCII")
+ rex = re.compile(rex, re.M | re.S)
+ m = rex.search(text)
+ assert m is not None, "non-matching output: %s" % text
+
+
+def test_assert_0():
+ check(0, r"test_assert\.c:\d+.*number > 0")
+
+
+def test_assert_1():
+ check(1, r"test_assert\.c:\d+.*number > 1.*\(B\) the number was 1")
+
+
+def test_assert_2():
+ check(2, r"test_assert\.c:\d+.*number > 2")
+
+
+def test_assert_3():
+ check(3, r"test_assert\.c:\d+.*number > 3.*\(A\) the number was 3")
+
+
+def test_assert_4():
+ check(4, r"test_assert\.c:\d+.*number > 4")
+
+
+def test_assert_10():
+ check(10, r"test_assert\.c:\d+.*number > 10.*\(D\) the number was 10")
+
+
+def test_assert_11():
+ check(11)