blob: 8abf4d9c9a8f888ebe110000aa6be6c50824592f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/bin/sh
set -eu
base="${TMPDIR-/tmp}/mcpu-cpp-predef-$$"
mkdir -p "$base"
trap 'rm -rf "$base"' EXIT HUP INT TERM
cat > "$base/main.c" <<'EOT'
root_file = __FILE__;
root_base = __BASE_FILE__;
root_level = __INCLUDE_LEVEL__;
#define HERE() __LINE__
root_line = HERE();
cpp_version = __MCPU_CPP_VERSION__;
old_version_name = __VERSION__;
date = __DATE__;
time = __TIME__;
#include "one.h"
after_line = __LINE__;
EOT
cat > "$base/one.h" <<'EOT'
one_file = __FILE__;
one_base = __BASE_FILE__;
one_level = __INCLUDE_LEVEL__;
one_line = __LINE__;
#include "two.h"
EOT
cat > "$base/two.h" <<'EOT'
two_file = __FILE__;
two_base = __BASE_FILE__;
two_level = __INCLUDE_LEVEL__;
two_line = __LINE__;
EOT
"$MCPU_CPP" --no-config "$base/main.c" -o "$base/out"
grep -F "root_file = \"$base/main.c\";" "$base/out" >/dev/null
grep -F "root_base = \"$base/main.c\";" "$base/out" >/dev/null
grep '^root_level = 0;$' "$base/out" >/dev/null
grep '^root_line = 5;$' "$base/out" >/dev/null
grep '^cpp_version = "1\.0\.4";$' "$base/out" >/dev/null
grep '^old_version_name = __VERSION__;$' "$base/out" >/dev/null
grep '^date = "[A-Z][a-z][a-z] [0-9] [0-9][0-9][0-9][0-9]";$\|^date = "[A-Z][a-z][a-z] [12][0-9] [0-9][0-9][0-9][0-9]";$\|^date = "[A-Z][a-z][a-z] 3[01] [0-9][0-9][0-9][0-9]";$' "$base/out" >/dev/null
grep '^time = "[0-2][0-9]:[0-5][0-9]:[0-5][0-9]";$' "$base/out" >/dev/null
grep -F "one_file = \"$base/one.h\";" "$base/out" >/dev/null
grep -F "one_base = \"$base/main.c\";" "$base/out" >/dev/null
grep '^one_level = 1;$' "$base/out" >/dev/null
grep '^one_line = 4;$' "$base/out" >/dev/null
grep -F "two_file = \"$base/two.h\";" "$base/out" >/dev/null
grep -F "two_base = \"$base/main.c\";" "$base/out" >/dev/null
grep '^two_level = 2;$' "$base/out" >/dev/null
grep '^two_line = 4;$' "$base/out" >/dev/null
grep '^after_line = 11;$' "$base/out" >/dev/null
|