diff --git a/test/process_substitution.sh b/test/process_substitution.sh new file mode 100755 index 00000000..4dabec48 --- /dev/null +++ b/test/process_substitution.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +TRY_TOP="${TRY_TOP:-$(git rev-parse --show-toplevel --show-superproject-working-tree 2>/dev/null || echo "${0%/*}")}" +TRY="$TRY_TOP/try" + +cleanup() { + cd / + + if [ -d "$try_workspace" ] + then + rm -rf "$try_workspace" >/dev/null 2>&1 + fi +} + +trap 'cleanup' EXIT + +if ! command -v bash >/dev/null 2>&1 +then + exit 0 +fi + +try_workspace="$(mktemp -d)" +cd "$try_workspace" || exit 9 + +TRY_SHELL="$(command -v bash)" \ + "$TRY" -n 'diff <(printf "alpha\n") <(printf "alpha\n")' || exit 1 diff --git a/test/process_substitution_D_flag.sh b/test/process_substitution_D_flag.sh new file mode 100755 index 00000000..56b1d78c --- /dev/null +++ b/test/process_substitution_D_flag.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +TRY_TOP="${TRY_TOP:-$(git rev-parse --show-toplevel --show-superproject-working-tree 2>/dev/null || echo "${0%/*}")}" +TRY="$TRY_TOP/try" + +cleanup() { + cd / + + if [ -d "$try_workspace" ] + then + rm -rf "$try_workspace" >/dev/null 2>&1 + fi + + if [ -d "$try_sandbox" ] + then + rm -rf "$try_sandbox" >/dev/null 2>&1 + fi +} + +trap 'cleanup' EXIT + +if ! command -v bash >/dev/null 2>&1 +then + exit 0 +fi + +try_workspace="$(mktemp -d)" +try_sandbox="$(mktemp -d)" +cd "$try_workspace" || exit 9 + +TRY_SHELL="$(command -v bash)" \ + "$TRY" -D "$try_sandbox" 'diff <(printf "alpha\n") <(printf "alpha\n")' || exit 1 diff --git a/try b/try index 4aedd742..5c4b2ee2 100755 --- a/try +++ b/try @@ -168,6 +168,7 @@ devices_to_mount="tty null zero full random urandom" ## Mounts and unmounts a few select devices instead of the whole `/dev` mount_devices() { sandbox_dir="$1" + mkdir -p "$sandbox_dir/temproot/dev" "$sandbox_dir/temproot/dev/pts" for dev in $devices_to_mount do touch "$sandbox_dir/temproot/dev/$dev" @@ -272,6 +273,8 @@ exitcode="$?" rm "$sandbox_dir/temproot/dev/stdin" rm "$sandbox_dir/temproot/dev/stdout" rm "$sandbox_dir/temproot/dev/stderr" +rm "$sandbox_dir/temproot/dev/fd" +rm "$sandbox_dir/temproot/dev/ptmx" unmount_devices "$SANDBOX_DIR" @@ -285,7 +288,10 @@ EOF unset START_DIR SANDBOX_DIR UNION_HELPER DIRS_AND_MOUNTS TRY_EXIT_STATUS TRY_COMMAND TRY_SHELL UPDATED_DIRS_AND_MOUNTS unset script_to_execute chroot_executable try_mount_log +mount -t devpts devpts /dev/pts -o newinstance,ptmxmode=0666,mode=0620,gid=$(getent group tty | cut -d: -f3 || echo 5) 2>/dev/null && +[ -e /dev/ptmx ] || ln -s /dev/pts/ptmx /dev/ptmx && mount -t proc proc /proc && +ln -s /proc/self/fd /dev/fd && ln -s /proc/self/fd/0 /dev/stdin && ln -s /proc/self/fd/1 /dev/stdout && ln -s /proc/self/fd/2 /dev/stderr &&