tap-merge.pl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #! /usr/bin/env perl
  2. # Copyright (C) 2018 Red Hat, Inc.
  3. #
  4. # Author: Paolo Bonzini <pbonzini@redhat.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. # ---------------------------------- #
  19. # Imports, static data, and setup. #
  20. # ---------------------------------- #
  21. use warnings FATAL => 'all';
  22. use strict;
  23. use Getopt::Long ();
  24. use TAP::Parser;
  25. my $ME = "tap-merge.pl";
  26. my $VERSION = "2018-11-30";
  27. my $HELP = "$ME: merge multiple TAP inputs from stdin.";
  28. use constant DIAG_STRING => "#";
  29. # ----------------- #
  30. # Option parsing. #
  31. # ----------------- #
  32. Getopt::Long::GetOptions
  33. (
  34. 'help' => sub { print $HELP; exit 0; },
  35. 'version' => sub { print "$ME $VERSION\n"; exit 0; },
  36. );
  37. # -------------- #
  38. # Subroutines. #
  39. # -------------- #
  40. sub main ()
  41. {
  42. my $iterator = TAP::Parser::Iterator::Stream->new(\*STDIN);
  43. my $parser = TAP::Parser->new ({iterator => $iterator });
  44. my $testno = 0; # Number of test results seen so far.
  45. my $bailed_out = 0; # Whether a "Bail out!" directive has been seen.
  46. STDOUT->autoflush(1);
  47. while (defined (my $cur = $parser->next))
  48. {
  49. if ($cur->is_bailout)
  50. {
  51. $bailed_out = 1;
  52. print DIAG_STRING . " " . $cur->as_string . "\n";
  53. next;
  54. }
  55. elsif ($cur->is_plan)
  56. {
  57. $bailed_out = 0;
  58. next;
  59. }
  60. elsif ($cur->is_test)
  61. {
  62. $bailed_out = 0 if $cur->number == 1;
  63. $testno++;
  64. $cur = TAP::Parser::Result::Test->new({
  65. ok => $cur->ok,
  66. test_num => $testno,
  67. directive => $cur->directive,
  68. explanation => $cur->explanation,
  69. description => $cur->description
  70. });
  71. }
  72. elsif ($cur->is_version)
  73. {
  74. next if $testno > 0;
  75. }
  76. print $cur->as_string . "\n" unless $bailed_out;
  77. }
  78. print "1..$testno\n";
  79. }
  80. # ----------- #
  81. # Main code. #
  82. # ----------- #
  83. main;
  84. # Local Variables:
  85. # perl-indent-level: 2
  86. # perl-continued-statement-offset: 2
  87. # perl-continued-brace-offset: 0
  88. # perl-brace-offset: 0
  89. # perl-brace-imaginary-offset: 0
  90. # perl-label-offset: -2
  91. # cperl-indent-level: 2
  92. # cperl-brace-offset: 0
  93. # cperl-continued-brace-offset: 0
  94. # cperl-label-offset: -2
  95. # cperl-extra-newline-before-brace: t
  96. # cperl-merge-trailing-else: nil
  97. # cperl-continued-statement-offset: 2
  98. # End: