]>
Commit | Line | Data |
---|---|---|
64dd7736 DL |
1 | import frrtest |
2 | import os | |
3 | import re | |
4 | import subprocess | |
5 | import inspect | |
6 | ||
7 | basedir = os.path.dirname(__file__) | |
8 | program = os.path.join(basedir, "test_assert") | |
9 | ||
10 | ||
11 | def check(number, rex=None): | |
12 | proc = subprocess.Popen( | |
13 | [frrtest.binpath(program), str(number)], | |
14 | stdout=subprocess.PIPE, | |
15 | stderr=subprocess.PIPE, | |
16 | ) | |
17 | out, err = proc.communicate() | |
18 | exitcode = proc.wait() | |
19 | ||
20 | if rex is None: | |
21 | assert exitcode == 0 | |
22 | else: | |
23 | assert exitcode != 0 | |
24 | ||
25 | text = out.decode("US-ASCII") + err.decode("US-ASCII") | |
26 | rex = re.compile(rex, re.M | re.S) | |
27 | m = rex.search(text) | |
28 | assert m is not None, "non-matching output: %s" % text | |
29 | ||
30 | ||
31 | def test_assert_0(): | |
32 | check(0, r"test_assert\.c:\d+.*number > 0") | |
33 | ||
34 | ||
35 | def test_assert_1(): | |
36 | check(1, r"test_assert\.c:\d+.*number > 1.*\(B\) the number was 1") | |
37 | ||
38 | ||
39 | def test_assert_2(): | |
40 | check(2, r"test_assert\.c:\d+.*number > 2") | |
41 | ||
42 | ||
43 | def test_assert_3(): | |
44 | check(3, r"test_assert\.c:\d+.*number > 3.*\(A\) the number was 3") | |
45 | ||
46 | ||
47 | def test_assert_4(): | |
48 | check(4, r"test_assert\.c:\d+.*number > 4") | |
49 | ||
50 | ||
51 | def test_assert_10(): | |
52 | check(10, r"test_assert\.c:\d+.*number > 10.*\(D\) the number was 10") | |
53 | ||
54 | ||
55 | def test_assert_11(): | |
56 | check(11) |