#!/bin/sh set -eu src="${TMPDIR-/tmp}/mcpu-cpp-comments-$$.c" out="${TMPDIR-/tmp}/mcpu-cpp-comments-$$.out" trap 'rm -f "$src" "$out"' EXIT HUP INT TERM cat > "$src" <<'EOT' /* #lang "diff" */ int c_side; /* comment before directive */ #lang "diff" y' = 1; #endlang // one-line comment /* multi-line comment */ LEFT/**/RIGHT int block_tail; /* block tail */ int line_tail; // line tail int multi_tail; /* block tail */ EOT "$MCPU_CPP" --no-config "$src" -o "$out" grep 'int c_side' "$out" >/dev/null grep "y' = 1" "$out" >/dev/null grep '^LEFT RIGHT$' "$out" >/dev/null # Comment-only lines must be really empty; no synthetic or leading spaces remain. if grep '^[[:blank:]][[:blank:]]*$' "$out" >/dev/null; then exit 1 fi # A comment ending a non-empty line must not leave trailing whitespace. grep '^int block_tail;$' "$out" >/dev/null grep '^int line_tail;$' "$out" >/dev/null grep '^int multi_tail;$' "$out" >/dev/null if grep '[[:blank:]]$' "$out" >/dev/null; then exit 1 fi