summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorkx <kx@radix-linux.su>2026-10-02 08:45:51 +0300
committerkx <kx@radix-linux.su>2026-10-02 08:45:51 +0300
commit9d5894a43e3b4dcc4c3b2756b289aba51eef6c63 (patch)
tree5df3a0f2d7c387180da675aec606e276c0d76f11 /tests
parentba1b04d64bdfaf377915b22f77520216ebe47674 (diff)
downloadmcpu-cpp-9d5894a43e3b4dcc4c3b2756b289aba51eef6c63.tar.xz
Move per-user configuration to /home/kx/.mcpu/etc/mcpu-cpp.conf and add --sys-root=PATH
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am3
-rwxr-xr-xtests/t0012-user-config-path.sh10
-rwxr-xr-xtests/t0022-predefined-macros.sh2
-rwxr-xr-xtests/t0024-abi-predefined.sh2
-rwxr-xr-xtests/t0025-dump-macros.sh2
-rwxr-xr-xtests/t0033-dump-definitions.sh2
-rwxr-xr-xtests/t0048-no-config-defaults.sh4
-rwxr-xr-xtests/t0053-interface-cleanup.sh5
-rwxr-xr-xtests/t0062-sys-root.sh74
9 files changed, 94 insertions, 10 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ade9bae..1d1398c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -60,7 +60,8 @@ TESTS = \
t0058-variadic-macros.sh \
t0059-va-opt.sh \
t0060-macro-whitespace.sh \
- t0061-output-line-compaction.sh
+ t0061-output-line-compaction.sh \
+ t0062-sys-root.sh
noinst_PROGRAMS = mcpp-options-test
diff --git a/tests/t0012-user-config-path.sh b/tests/t0012-user-config-path.sh
index 54b6e64..ce1fdc5 100755
--- a/tests/t0012-user-config-path.sh
+++ b/tests/t0012-user-config-path.sh
@@ -1,9 +1,13 @@
#!/bin/sh
set -eu
dir="${TMPDIR-/tmp}/mcpu-cpp-userconf-$$"
-mkdir -p "$dir/home/.mcpu" "$dir/include" "$dir/system/as"
+mkdir -p "$dir/home/.mcpu/etc" "$dir/include" "$dir/system/as" "$dir/old-system/as"
trap 'rm -rf "$dir"' EXIT HUP INT TERM
cat > "$dir/home/.mcpu/mcpu-cpp.conf" <<EOT
+MCPU_CPP_SYSTEM_INCLUDE_PATH = $dir/old-system;
+MCPU_CPP_OLD_USER_CONFIG = must-not-be-read;
+EOT
+cat > "$dir/home/.mcpu/etc/mcpu-cpp.conf" <<EOT
MCPU_CPP_INCLUDE_PATH = $dir/include;
MCPU_CPP_SYSTEM_INCLUDE_PATH = $dir/system;
EOT
@@ -24,3 +28,7 @@ grep 'from_user_mcpu_configuration' "$dir/out" >/dev/null
grep 'from_user_system_root' "$dir/out" >/dev/null
HOME="$dir/home" "$MCPU_CPP" -dconfig > "$dir/config.out"
grep "^MCPU_CPP_SYSTEM_INCLUDE_PATH = $dir/system;$" "$dir/config.out" >/dev/null
+if grep '^MCPU_CPP_OLD_USER_CONFIG = ' "$dir/config.out" >/dev/null; then
+ echo 'obsolete $HOME/.mcpu/mcpu-cpp.conf was read' >&2
+ exit 1
+fi
diff --git a/tests/t0022-predefined-macros.sh b/tests/t0022-predefined-macros.sh
index 960e1e8..bb8f79e 100755
--- a/tests/t0022-predefined-macros.sh
+++ b/tests/t0022-predefined-macros.sh
@@ -39,7 +39,7 @@ 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 '^cpp_version = "1\.0\.3";$' "$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
diff --git a/tests/t0024-abi-predefined.sh b/tests/t0024-abi-predefined.sh
index 984f0a2..04be52f 100755
--- a/tests/t0024-abi-predefined.sh
+++ b/tests/t0024-abi-predefined.sh
@@ -100,7 +100,7 @@ EOT
"$MCPU_CPP" --no-config "$base/main.c" -o "$base/out"
grep '^arch = 1;$' "$base/out" >/dev/null
-grep '^cpp_version = "1\.0\.2";$' "$base/out" >/dev/null
+grep '^cpp_version = "1\.0\.3";$' "$base/out" >/dev/null
grep '^old_version = __VERSION__;$' "$base/out" >/dev/null
grep '^byte_order = \(1234\|4321\);$' "$base/out" >/dev/null
grep '^mcpu_byte_order = \(1234\|4321\);$' "$base/out" >/dev/null
diff --git a/tests/t0025-dump-macros.sh b/tests/t0025-dump-macros.sh
index ea0ede5..91502a7 100755
--- a/tests/t0025-dump-macros.sh
+++ b/tests/t0025-dump-macros.sh
@@ -9,7 +9,7 @@ trap 'rm -rf "$base"' EXIT HUP INT TERM
test -s "$base/macros"
LC_ALL=C sort -c "$base/macros"
grep '^#define _ARCH_MCPU 1$' "$base/macros" >/dev/null
-grep '^#define __MCPU_CPP_VERSION__ "1\.0\.2"$' "$base/macros" >/dev/null
+grep '^#define __MCPU_CPP_VERSION__ "1\.0\.3"$' "$base/macros" >/dev/null
grep '^#define __MCPU_MACHINE_REGISTER_WIDTH__ 64$' "$base/macros" >/dev/null
grep '^#define __MCPU_REAL_IO_LIMIT__ [0-9][0-9]*$' "$base/macros" >/dev/null
grep '^#define __MCPU_MATH_FN_LIMIT__ [0-9][0-9]*$' "$base/macros" >/dev/null
diff --git a/tests/t0033-dump-definitions.sh b/tests/t0033-dump-definitions.sh
index 2637e53..9c30b8c 100755
--- a/tests/t0033-dump-definitions.sh
+++ b/tests/t0033-dump-definitions.sh
@@ -24,7 +24,7 @@ EOT
# ordinary preprocessed result.
grep '^# 0 "'"$base/main.c"'"$' "$base/out" >/dev/null
grep '^# 0 "<built-in>"$' "$base/out" >/dev/null
-grep '^#define __MCPU_CPP_VERSION__ "1.0.2"$' "$base/out" >/dev/null
+grep '^#define __MCPU_CPP_VERSION__ "1.0.3"$' "$base/out" >/dev/null
grep '^#define FROM_HEADER 17$' "$base/out" >/dev/null
grep '^#define LOCAL_VALUE 25$' "$base/out" >/dev/null
if grep '^[[:blank:]]*#[[:blank:]]*\(if\|ifdef\|ifndef\|elif\|else\|endif\)\>' "$base/out" >/dev/null; then
diff --git a/tests/t0048-no-config-defaults.sh b/tests/t0048-no-config-defaults.sh
index a6d2c75..595371b 100755
--- a/tests/t0048-no-config-defaults.sh
+++ b/tests/t0048-no-config-defaults.sh
@@ -1,11 +1,11 @@
#!/bin/sh
set -eu
base="${TMPDIR-/tmp}/mcpu-cpp-no-config-defaults-$$"
-mkdir -p "$base/home/.mcpu" "$base/I" "$base/isystem" "$base/after"
+mkdir -p "$base/home/.mcpu/etc" "$base/I" "$base/isystem" "$base/after"
trap 'rm -rf "$base"' EXIT HUP INT TERM
runtime_root=$(cd "$(dirname "$MCPU_CPP")/.." && pwd -P)
-cat > "$base/home/.mcpu/mcpu-cpp.conf" <<EOT
+cat > "$base/home/.mcpu/etc/mcpu-cpp.conf" <<EOT
MCPU_CPP_INCLUDE_PATH = $base/forbidden-user;
MCPU_CPP_SYSTEM_INCLUDE_PATH = $base/forbidden-system;
MCPU_CPP_AFTER_INCLUDE_PATH = $base/forbidden-after;
diff --git a/tests/t0053-interface-cleanup.sh b/tests/t0053-interface-cleanup.sh
index 80d5410..8387b27 100755
--- a/tests/t0053-interface-cleanup.sh
+++ b/tests/t0053-interface-cleanup.sh
@@ -6,15 +6,16 @@ trap 'rm -rf "$base"' EXIT HUP INT TERM
# --version identifies the independent MCPU languages preprocessor.
"$MCPU_CPP" --version > "$base/version"
-printf '%s\n' 'mcpu-cpp 1.0.2' 'MCPU languages preprocessor' > "$base/version.expected"
+printf '%s\n' 'mcpu-cpp 1.0.3' 'MCPU languages preprocessor' > "$base/version.expected"
cmp "$base/version.expected" "$base/version"
# --help contains the current public interface, including --object-suffix,
# and puts the stdin/stdout notes after the option list.
"$MCPU_CPP" --help > "$base/help"
-grep '^mcpu-cpp 1\.0\.2$' "$base/help" >/dev/null
+grep '^mcpu-cpp 1\.0\.3$' "$base/help" >/dev/null
grep '^MCPU languages preprocessor$' "$base/help" >/dev/null
grep '^ --object-suffix SFX set object suffix used for dependency targets$' "$base/help" >/dev/null
+grep '^ --sys-root=PATH use PATH as MCPU root and do not read configuration files$' "$base/help" >/dev/null
help_version_line=$(grep -n '^ --version ' "$base/help" | cut -d: -f1)
input_note_line=$(grep -n "^If input is omitted or '-', read standard input\.$" "$base/help" | cut -d: -f1)
test "$input_note_line" -gt "$help_version_line"
diff --git a/tests/t0062-sys-root.sh b/tests/t0062-sys-root.sh
new file mode 100755
index 0000000..0dcd85f
--- /dev/null
+++ b/tests/t0062-sys-root.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+set -eu
+base="${TMPDIR-/tmp}/mcpu-cpp-sys-root-$$"
+abs_root="$base/absolute-root"
+rel_root="$base/relative-root"
+home="$base/home"
+mkdir -p "$abs_root/include/as" "$rel_root/include/as" \
+ "$home/.mcpu/etc" "$base/forbidden"
+trap 'rm -rf "$base"' EXIT HUP INT TERM
+
+cat > "$abs_root/include/as/sys-root.h" <<'EOT'
+int from_absolute_sys_root = 103;
+EOT
+cat > "$rel_root/include/as/sys-root.h" <<'EOT'
+int from_relative_sys_root = 104;
+EOT
+
+cat > "$home/.mcpu/etc/mcpu-cpp.conf" <<EOT
+MCPU_CPP_INCLUDE_PATH = $base/forbidden;
+MCPU_CPP_SYSTEM_INCLUDE_PATH = $base/forbidden;
+MCPU_CPP_SYS_ROOT_SENTINEL = user-config-must-not-be-read;
+EOT
+
+cat > "$base/explicit.conf" <<EOT
+MCPU_CPP_SYSTEM_INCLUDE_PATH = $base/forbidden;
+MCPU_CPP_SYS_ROOT_SENTINEL = explicit-config-must-not-be-read;
+EOT
+
+cat > "$base/main.c" <<'EOT'
+#lang "as"
+#include <sys-root.h>
+#endlang
+EOT
+
+# An absolute --sys-root replaces the runtime root for the system include tree
+# and implies --no-config, including for an explicitly named config file.
+HOME="$home" "$MCPU_CPP" --sys-root="$abs_root" \
+ --config-file "$base/explicit.conf" -dconfig > "$base/absolute.config"
+grep "^MCPU_CPP_SYSTEM_INCLUDE_PATH = $abs_root/include;$" \
+ "$base/absolute.config" >/dev/null
+if grep 'MCPU_CPP_SYS_ROOT_SENTINEL\|forbidden' "$base/absolute.config" >/dev/null; then
+ echo '--sys-root read a configuration file' >&2
+ exit 1
+fi
+
+HOME="$home" "$MCPU_CPP" --sys-root="$abs_root" \
+ "$base/main.c" -o "$base/absolute.out"
+grep '^int from_absolute_sys_root = 103;$' "$base/absolute.out" >/dev/null
+
+# A relative --sys-root is interpreted relative to the invocation working
+# directory and becomes an absolute effective system include root.
+(
+ cd "$base"
+ HOME="$home" "$MCPU_CPP" --sys-root=relative-root -dconfig \
+ > "$base/relative.config"
+ HOME="$home" "$MCPU_CPP" --sys-root=relative-root \
+ "$base/main.c" -o "$base/relative.out"
+)
+grep "^MCPU_CPP_SYSTEM_INCLUDE_PATH = $rel_root/include;$" \
+ "$base/relative.config" >/dev/null
+grep '^int from_relative_sys_root = 104;$' "$base/relative.out" >/dev/null
+
+# The separated spelling is accepted as the same option.
+HOME="$home" "$MCPU_CPP" --sys-root "$abs_root" -dsearch-dirs \
+ > "$base/separate.search"
+grep "^search: $abs_root/include/as$" "$base/separate.search" >/dev/null
+grep "^search: $abs_root/include$" "$base/separate.search" >/dev/null
+
+# An empty system root is never accepted.
+if HOME="$home" "$MCPU_CPP" --sys-root= -dconfig \
+ > "$base/empty.out" 2> "$base/empty.err"; then
+ echo 'empty --sys-root unexpectedly accepted' >&2
+ exit 1
+fi