File Coverage

blib/lib/Clarity/XOG/Command/selftest.pm
Criterion Covered Total %
statement 16 18 88.8
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 24 91.6


line stmt bran cond sub pod time code
1             package Clarity::XOG::Command::selftest;
2              
3 1     1   768 use strict;
  1         2  
  1         34  
4 1     1   5 use warnings;
  1         2  
  1         25  
5              
6 1     1   1375 use Test::More;
  1         23701  
  1         15  
7 1     1   1901 use Test::Deep;
  1         15578  
  1         332  
8 1     1   788 use Clarity::XOG -command;
  1         5  
  1         13  
9 1     1   5946 use Clarity::XOG::Merge;
  0            
  0            
10              
11             use File::Temp qw(tempfile tempdir);
12              
13             # ----- evaluate result -----
14             my $counter_Resource = 0;
15             my $counter_Project = 0;
16             my $counter_CustomInformation = 0;
17             my @projects = ();
18              
19             sub abstract { "built-in self test" }
20              
21             sub description {
22              
23             "Built-in self test.
24              
25             Merge some self-contained dummy xml files into a temporary result file
26             and executes plausibility checks.
27              
28             This is to check for general working, like XML parsing, create and
29             cleanup temp files, etc.
30              
31             Expected output is some 'ok' lines and number of tests, eg. '1..4'."}
32              
33             sub cb_Resource {
34             $counter_Resource++;
35             }
36              
37             sub cb_Project {
38             my ($t, $project) = @_;
39              
40             my $projectID = $project->att('projectID');
41             my $name = $project->att('name');
42              
43             $counter_Project++;
44             push @projects, { projectID => $projectID,
45             name => $name };
46             }
47              
48             sub cb_CustomInformation {
49             $counter_CustomInformation++;
50             }
51              
52             use Clarity::XOG::Cargo::Test::QA;
53             use Clarity::XOG::Cargo::Test::PS;
54             use Clarity::XOG::Cargo::Test::TJ;
55              
56             sub prepare_srcdir {
57             my $srcdir = tempdir( CLEANUP => 1 );
58              
59             my $file_QA = "$srcdir/QA.xml";
60             my $file_PS = "$srcdir/PS.xml";
61             my $file_TJ = "$srcdir/TJ.xml";
62              
63             open TESTDATA, ">", $file_QA or die "Can not write to $file_QA";
64             print TESTDATA $_ while <Clarity::XOG::Cargo::Test::QA::DATA>;
65             close TESTDATA;
66              
67             open TESTDATA, ">", $file_PS or die "Can not write to $file_PS";
68             print TESTDATA $_ while <Clarity::XOG::Cargo::Test::PS::DATA>;
69             close TESTDATA;
70              
71             open TESTDATA, ">", $file_TJ or die "Can not write to $file_TJ";
72             print TESTDATA $_ while <Clarity::XOG::Cargo::Test::TJ::DATA>;
73             close TESTDATA;
74              
75             return $srcdir;
76             }
77              
78             sub execute {
79             my $srcdir = prepare_srcdir;
80             my $tmpdir = tempdir( CLEANUP => 1 );
81             my $out_file = "$tmpdir/tmp_OUTFILE.xml";
82             my $merger = Clarity::XOG::Merge->new( files => ["$srcdir/QA.xml",
83             "$srcdir/PS.xml",
84             "$srcdir/TJ.xml"],
85             out_file => $out_file
86             );
87             $merger->Main;
88             my $twig= XML::Twig->new ( twig_handlers => {
89             Project => \&cb_Project,
90             Resource => \&cb_Resource,
91             CustomInformation => \&cb_CustomInformation,
92             },
93             );
94             $twig->parsefile( $out_file );
95             is($counter_Resource, 14, "count result Resource elements");
96              
97             my @expected_projects = ( { projectID => "PRJ-300330", name => "KRAM Testing" },
98             { projectID => "PRJ-200220", name => "Turbo Basic" },
99             { projectID => "PRJ-100224", name => "Eidolon" },
100             { projectID => "PRJ-100222", name => "International Karate" },
101             { projectID => "PRJ-100223", name => "Birne" }, );
102              
103             is($counter_Project, 5, "count result Project elements");
104             cmp_bag(\@projects, \@expected_projects, "expected project elements");
105              
106             is($counter_CustomInformation, $counter_Project, "have as many CustomInformation as Project elements");
107             done_testing();
108             }
109              
110             1;
111              
112             __END__
113              
114             =pod
115              
116             =head1 NAME
117              
118             Clarity::XOG::Command::selftest - xogtool subcommand 'selftest'
119              
120             =head1 ABOUT
121              
122             This is the class for C<xogtool selftest>. It runs a self-test, useful
123             if the developer needs information from a user who has problems with
124             the tool.
125              
126             See also L<xogtool|xogtool> for details.
127              
128             =head1 AUTHOR
129              
130             Steffen Schwigon, C<< <ss5 at renormalist.net> >>
131              
132             =head1 BUGS
133              
134             Please report any bugs or feature requests to C<bug-clarity-xog-merge
135             at rt.cpan.org>, or through the web interface at
136             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Clarity-XOG-Merge>. I
137             will be notified, and then you'll automatically be notified of
138             progress on your bug as I make changes.
139              
140             =head1 COPYRIGHT & LICENSE
141              
142             Copyright 2010-2011 Steffen Schwigon, all rights reserved.
143              
144             This program is free software; you can redistribute it and/or modify
145             it under the same terms as Perl itself.
146              
147             =cut