summaryrefslogtreecommitdiff
path: root/tests/t0035-line-control.sh
blob: b892015da66a8199b6f95b8f4f414a1982355935 (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
#!/bin/sh
set -eu
base="${TMPDIR-/tmp}/mcpu-cpp-line-control-$$"
mkdir -p "$base/inc"
trap 'rm -rf "$base"' EXIT HUP INT TERM

cat > "$base/inc/one.h" <<'EOT'
int header_line = __LINE__;
EOT

cat > "$base/main.c" <<'EOT'
int before = __LINE__;
#line 62 "main.y"
int after = __LINE__;
const char *file_after = __FILE__;
#include "one.h"
int returned = __LINE__;
#define LINE_NUMBER 90
#line LINE_NUMBER "macro-line.y"
int macro_line = __LINE__;
EOT

"$MCPU_CPP" --no-config -I"$base/inc" "$base/main.c" -o "$base/out"

# Generated line information uses GNU linemarker syntax, not input #line syntax.
if grep '^#line[[:blank:]]' "$base/out" >/dev/null; then exit 1; fi

grep "^# 1 \"$base/main.c\"$" "$base/out" >/dev/null
grep '^# 62 "main.y"$' "$base/out" >/dev/null
grep '^int after = 62;$' "$base/out" >/dev/null
grep '^const char \*file_after = "main.y";$' "$base/out" >/dev/null

# Flag 1 means entering an included file; flag 2 means returning to its includer.
grep "^# 1 \"$base/inc/one.h\" 1$" "$base/out" >/dev/null
grep '^# 65 "main.y" 2$' "$base/out" >/dev/null
grep '^int returned = 65;$' "$base/out" >/dev/null

# Arguments of #line are macro-expanded before interpretation.
grep '^# 90 "macro-line.y"$' "$base/out" >/dev/null
grep '^int macro_line = 90;$' "$base/out" >/dev/null