61-test_bio_prefix.t 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #! /usr/bin/env perl
  2. # Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. use strict;
  9. use warnings;
  10. use OpenSSL::Test qw(:DEFAULT data_file);
  11. use File::Compare qw(compare_text);
  12. setup('test_bio_prefix');
  13. my %input_result = (
  14. 'in1.txt' => [ 'args1.pl', 'out1.txt' ],
  15. 'in2.txt' => [ 'args2.pl', 'out2.txt' ],
  16. );
  17. plan tests => 2 * scalar(keys %input_result);
  18. foreach (sort keys %input_result) {
  19. SKIP: {
  20. my $input_path = data_file($_);
  21. my $args_path = data_file($input_result{$_}->[0]);
  22. my $expected_path = data_file($input_result{$_}->[1]);
  23. my $result_path = "test_bio_prefix-$_-stdout";
  24. my @args = do $args_path;
  25. skip "Problem prefixing $_", 1
  26. unless ok(run(test([ 'bio_prefix_text', @args ],
  27. stdin => $input_path, stdout => $result_path)),
  28. "prefixing $_ with args " . join(' ', @args));
  29. is(compare_text($result_path, $expected_path, \&cmp_line), 0,
  30. "comparing the dump of $_ with $expected_path");
  31. }
  32. }
  33. sub cmp_line {
  34. return 0 if scalar @_ == 0;
  35. if (scalar @_ != 2) {
  36. diag "Lines to compare less than 2: ", scalar @_;
  37. return -1;
  38. }
  39. $_[0] =~ s|\R$||;
  40. $_[1] =~ s|\R$||;
  41. my $r = $_[0] cmp $_[1];
  42. diag "Lines differ:\n<: $_[0]\n>: $_[1]\n" unless $r == 0;
  43. return $r;
  44. }