File: scan-copyright.t

package info (click to toggle)
libconfig-model-dpkg-perl 3.014
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,200 kB
  • sloc: perl: 8,255; python: 242; makefile: 77; javascript: 16; sh: 1
file content (62 lines) | stat: -rw-r--r-- 1,805 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- cperl -*-
use strict;
use warnings;
use 5.020;

use Test::More;   # see done_testing()
use Path::Tiny;
use Test::File::Contents;
use Config::Model::Tester::Setup qw/init_test setup_test_dir/;
use Getopt::Long;

use feature qw/postderef signatures/;
no warnings qw/experimental::postderef experimental::signatures/;

use Dpkg::Copyright::Scanner qw/generate_copyright/;

sub check_output ($in, $out_file, $test_name, $fix, $long = 0) {
    my %from = $in->is_dir ? ( from_dir => $in ) : ( in => $in );
    my $out_text = generate_copyright( %from , quiet => 1, long => $long);

    my $success = file_contents_eq_or_diff($out_file, $out_text, { encoding => 'UTF-8' }, "check $test_name copyright");

    if ($fix and not $success) {
        print "Fix $test_name output ? (yes/no/quit) ";
        my $answer = <STDIN>;
        if ($answer =~ /^q/i) {
            exit 0;
        }
        if ($answer =~ /^y/i) {
            $out_file->spew_utf8($out_text);
        }
    }
}

my ($model, $trace, $options) = init_test("fix");

# global tests
my $dir = path('t/scanner/examples/') ;
my $suffix_re = qr/\.(in|d)$/;

foreach my $in (sort $dir->children($suffix_re)) {
    my $test_name = $in->basename($suffix_re);
    next if @ARGV and not grep { $test_name =~ /$_/; } @ARGV;
    note("scanning $test_name");

    my $out_file_name =  $test_name. '.out';
    my $out_file = $dir->child($out_file_name);
    if (not $out_file->exists) {
        # avoids breaking the test when creating a new test case
        $out_file->spew('');
    }

    check_output($in, $out_file, "$in short", $options->{fix}) ;

    my $long_out_file = $dir->child($test_name. '-long.out');
    if ($long_out_file->exists) {
        check_output($in, $long_out_file, "$in long", $options->{fix}, 1) ;
    }
}


done_testing();