XOG/Command/selftest.pm

filter: Statementstmt 88.8% 16 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.6% 22 / 24 CC 1 SCAR 0.5
CC
1
Cov
89%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« XOG/Merge.pm ↑ Summary XOG/Cargo/Test/PS.pm »
1 package Clarity::XOG::Command::selftest;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Test::Deep;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Clarity::XOG -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 0 ▶use Clarity::XOG::Merge;
Subroutine BEGIN: called CC=1 SCAR=2.6
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__
« XOG/Merge.pm ↑ Summary XOG/Cargo/Test/PS.pm »