Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdstream support #168

Merged
merged 9 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test/stdstream.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

TRY_TOP="${TRY_TOP:-$(git rev-parse --show-toplevel --show-superproject-working-tree 2>/dev/null || echo "${0%/*}")}"
TRY="$TRY_TOP/try"

cmdfile="$(mktemp)"

cat > "$cmdfile" <<'EOF'
read x < /dev/stdin
ezrizhu marked this conversation as resolved.
Show resolved Hide resolved
echo $((x * 2)) > /dev/stdout
echo $((x * 3)) > /dev/stderr

EOF

chmod +x "$cmdfile"

# test stdout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not test for exact output from both at once by capturing output in mktemped files?

result=$(echo 5 | "$TRY" "$cmdfile" 2>/dev/null)
expected=$(echo 5 | sh "$cmdfile" 2>/dev/null)

[ "$result" = "$expected" ] || exit 1

# test stdout + stderr
result=$(echo 5 | "$TRY" "$cmdfile" 2>&1)

# using grep because stdout also includes try err/warns
echo "$result" | grep 15 > /dev/null
7 changes: 7 additions & 0 deletions try
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ unshare --root="$SANDBOX_DIR/temproot" /bin/sh "$chroot_executable"
exitcode="$?"

# unmount the devices
rm "$sandbox_dir/temproot/dev/stdin"
rm "$sandbox_dir/temproot/dev/stdout"
rm "$sandbox_dir/temproot/dev/stderr"

unmount_devices "$SANDBOX_DIR"

exit $exitcode
Expand All @@ -262,6 +266,9 @@ unset START_DIR SANDBOX_DIR UNION_HELPER DIRS_AND_MOUNTS TRY_EXIT_STATUS
unset script_to_execute chroot_executable try_mount_log

mount -t proc proc /proc &&
ln -s /proc/self/fd/0 /dev/stdin &&
ezrizhu marked this conversation as resolved.
Show resolved Hide resolved
ln -s /proc/self/fd/1 /dev/stdout &&
ln -s /proc/self/fd/2 /dev/stderr &&
cd "$START_DIR" &&
ezrizhu marked this conversation as resolved.
Show resolved Hide resolved
. "$script_to_execute"
EOF
Expand Down
Loading