diff options
Diffstat (limited to 'tests/t0032-command-line.sh')
| -rwxr-xr-x | tests/t0032-command-line.sh | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/tests/t0032-command-line.sh b/tests/t0032-command-line.sh new file mode 100755 index 0000000..e0deb91 --- /dev/null +++ b/tests/t0032-command-line.sh @@ -0,0 +1,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 |
