1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-01-22 14:45:27 +00:00
nixpkgs/pkgs/build-support/setup-hooks/patch-rc-path-hooks/test/test-sourcing-bash
Shamrock Lee da31bd5673 patchRcPathBash, patchRcPathCsh, patchRcPathFish, patchRcPathPosix: init
Init patchRcPath hooks, which provides
utilities to patch shell scripts to be sourced by users.

Add test cases and documentation.
2022-11-10 09:23:52 +08:00

22 lines
592 B
Bash

#!/usr/bin/env bash
set -eu -o pipefail
UNPATCHED_SOURCE_FILE="$1"
PATCHED_SOURCE_FILE="$2"
ORIG_PATH="$PWD/alfa:$PWD/bravo"
RESULT_PATH_FROM_UNPATCHED="$(
PATH="$ORIG_PATH"; export PATH
. "$UNPATCHED_SOURCE_FILE"
echo "$PATH"
)"
RESULT_PATH_FROM_PATCHED="$(
PATH="$ORIG_PATH"; export PATH
. "$PATCHED_SOURCE_FILE"
echo "$PATH"
)"
if [[ "$RESULT_PATH_FROM_UNPATCHED" != "$RESULT_PATH_FROM_PATCHED" ]]; then
echo "Result path mismatched: $UNPATCHED_SOURCE_FILE ($RESULT_PATH_FROM_UNPATCHED) and $PATCHED_SOURCE_FILE ($RESULT_PATH_FROM_PATCHED)" >&2
exit 1
fi