From 45371e38949c63a14570a6d69ee0302d70cd48e1 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 13 Mar 2021 05:05:34 +0100 Subject: [PATCH] test return status of example commands and pipes Explicitly run with bash so intermediate failure can be detected using the pipefail option. --- t/examples.t | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/t/examples.t b/t/examples.t index cd7f1b3..02019b9 100755 --- a/t/examples.t +++ b/t/examples.t @@ -15,18 +15,26 @@ open my $input, '<', $filename local $/ = "\n\n"; while (readline $input) { + # find code snippets in the appropriate section /^=head1 EXAMPLES/ ... /^=head1/ or next; /^\h/ or next; chomp; my ($name) = /[\h(]*([^|]+)/; + # prepare shell command to execute my $cmd = $_; while (my ($subcmd, $args) = each %CMDARGS) { $subcmd .= " \\K", $args .= ' ' unless $subcmd =~ m/\\K/; $cmd =~ s/\b$subcmd/$args/; } - ok(qx($cmd), $name); + $cmd =~ s/'/'\\''/g, $cmd = "bash -c 'set -o pipefail\n$cmd'"; + + # run and report unexpected results + ok(eval { + qx($cmd) or return; + return $? == 0; + }, $name); } done_testing(); -- 2.30.0