Skip to content

Commit

Permalink
Output stdout from long running task
Browse files Browse the repository at this point in the history
  • Loading branch information
citizen-stig committed Sep 2, 2024
1 parent 6d3a8c1 commit 0c0b314
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,36 @@ impl Command {
shell_escape::escape(format!("Running: '{}'", self.cmd).into())
)?;

writeln!(
w,
indoc!(
r#"
check_and_output_long_running_output() {{
if [[ -n "$BASHTESTMD_LONG_RUNNING_OUTPUT" && -f "$BASHTESTMD_LONG_RUNNING_OUTPUT" ]]; then
echo "Output of the long running task:"
cat "$BASHTESTMD_LONG_RUNNING_OUTPUT"
fi
}}
"#
))?;

if self.long_running {
if let Some(wait_until) = &self.wait_until {
writeln!(
w,
indoc!(
r#"
output=$(mktemp)
{} &> $output &
long_running_output=$(mktemp)
export BASHTESTMD_LONG_RUNNING_OUTPUT=$long_running_output
{} &> $long_running_output &
background_process_pid=$!
echo "Waiting for process with PID: $background_process_pid"
until grep -q -i {} $output
do
if ! ps $background_process_pid > /dev/null
then
echo "The background process died died" >&2
echo "The background process died, output:" >&2
cat $long_running_output
exit 1
fi
echo -n "."
Expand Down Expand Up @@ -104,6 +119,7 @@ impl Command {
if ! [[ $output == *"$expected"* || $expected == *"$output"* ]]; then
echo "'$expected' not found in text:"
echo "'$output'"
check_and_output_long_running_output
exit 1
fi
"#
Expand All @@ -122,6 +138,7 @@ impl Command {
r#"
if [ $? -ne {0} ]; then
echo "Expected exit code {0}, got $?"
check_and_output_long_running_output
exit 1
fi
"#,
Expand Down

0 comments on commit 0c0b314

Please sign in to comment.