From 4e90ca1cdb700d69875e2129a965a48841506ff8 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 27 Sep 2015 18:16:43 +0200 Subject: [PATCH] [tesh] reduce the uglyness of that code a bit MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Write "if (cond) {A} else {B}" instead of "if (!cond) {B} else {A}" or "unless(cond) {B} else {A}" - Kill some dead code - Other tiny cleanups There still a lot to do to make it nice to read :( --- tools/tesh/tesh.pl | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/tools/tesh/tesh.pl b/tools/tesh/tesh.pl index 7e16cf8ffa..d55db79e8b 100755 --- a/tools/tesh/tesh.pl +++ b/tools/tesh/tesh.pl @@ -110,8 +110,6 @@ sub cd_cmd { print "Chdir to $directory failed: No such file or directory\n"; } if($failure==1){ - $error=1; - $exitcode=4; print "Test suite `$tesh_file': NOK (system error)\n"; exit 4; } @@ -175,13 +173,13 @@ sub get_options { print "New tesh: $diff_tool_tmp_filename\n"; } - unless($tesh_file=~/(.*)\.tesh/){ + if ($tesh_file =~ m/(.*)\.tesh/) { + $tesh_name=$1; + print "Test suite `$tesh_name'\n"; + } else { $tesh_file="(stdin)"; $tesh_name="(stdin)"; print "Test suite from stdin\n"; - }else{ - $tesh_name=$1; - print "Test suite `$tesh_name'\n"; } foreach (@cfg) { @@ -389,14 +387,13 @@ sub parse_out { # Check the result of execution ### my $diff; - if (defined($cmd{'output display'})){ + if (defined($cmd{'output display'})) { print "[Tesh/INFO] Here is the (ignored) command output:\n"; - map { print "||$_\n" } @got; - } - elsif (!defined($cmd{'output ignore'})){ - $diff = build_diff(\@{$cmd{'out'}}, \@got); - }else{ + map { print "||$_\n" } @got; + } elsif (defined($cmd{'output ignore'})) { print "(ignoring the output of <$cmd{'file'}:$cmd{'line'}> as requested)\n" + } else { + $diff = build_diff(\@{$cmd{'out'}}, \@got); } if (length $diff) { print "Output of <$cmd{'file'}:$cmd{'line'}> mismatch".($cmd{'sort'}?" (even after sorting)":"").":\n"; @@ -412,8 +409,7 @@ sub parse_out { } print "Test suite `$cmd{'file'}': NOK (<$cmd{'file'}:$cmd{'line'}> output mismatch)\n"; - $error=1; - $exitcode=2; + exit 2; } } @@ -435,7 +431,7 @@ if($tesh_file eq "(stdin)"){ $infh = *STDIN; } else { open $infh, $tesh_file - or die "[Tesh/CRITICAL] Unable to open $tesh_file $!\n"; + or die "[Tesh/CRITICAL] Unable to open $tesh_file: $!\n"; } my %cmd; # everything about the next command to run @@ -631,11 +627,11 @@ if ($diff_tool) { unlink $diff_tool_tmp_filename; } -if($error !=0){ +if ($error !=0){ exit $exitcode; -}elsif($tesh_file eq "(stdin)"){ +} elsif($tesh_file eq "(stdin)") { print "Test suite from stdin OK\n"; -}else{ +} else { print "Test suite `$tesh_name' OK\n"; } -- 2.20.1