summaryrefslogtreecommitdiff
path: root/tests/t0032-command-line.sh
blob: e0deb91d2a6efd0655956d3689871fb95872e65e (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
set -eu
base="${TMPDIR-/tmp}/mcpu-cpp-options-$$"
mkdir -p "$base"
trap 'rm -rf "$base"' EXIT HUP INT TERM

check()
{
  name=$1
  shift
  "$MCPP_OPTIONS_TEST" "$@" > "$base/$name"
}

check pipe
cat > "$base/pipe.expected" <<'EOT'
input=<stdin>
output=<stdout>
verbose=0
nostdinc=0
dump_config=0
dump_search_dirs=0
dump_macros=0
actions=0
EOT
cmp "$base/pipe.expected" "$base/pipe"

check files input.S output.s
sed -n '1,2p' "$base/files" > "$base/files.io"
printf '%s\n' 'input=input.S' 'output=output.s' > "$base/files.expected"
cmp "$base/files.expected" "$base/files.io"

check dash - -
sed -n '1,2p' "$base/dash" > "$base/dash.io"
printf '%s\n' 'input=<stdin>' 'output=<stdout>' > "$base/dash.expected"
cmp "$base/dash.expected" "$base/dash.io"

check outfile input.S -o result.s
sed -n '1,2p' "$base/outfile" > "$base/outfile.io"
printf '%s\n' 'input=input.S' 'output=result.s' > "$base/outfile.expected"
cmp "$base/outfile.expected" "$base/outfile.io"

check options -v -nostdinc -Iinc1 -I inc2 -isystem sys -idirafter after input.S -
grep '^verbose=1$' "$base/options" >/dev/null
grep '^nostdinc=1$' "$base/options" >/dev/null
grep '^actions=4$' "$base/options" >/dev/null
grep '^action\[0\]=include-user:inc1$' "$base/options" >/dev/null
grep '^action\[1\]=include-user:inc2$' "$base/options" >/dev/null
grep '^action\[2\]=include-system:sys$' "$base/options" >/dev/null
grep '^action\[3\]=include-after:after$' "$base/options" >/dev/null

check ordered -DA=1 -UA -DA=2
sed -n '/^actions=/,$p' "$base/ordered" > "$base/ordered.actions"
cat > "$base/ordered.expected" <<'EOT'
actions=3
action[0]=define:A=1
action[1]=undef:A
action[2]=define:A=2
EOT
cmp "$base/ordered.expected" "$base/ordered.actions"

check searchdirs -dsearch-dirs
grep '^dump_search_dirs=1$' "$base/searchdirs" >/dev/null

check dump -dMP input.S -o macros.txt
grep '^dump_macros=1$' "$base/dump" >/dev/null

check retained -include force.h -imacros macros.h -DA=1 -UOLD -M -MG -w -Wall -Werror input.S output.s
grep '^input=input.S$' "$base/retained" >/dev/null
grep '^output=output.s$' "$base/retained" >/dev/null
grep '^action\[[0-9][0-9]*\]=include:force.h$' "$base/retained" >/dev/null
grep '^action\[[0-9][0-9]*\]=imacros:macros.h$' "$base/retained" >/dev/null
grep '^action\[[0-9][0-9]*\]=define:A=1$' "$base/retained" >/dev/null
grep '^action\[[0-9][0-9]*\]=undef:OLD$' "$base/retained" >/dev/null

check dumpD -dD input.S
grep '^dump_macros=2$' "$base/dumpD" >/dev/null

check md -MD input.S
grep '^input=input.S$' "$base/md" >/dev/null
check mmd -MMD input.S
grep '^input=input.S$' "$base/mmd" >/dev/null
check mf -MD -MF deps.mk input.S
grep '^input=input.S$' "$base/mf" >/dev/null
check mfattached -MMD -MFdeps.mk input.S
grep '^input=input.S$' "$base/mfattached" >/dev/null
check mt -M -MT target.o input.S
grep '^action\[[0-9][0-9]*\]=dep-target:target.o$' "$base/mt" >/dev/null
check mtattached -MM -MTtarget.o input.S
grep '^action\[[0-9][0-9]*\]=dep-target:target.o$' "$base/mtattached" >/dev/null
check mq -MD -MQ '$(OBJDIR)/target.o' input.S
grep '^action\[[0-9][0-9]*\]=dep-target-quoted:$(OBJDIR)/target.o$' "$base/mq" >/dev/null
check mqattached -MMD '-MQ$(OBJDIR)/target.o' input.S
grep '^action\[[0-9][0-9]*\]=dep-target-quoted:$(OBJDIR)/target.o$' "$base/mqattached" >/dev/null
if "$MCPP_OPTIONS_TEST" a b c > /dev/null 2>&1; then exit 1; fi
if "$MCPP_OPTIONS_TEST" -o > /dev/null 2>&1; then exit 1; fi
if "$MCPP_OPTIONS_TEST" -isystem > /dev/null 2>&1; then exit 1; fi
if "$MCPP_OPTIONS_TEST" --bad-option > /dev/null 2>&1; then exit 1; fi
if "$MCPP_OPTIONS_TEST" -MF deps.mk input.S > /dev/null 2>&1; then exit 1; fi
if "$MCPP_OPTIONS_TEST" -MT target.o input.S > /dev/null 2>&1; then exit 1; fi
if "$MCPP_OPTIONS_TEST" -MQ target.o input.S > /dev/null 2>&1; then exit 1; fi
if "$MCPP_OPTIONS_TEST" -M -MT > /dev/null 2>&1; then exit 1; fi
if "$MCPP_OPTIONS_TEST" -M -MQ > /dev/null 2>&1; then exit 1; fi

# Unsupported legacy assertion options remain rejected.
if "$MCPP_OPTIONS_TEST" -Aquestion input.S > /dev/null 2>&1; then exit 1; fi
if "$MCPP_OPTIONS_TEST" -dMA input.S > /dev/null 2>&1; then exit 1; fi

# Removed compatibility options are not recognized by mcpu-cpp.
for opt in \
  -x -X -out-unix-mode -I- -H -C -P '-$' -r -R -undef -u -dN -g3 -dark \
  -Wimport -Wno-import -pedantic-ANSI-C -pedantic-ANSI-C-errors \
  -lang-k -lang-k++ -lang-k-k++-comments -lang-asm -+ \
  -iprefix -iwithprefix -iwithprefixbefore
do
  if "$MCPP_OPTIONS_TEST" "$opt" input.S > /dev/null 2>&1; then
    echo "removed option unexpectedly accepted: $opt" >&2
    exit 1
  fi
done