File: 35patch.t

package info (click to toggle)
libparse-debcontrol-perl 2.005-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 384 kB
  • sloc: perl: 910; makefile: 2
file content (95 lines) | stat: -rw-r--r-- 3,568 bytes parent folder | download | duplicates (4)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#
#===============================================================================
#
#         FILE:  35patch.t
#
#  DESCRIPTION:
#
#        FILES:  ---
#         BUGS:  ---
#        NOTES:  ---
#       AUTHOR:   (), <>
#      COMPANY:
#      VERSION:  1.0
#      CREATED:  2009-11-29 19.13.10 CET
#     REVISION:  ---
#===============================================================================

use strict;
use warnings;

use Test::More tests => 31;                      # last test to print
use Test::Exception;

BEGIN {
    chdir 't' if -d 't';
    use lib '../blib/lib', 'lib/', '..';
}

my $pdc;
my $data;

#Object initialization - 2 tests

BEGIN { use_ok( 'Parse::DebControl::Patch' ) };
ok($pdc = new Parse::DebControl::Patch(), "Parser object creation works fine");

#Parse file - 1 test
lives_ok ( sub {
        $data = $pdc->parse_file( 'testfiles/patch1.diff' )
    }, "Parsed patch ok");

# Check From - 3 tests
ok(  exists $data->{From}->[0], "Exists first From field");
is( $data->{From}->[0], "Ulrich Drepper <drepper\@redhat.com>", "Single From field");
ok( ! exists $data->{From}->[1], "No second From field");

# Check Subject - 5 tests
ok( exists $data->{Subject}->[0], "Exists first Subject field");
ok( exists $data->{Subject}->[1], "Exists second Subject field");
is( $data->{Subject}->[0], "Fix regex problems with some multi-bytes characters", "First paragraph of Subject");
is( $data->{Subject}->[1],
    "* posix/bug-regex17.c: Add testcases.\n".
    "* posix/regcomp.c (re_compile_fastmap_iter): Rewrite COMPLEX_BRACKET\n".
    "  handling.", "Second paragraph of Subject"
);
ok( ! exists $data->{Subject}->[2], "No third Subject field");

# Check Origin - 3 tests
ok( exists $data->{Origin}->[0], "Exists first Origin field");
is( $data->{Origin}->[0], "upstream, http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=bdb56bac", "Single Origin address");
ok( ! exists $data->{Origin}->[1], "No second Origin field");

# Check Bug - 3 tests
ok( exists $data->{Bug}->[0], "Exists first Bug field");
is( $data->{Bug}->[0], "http://sourceware.org/bugzilla/show_bug.cgi?id=9697", "Single Bug field");
ok( ! exists $data->{Bug}->[1], "No second Bug field");

# Check Bug-Debian - 3 tests
ok( exists $data->{"Bug-Debian"}->[0], "Exists first Bug-Debian field");
is( $data->{"Bug-Debian"}->[0], "http://bugs.debian.org/510219", "Single Bug-Debian field");
ok( ! exists $data->{"Bug-Debian"}->[1], "No second Bug-Debian field");

# Check if the Forwarded field is set and is set to true - 3 tests
# Test file doesn't include a forwared field, so it should default to true
ok( exists $data->{Forwarded}, "Exists Forwarded field");
ok( $data->{Forwarded}, "Forwarded is true");
is( $data->{Forwarded}, 'yes', "Forwarded is set to \"yes\"");

#Parse file - 1 test
lives_ok ( sub {
        $data = $pdc->parse_file( 'testfiles/patch2.diff' )
    }, "Parsed patch2 ok");
# Check if the Forwarded field is set and is set to false - 3 tests
ok( exists $data->{Forwarded}, "Exists Forwarded field");
ok( !$data->{Forwarded}, "Forwarded is false");
is( $data->{Forwarded}, 'not-needed', "Forwarded is set to \"not-needed\"");

#Parse file - 1 test
lives_ok ( sub {
        $data = $pdc->parse_file( 'testfiles/patch3.diff' )
    }, "Parsed patch3 ok");
# Check if the Forwarded field is set and is set to true - 3 tests
ok( exists $data->{Forwarded}, "Exists Forwarded field");
ok( $data->{Forwarded}, "Forwarded is true");
is( $data->{Forwarded}, 'http://www.example.com/patches?id=42', "Forwarded is set to \"http://www.example.com/patches?id=42\"");