Commit 14a8c1a
authored
Remove the boost test runner (#38)
* scripted-diff: Unroll `&&` conditions in tests
Most test frameworks use a technique called expression decomposition, which
captures the values of test expressions. The `&&` is `delete` when using value decomposition.
ref: https://fekir.info/post/decomposing-an-expression/
-BEGIN VERIFY SCRIPT-
set -eu
MACRO_RE='BOOST_CHECK|BOOST_REQUIRE|BOOST_CHECK_MESSAGE|BOOST_REQUIRE_MESSAGE|BOOST_CHECK_NO_THROW|BOOST_REQUIRE_NO_THROW'
FILES=$(git grep -lE "\b(${MACRO_RE})[[:space:]]*\(" -- \
':(glob)src/test/**/*.cpp' ':(glob)src/test/**/*.h' \
':(glob)src/test/*.cpp' ':(glob)src/test/*.h' \
':(glob)src/ipc/test/**/*.cpp' ':(glob)src/ipc/test/**/*.h' \
':(glob)src/ipc/test/*.cpp' ':(glob)src/ipc/test/*.h' 2>/dev/null || true)
if [ -z "$FILES" ]; then
echo "no matching files"
exit 0
fi
perl -i -0777 -pe '
use strict;
use warnings;
my $names = "BOOST_CHECK|BOOST_REQUIRE|BOOST_CHECK_MESSAGE|BOOST_REQUIRE_MESSAGE|BOOST_CHECK_NO_THROW|BOOST_REQUIRE_NO_THROW";
my $re = qr/\b($names)\s*\(/;
my @DIGIT_SEP_PREV = (0) x 256;
$DIGIT_SEP_PREV[ord($_)] = 1 for split //, "0123456789abcdefABCDEF" . chr(39);
sub is_char_open {
my ($s, $i) = @_;
return 1 if $i == 0;
return $DIGIT_SEP_PREV[ord(substr($$s, $i-1, 1))] ? 0 : 1;
}
sub close_paren {
my ($s, $open) = @_;
my ($depth, $i, $in_str, $in_char) = (0, $open, 0, 0);
my $n = length($$s);
while ($i < $n) {
my $c = substr($$s, $i, 1);
if ($in_str) {
if ($c eq "\\") { $i += 2; next; }
$in_str = 0 if $c eq q{"};
} elsif ($in_char) {
if ($c eq "\\") { $i += 2; next; }
$in_char = 0 if $c eq chr(39);
} elsif ($c eq q{"}) { $in_str = 1; }
elsif ($c eq chr(39) && is_char_open($s, $i)) { $in_char = 1; }
elsif ($c =~ /[(\[{]/) { $depth++; }
elsif ($c =~ /[)\]}]/) { $depth--; return $i if $depth == 0; }
$i++;
}
return -1;
}
sub split_first_comma {
my ($s) = @_;
my ($depth, $i, $in_str, $in_char) = (0, 0, 0, 0);
my $n = length($s);
while ($i < $n) {
my $c = substr($s, $i, 1);
if ($in_str) {
if ($c eq "\\") { $i += 2; next; }
$in_str = 0 if $c eq q{"};
} elsif ($in_char) {
if ($c eq "\\") { $i += 2; next; }
$in_char = 0 if $c eq chr(39);
} elsif ($c eq q{"}) { $in_str = 1; }
elsif ($c eq chr(39) && is_char_open(\$s, $i)) { $in_char = 1; }
elsif ($c =~ /[(\[{]/) { $depth++; }
elsif ($c =~ /[)\]}]/) { $depth--; }
elsif ($c eq "," && $depth == 0) {
return (substr($s, 0, $i), substr($s, $i));
}
$i++;
}
return ($s, "");
}
sub top_level_and_positions {
my ($e) = @_;
my @ops;
my ($depth, $i, $in_str, $in_char) = (0, 0, 0, 0);
my $n = length($e);
while ($i < $n) {
my $c = substr($e, $i, 1);
if ($in_str) {
if ($c eq "\\") { $i += 2; next; }
$in_str = 0 if $c eq q{"};
$i++; next;
} elsif ($in_char) {
if ($c eq "\\") { $i += 2; next; }
$in_char = 0 if $c eq chr(39);
$i++; next;
}
if ($c eq q{"}) { $in_str = 1; $i++; next; }
if ($c eq chr(39) && is_char_open(\$e, $i)) { $in_char = 1; $i++; next; }
if ($c =~ /[(\[{]/) { $depth++; $i++; next; }
if ($c =~ /[)\]}]/) { $depth--; $i++; next; }
if ($depth == 0 && $i + 1 < $n && substr($e, $i, 2) eq "&&") {
push @ops, $i;
$i += 2; next;
}
$i++;
}
return @ops;
}
my $text = $_;
my $out = "";
my $cur = 0;
while ($text =~ /$re/g) {
my $macro = $1;
my $m_start = $-[0];
my $p_open = $+[0] - 1;
my $p_close = close_paren(\$text, $p_open);
next if $p_close < 0;
my $args = substr($text, $p_open + 1, $p_close - $p_open - 1);
my ($expr_raw, $message) = split_first_comma($args);
my $expr = $expr_raw;
$expr =~ s/^\s+//;
$expr =~ s/\s+$//;
my @ats = top_level_and_positions($expr);
next unless @ats;
# Compose the replacement with original indentation.
my $line_start = rindex(substr($text, 0, $m_start), "\n") + 1;
my $indent = substr($text, $line_start, $m_start - $line_start);
$indent =~ s/[^\s].*//s;
my @Parts;
my $last = 0;
for my $p (@ats) {
my $piece = substr($expr, $last, $p - $last);
$piece =~ s/^\s+//; $piece =~ s/\s+$//;
push @Parts, $piece;
$last = $p + 2;
}
my $tail = substr($expr, $last);
$tail =~ s/^\s+//; $tail =~ s/\s+$//;
push @Parts, $tail;
my $sep = ";\n" . $indent;
my $replacement = join($sep, map { "$macro($_$message)" } @Parts);
$out .= substr($text, $cur, $m_start - $cur);
$out .= $replacement;
$cur = $p_close + 1;
# Resume the global match where the new content ends.
pos($text) = $cur;
}
$out .= substr($text, $cur);
$_ = $out;
' -- $FILES
-END VERIFY SCRIPT-
* scripted-diff: Wrap checks with `||`
`||` is also `delete` when decomposing an expression. See previous
commit message.
ref: https://fekir.info/post/decomposing-an-expression/
-BEGIN VERIFY SCRIPT-
set -eu
MACRO_RE='BOOST_CHECK|BOOST_REQUIRE|BOOST_CHECK_MESSAGE|BOOST_REQUIRE_MESSAGE|BOOST_CHECK_NO_THROW|BOOST_REQUIRE_NO_THROW'
FILES=$(git grep -lE "\b(${MACRO_RE})[[:space:]]*\(" -- \
':(glob)src/test/**/*.cpp' ':(glob)src/test/**/*.h' \
':(glob)src/test/*.cpp' ':(glob)src/test/*.h' \
':(glob)src/ipc/test/**/*.cpp' ':(glob)src/ipc/test/**/*.h' \
':(glob)src/ipc/test/*.cpp' ':(glob)src/ipc/test/*.h' 2>/dev/null || true)
if [ -z "$FILES" ]; then
echo "no matching files"
exit 0
fi
perl -i -0777 -pe '
use strict;
use warnings;
my $names = "BOOST_CHECK|BOOST_REQUIRE|BOOST_CHECK_MESSAGE|BOOST_REQUIRE_MESSAGE|BOOST_CHECK_NO_THROW|BOOST_REQUIRE_NO_THROW";
my $re = qr/\b($names)\s*\(/;
my @DIGIT_SEP_PREV = (0) x 256;
$DIGIT_SEP_PREV[ord($_)] = 1 for split //, "0123456789abcdefABCDEF" . chr(39);
sub is_char_open {
my ($s, $i) = @_;
return 1 if $i == 0;
return $DIGIT_SEP_PREV[ord(substr($$s, $i-1, 1))] ? 0 : 1;
}
sub close_paren {
my ($s, $open) = @_;
my ($depth, $i, $in_str, $in_char) = (0, $open, 0, 0);
my $n = length($$s);
while ($i < $n) {
my $c = substr($$s, $i, 1);
if ($in_str) {
if ($c eq "\\") { $i += 2; next; }
$in_str = 0 if $c eq q{"};
} elsif ($in_char) {
if ($c eq "\\") { $i += 2; next; }
$in_char = 0 if $c eq chr(39);
} elsif ($c eq q{"}) { $in_str = 1; }
elsif ($c eq chr(39) && is_char_open($s, $i)) { $in_char = 1; }
elsif ($c =~ /[(\[{]/) { $depth++; }
elsif ($c =~ /[)\]}]/) { $depth--; return $i if $depth == 0; }
$i++;
}
return -1;
}
sub split_first_comma {
my ($s) = @_;
my ($depth, $i, $in_str, $in_char) = (0, 0, 0, 0);
my $n = length($s);
while ($i < $n) {
my $c = substr($s, $i, 1);
if ($in_str) {
if ($c eq "\\") { $i += 2; next; }
$in_str = 0 if $c eq q{"};
} elsif ($in_char) {
if ($c eq "\\") { $i += 2; next; }
$in_char = 0 if $c eq chr(39);
} elsif ($c eq q{"}) { $in_str = 1; }
elsif ($c eq chr(39) && is_char_open(\$s, $i)) { $in_char = 1; }
elsif ($c =~ /[(\[{]/) { $depth++; }
elsif ($c =~ /[)\]}]/) { $depth--; }
elsif ($c eq "," && $depth == 0) {
return (substr($s, 0, $i), substr($s, $i));
}
$i++;
}
return ($s, "");
}
sub has_top_level_or {
my ($e) = @_;
my ($depth, $i, $in_str, $in_char) = (0, 0, 0, 0);
my $n = length($e);
while ($i < $n) {
my $c = substr($e, $i, 1);
if ($in_str) {
if ($c eq "\\") { $i += 2; next; }
$in_str = 0 if $c eq q{"};
$i++; next;
} elsif ($in_char) {
if ($c eq "\\") { $i += 2; next; }
$in_char = 0 if $c eq chr(39);
$i++; next;
}
if ($c eq q{"}) { $in_str = 1; $i++; next; }
if ($c eq chr(39) && is_char_open(\$e, $i)) { $in_char = 1; $i++; next; }
if ($c =~ /[(\[{]/) { $depth++; $i++; next; }
if ($c =~ /[)\]}]/) { $depth--; $i++; next; }
if ($depth == 0 && $i + 1 < $n && substr($e, $i, 2) eq "||") {
return 1;
}
$i++;
}
return 0;
}
my $text = $_;
my $out = "";
my $cur = 0;
while ($text =~ /$re/g) {
my $macro = $1;
my $m_start = $-[0];
my $p_open = $+[0] - 1;
my $p_close = close_paren(\$text, $p_open);
next if $p_close < 0;
my $args = substr($text, $p_open + 1, $p_close - $p_open - 1);
my ($expr_raw, $message) = split_first_comma($args);
my $expr = $expr_raw;
$expr =~ s/^\s+//;
$expr =~ s/\s+$//;
next unless has_top_level_or($expr);
$out .= substr($text, $cur, $m_start - $cur);
$out .= "$macro(($expr)$message)";
$cur = $p_close + 1;
pos($text) = $cur;
}
$out .= substr($text, $cur);
$_ = $out;
' -- $FILES
-END VERIFY SCRIPT-
* test: Add header-only test framework
Adds src/test/util/framework.hpp as a lightweight Boost.Test replacement.
This commit only introduces the header; build-system integration and
call-site migration follow in subsequent commits.
Includes:
- `CHECK`, valid with any comparison operator, optional message
- `REQUIRE`, valid with any comparison operator, optional message
- `CHECK_EQUAL_RANGES`, better debugging for vectors
- `THROW_*`, macros for checking throwing conditions
- Info and warn messages
* test: Integrate test framework
Integrates src/test/util/framework.hpp into the build (CMake, main.cpp)
and replaces the Boost.Test macros across the unit test suite via a
scripted diff.
* test: Enforce comparison of signed types at compile time
* Remove remaining `BOOST` references1 parent 6e7021e commit 14a8c1a
135 files changed
Lines changed: 9383 additions & 8634 deletions
File tree
- ci/test
- doc
- src
- ipc/test
- test
- kernel
- util
- test/lint
- test_runner/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
| 47 | + | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
50 | | - | |
51 | | - | |
| 49 | + | |
| 50 | + | |
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
| |||
87 | 86 | | |
88 | 87 | | |
89 | 88 | | |
90 | | - | |
| 89 | + | |
91 | 90 | | |
92 | 91 | | |
93 | 92 | | |
94 | | - | |
| 93 | + | |
95 | 94 | | |
96 | 95 | | |
97 | 96 | | |
98 | 97 | | |
99 | 98 | | |
100 | | - | |
| 99 | + | |
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
| |||
106 | 105 | | |
107 | 106 | | |
108 | 107 | | |
109 | | - | |
| 108 | + | |
110 | 109 | | |
111 | 110 | | |
112 | 111 | | |
113 | | - | |
| 112 | + | |
114 | 113 | | |
115 | 114 | | |
116 | 115 | | |
117 | | - | |
| 116 | + | |
118 | 117 | | |
119 | 118 | | |
120 | 119 | | |
| |||
125 | 124 | | |
126 | 125 | | |
127 | 126 | | |
128 | | - | |
| 127 | + | |
129 | 128 | | |
130 | 129 | | |
131 | 130 | | |
| |||
135 | 134 | | |
136 | 135 | | |
137 | 136 | | |
138 | | - | |
| 137 | + | |
139 | 138 | | |
140 | 139 | | |
141 | | - | |
| 140 | + | |
142 | 141 | | |
143 | 142 | | |
144 | 143 | | |
| |||
151 | 150 | | |
152 | 151 | | |
153 | 152 | | |
154 | | - | |
155 | | - | |
| 153 | + | |
| 154 | + | |
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
159 | 158 | | |
160 | | - | |
161 | | - | |
| 159 | + | |
| 160 | + | |
162 | 161 | | |
163 | 162 | | |
164 | 163 | | |
165 | 164 | | |
166 | 165 | | |
167 | 166 | | |
168 | | - | |
| 167 | + | |
169 | 168 | | |
170 | 169 | | |
171 | | - | |
| 170 | + | |
172 | 171 | | |
173 | 172 | | |
174 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
21 | | - | |
| 20 | + | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | | - | |
| 27 | + | |
29 | 28 | | |
30 | | - | |
| 29 | + | |
31 | 30 | | |
32 | | - | |
| 31 | + | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| |||
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
43 | | - | |
| 42 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
174 | | - | |
175 | | - | |
| 173 | + | |
176 | 174 | | |
177 | 175 | | |
178 | | - | |
| 176 | + | |
179 | 177 | | |
180 | 178 | | |
181 | 179 | | |
| |||
194 | 192 | | |
195 | 193 | | |
196 | 194 | | |
197 | | - | |
| 195 | + | |
198 | 196 | | |
199 | 197 | | |
200 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | | - | |
34 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
129 | | - | |
130 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
131 | 134 | | |
132 | 135 | | |
133 | 136 | | |
| |||
146 | 149 | | |
147 | 150 | | |
148 | 151 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
| |||
0 commit comments