summaryrefslogtreecommitdiff
path: root/tests/t0049-relocatable-root.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/t0049-relocatable-root.sh')
-rwxr-xr-xtests/t0049-relocatable-root.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/t0049-relocatable-root.sh b/tests/t0049-relocatable-root.sh
new file mode 100755
index 0000000..d64a9b8
--- /dev/null
+++ b/tests/t0049-relocatable-root.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+set -eu
+base="${TMPDIR-/tmp}/mcpu-cpp-relocatable-root-$$"
+root_a="$base/mcpu-a"
+root_b="$base/mcpu-b"
+mkdir -p "$root_a/bin" "$root_a/etc" "$root_a/include/diff" "$base/home"
+trap 'rm -rf "$base"' EXIT HUP INT TERM
+
+cp "$MCPU_CPP" "$root_a/bin/mcpu-cpp"
+chmod +x "$root_a/bin/mcpu-cpp"
+
+cat > "$root_a/include/diff/relocated.h" <<'EOT'
+int relocated_header = 37;
+EOT
+
+cat > "$root_a/etc/mcpu-cpp.conf" <<'EOT'
+MCPU_CPP_RELOCATION_SENTINEL = runtime-config;
+EOT
+
+# The copied executable first derives its defaults from its new physical root.
+HOME="$base/home" "$root_a/bin/mcpu-cpp" --no-config -dsearch-dirs \
+ > "$base/root-a.search"
+grep "^search: $root_a/include/diff$" "$base/root-a.search" >/dev/null
+grep "^search: $root_a/include$" "$base/root-a.search" >/dev/null
+
+# Move the complete MCPU tree without reconfiguring or rebuilding anything.
+mv "$root_a" "$root_b"
+
+HOME="$base/home" "$root_b/bin/mcpu-cpp" --no-config -dsearch-dirs \
+ > "$base/root-b.search"
+grep "^search: $root_b/include/diff$" "$base/root-b.search" >/dev/null
+grep "^search: $root_b/include$" "$base/root-b.search" >/dev/null
+if grep "$root_a" "$base/root-b.search" >/dev/null; then
+ echo 'relocated mcpu-cpp retained its previous installation root' >&2
+ exit 1
+fi
+
+cat > "$base/main.c" <<'EOT'
+#lang "diff"
+#include <relocated.h>
+#endlang
+EOT
+HOME="$base/home" "$root_b/bin/mcpu-cpp" --no-config \
+ "$base/main.c" -o "$base/main.out"
+grep '^int relocated_header = 37;$' "$base/main.out" >/dev/null
+
+# The packaged configuration is found relative to the relocated root as well.
+HOME="$base/home" "$root_b/bin/mcpu-cpp" -dconfig > "$base/config.out"
+grep '^MCPU_CPP_RELOCATION_SENTINEL = runtime-config;$' "$base/config.out" >/dev/null
+
+# Invoking through a symbolic link must still resolve the physical executable
+# and therefore the same relocated MCPU root.
+ln -s "$root_b/bin/mcpu-cpp" "$base/mcpu-cpp"
+HOME="$base/home" "$base/mcpu-cpp" --no-config -dconfig > "$base/link.out"
+grep "^MCPU_CPP_SYSTEM_INCLUDE_PATH = $root_b/include;$" "$base/link.out" >/dev/null