summaryrefslogtreecommitdiff
path: root/tests/t0005-errors.sh
blob: 458b4c896837b504f38678436128d870f3cee4f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
set -eu
out="${TMPDIR-/tmp}/mcpu-cpp-error-$$.out"
err="${TMPDIR-/tmp}/mcpu-cpp-error-$$.err"
bad="${TMPDIR-/tmp}/mcpu-cpp-nonucs2-$$.c"
trap 'rm -f "$out" "$err" "$bad"' EXIT HUP INT TERM

if "$MCPU_CPP" --no-config "$srcdir/data/unbalanced.c" -o "$out" 2>"$err"; then
  exit 1
fi
grep 'unbalanced #lang/#endlang' "$err" >/dev/null

# A valid UTF-8 scalar outside UCS-2 is harmless inside a comment.
"$MCPU_CPP" --no-config "$srcdir/data/nonucs2.c" -o "$out"
grep '^int x;$' "$out" >/dev/null

# The same scalar in program text is rejected after comment removal.
printf 'int x = \360\237\230\200;\n' > "$bad"
if "$MCPU_CPP" --no-config "$bad" -o "$out" 2>"$err"; then
  exit 1
fi
grep 'character outside UCS-2' "$err" >/dev/null