unblock.pl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/perl
  2. # Exercise dd's conv=unblock mode
  3. # Copyright (C) 2009-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. use strict;
  15. (my $program_name = $0) =~ s|.*/||;
  16. # Turn off localization of executable's output.
  17. @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
  18. my $out = 'out';
  19. my @t =
  20. (
  21. # An empty test name signals that these are the arguments to use for the
  22. # following tests.
  23. ['', [qw (cbs=3 conv=unblock status=noxfer < )]],
  24. ['0', '', ''],
  25. ['1', "a\n ", "a\n\n\n"],
  26. ['2', "a\n ", "a\n\n"],
  27. ['3', "a ", "a\n"],
  28. ['4', "a \n ", "a \n\n\n"],
  29. ['5', "a \n", "a \n\n"],
  30. ['6', "a ", "a\n\n"],
  31. ['7', "a \n", "a\n\n\n"],
  32. );
  33. my @Tests;
  34. my $args;
  35. foreach my $t (@t)
  36. {
  37. $t->[0] eq ''
  38. and $args = $t->[1], next;
  39. push @Tests, [$t->[0], @$args, {IN=>$t->[1]}, {OUT=>$t->[2]},
  40. {ERR_SUBST=>'s/^\d+\+\d+ records (?:in|out)$//'},
  41. {ERR=>"\n\n"}];
  42. }
  43. my $save_temps = $ENV{DEBUG};
  44. my $verbose = $ENV{VERBOSE};
  45. my $prog = 'dd';
  46. my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
  47. exit $fail;