summaryrefslogtreecommitdiff
path: root/tests/t0045-search-dirs-verbose.sh
blob: 03a639313065d032ab2d917d60d4c5f030b6164f (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
set -eu
base="${TMPDIR-/tmp}/mcpu-cpp-search-dirs-$$"
mkdir -p \
  "$base/cmd-user" \
  "$base/cmd-system" \
  "$base/config-as" \
  "$base/config-user" \
  "$base/system" \
  "$base/cmd-after" \
  "$base/config-after"
trap 'rm -rf "$base"' EXIT HUP INT TERM
runtime_root=$(cd "$(dirname "$MCPU_CPP")/.." && pwd -P)

cat > "$base/test.conf" <<EOT
MCPU_CPP_INCLUDE_PATH = $base/old-user;
MCPU_CPP_AS_INCLUDE_PATH = $base/config-as;
MCPU_CPP_INCLUDE_PATH = $base/config-user;
MCPU_CPP_SYSTEM_INCLUDE_PATH = $base/system;
MCPU_CPP_AFTER_INCLUDE_PATH = $base/config-after;
EOT

"$MCPU_CPP" \
  --config-file "$base/test.conf" \
  -I "$base/cmd-user" \
  -isystem "$base/cmd-system" \
  -idirafter "$base/cmd-after" \
  -v -dsearch-dirs \
  > "$base/search.out" 2> "$base/verbose.out"

cat > "$base/search.expected" <<EOT
search: $base/cmd-user
search: $base/cmd-system
search: $base/config-as
search: $base/config-user
search: $base/system/diff
search: $base/system/dift
search: $base/system/alg
search: $base/system/as
search: $base/system/avm
search: $base/system/acs
search: $base/system
search: $base/cmd-after
search: $base/config-after
EOT
cmp "$base/search.expected" "$base/search.out"

# -v prints one effective value, not every assignment encountered while
# reading configuration files.
test "$(grep -c '^config: MCPU_CPP_INCLUDE_PATH=' "$base/verbose.out")" -eq 1
grep "^config: MCPU_CPP_INCLUDE_PATH=$base/config-user$" "$base/verbose.out" >/dev/null
if grep "$base/old-user" "$base/verbose.out" >/dev/null; then
  echo 'verbose output contains an overridden configuration value' >&2
  exit 1
fi
grep "^config: MCPU_CPP_AS_INCLUDE_PATH=$base/config-as$" "$base/verbose.out" >/dev/null
grep "^config: MCPU_CPP_SYSTEM_INCLUDE_PATH=$base/system$" "$base/verbose.out" >/dev/null
grep "^config: MCPU_CPP_AFTER_INCLUDE_PATH=$base/config-after$" "$base/verbose.out" >/dev/null

# Even when an explicitly selected configuration file is empty, -v and
# -dsearch-dirs must expose the runtime-derived installation system root.
: > "$base/empty.conf"
"$MCPU_CPP" --config-file "$base/empty.conf" -v -dsearch-dirs \
  > "$base/default-search.out" 2> "$base/default-verbose.out"
grep '^config: MCPU_CPP_SYSTEM_INCLUDE_PATH=' "$base/default-verbose.out" >/dev/null
grep "^search: $runtime_root/include$" "$base/default-search.out" >/dev/null

# -nostdinc removes both the generated <lang> system directories and the
# configured system root from the directory dump, but keeps explicit -isystem.
"$MCPU_CPP" \
  --config-file "$base/test.conf" \
  -isystem "$base/cmd-system" \
  -nostdinc -dsearch-dirs > "$base/nostdinc.out"
grep "^search: $base/cmd-system$" "$base/nostdinc.out" >/dev/null
if grep "^search: $base/system" "$base/nostdinc.out" >/dev/null; then
  echo '-nostdinc left configured system directories in -dsearch-dirs' >&2
  exit 1
fi

# A dump action stops preprocessing.  An input name may be present but need
# not exist.
"$MCPU_CPP" --config-file "$base/test.conf" -dsearch-dirs \
  "$base/does-not-exist.c" > /dev/null

if "$MCPU_CPP" --config-file "$base/test.conf" -dsearch-dirs -o "$base/out" \
     > /dev/null 2>&1; then
  echo '-dsearch-dirs accepted an output file' >&2
  exit 1
fi