summaryrefslogtreecommitdiff
path: root/tests/t0022-predefined-macros.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/t0022-predefined-macros.sh')
-rwxr-xr-xtests/t0022-predefined-macros.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/t0022-predefined-macros.sh b/tests/t0022-predefined-macros.sh
new file mode 100755
index 0000000..960e1e8
--- /dev/null
+++ b/tests/t0022-predefined-macros.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+set -eu
+base="${TMPDIR-/tmp}/mcpu-cpp-predef-$$"
+mkdir -p "$base"
+trap 'rm -rf "$base"' EXIT HUP INT TERM
+
+cat > "$base/main.c" <<'EOT'
+root_file = __FILE__;
+root_base = __BASE_FILE__;
+root_level = __INCLUDE_LEVEL__;
+#define HERE() __LINE__
+root_line = HERE();
+cpp_version = __MCPU_CPP_VERSION__;
+old_version_name = __VERSION__;
+date = __DATE__;
+time = __TIME__;
+#include "one.h"
+after_line = __LINE__;
+EOT
+
+cat > "$base/one.h" <<'EOT'
+one_file = __FILE__;
+one_base = __BASE_FILE__;
+one_level = __INCLUDE_LEVEL__;
+one_line = __LINE__;
+#include "two.h"
+EOT
+
+cat > "$base/two.h" <<'EOT'
+two_file = __FILE__;
+two_base = __BASE_FILE__;
+two_level = __INCLUDE_LEVEL__;
+two_line = __LINE__;
+EOT
+
+"$MCPU_CPP" --no-config "$base/main.c" -o "$base/out"
+
+grep -F "root_file = \"$base/main.c\";" "$base/out" >/dev/null
+grep -F "root_base = \"$base/main.c\";" "$base/out" >/dev/null
+grep '^root_level = 0;$' "$base/out" >/dev/null
+grep '^root_line = 5;$' "$base/out" >/dev/null
+grep '^cpp_version = "1\.0\.2";$' "$base/out" >/dev/null
+grep '^old_version_name = __VERSION__;$' "$base/out" >/dev/null
+grep '^date = "[A-Z][a-z][a-z] [0-9] [0-9][0-9][0-9][0-9]";$\|^date = "[A-Z][a-z][a-z] [12][0-9] [0-9][0-9][0-9][0-9]";$\|^date = "[A-Z][a-z][a-z] 3[01] [0-9][0-9][0-9][0-9]";$' "$base/out" >/dev/null
+grep '^time = "[0-2][0-9]:[0-5][0-9]:[0-5][0-9]";$' "$base/out" >/dev/null
+
+grep -F "one_file = \"$base/one.h\";" "$base/out" >/dev/null
+grep -F "one_base = \"$base/main.c\";" "$base/out" >/dev/null
+grep '^one_level = 1;$' "$base/out" >/dev/null
+grep '^one_line = 4;$' "$base/out" >/dev/null
+
+grep -F "two_file = \"$base/two.h\";" "$base/out" >/dev/null
+grep -F "two_base = \"$base/main.c\";" "$base/out" >/dev/null
+grep '^two_level = 2;$' "$base/out" >/dev/null
+grep '^two_line = 4;$' "$base/out" >/dev/null
+grep '^after_line = 11;$' "$base/out" >/dev/null