| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl -w | 
| 2 | 1 |  |  | 1 |  | 143591 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 66 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 1 |  |  | 1 |  | 515 | use Test::More tests => 38; | 
|  | 1 |  |  |  |  | 15192 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 5 | 1 |  |  | 1 |  | 650 | use Test::Exception; | 
|  | 1 |  |  |  |  | 2608 |  | 
|  | 1 |  |  |  |  | 3 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 605 | use Data::Dumper; | 
|  | 1 |  |  |  |  | 6214 |  | 
|  | 1 |  |  |  |  | 49 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 297 | use lib "../lib"; | 
|  | 1 |  |  |  |  | 524 |  | 
|  | 1 |  |  |  |  | 3 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 1 |  |  | 1 |  | 68475 | use_ok("Devel::PerlySense"); | 
|  | 1 |  |  |  |  | 703 |  | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 1 | 50 |  | 1 |  | 511 | BEGIN { -d "t" and chdir("t"); } | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 1 |  |  |  |  | 269 | my $dot = "[.]"; | 
| 20 | 1 |  |  |  |  | 2 | my $up = "${dot}${dot}"; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 1 |  |  |  |  | 4 | note("Identify which file type to run"); | 
| 25 |  |  |  |  |  |  | { | 
| 26 | 1 |  |  |  |  | 55 | my $dirBase = "data/project/with-perlysenseproject"; | 
|  | 1 |  |  |  |  | 3 |  | 
| 27 | 1 |  |  |  |  | 2 | my $dirProject = "$dirBase/source"; | 
| 28 | 1 |  |  |  |  | 3 | my $dirTest = "$dirProject/bogus/t"; | 
| 29 | 1 |  |  |  |  | 1 | my $fileTest = "$dirTest/Game-Lawn.t"; | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 1 |  |  |  |  | 4 | ok( | 
| 33 |  |  |  |  |  |  | my $oPerlySense = Devel::PerlySense->new(), | 
| 34 |  |  |  |  |  |  | "New PerlySense object ok", | 
| 35 |  |  |  |  |  |  | ); | 
| 36 | 1 |  |  |  |  | 509 | ok($oPerlySense->setFindProject(file => $fileTest), "Found Project"); | 
| 37 | 1 |  |  |  |  | 224 | ok(my $oProject = $oPerlySense->oProject, "  got project property"); | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 1 |  |  |  |  | 183 | note("  Bad config formats"); | 
| 41 |  |  |  |  |  |  | { | 
| 42 | 1 |  |  |  |  | 37 | local $oProject->rhConfig->{run_file}->[0]->{rex} = undef; | 
|  | 1 |  |  |  |  | 3 |  | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | throws_ok( | 
| 45 | 1 |  |  | 1 |  | 27 | sub { $oProject->rhConfigTypeForFile( | 
| 46 |  |  |  |  |  |  | file      => $fileTest, | 
| 47 |  |  |  |  |  |  | keyConfig => "run_file", | 
| 48 |  |  |  |  |  |  | ) }, | 
| 49 | 1 |  |  |  |  | 40 | qr/Missing rex key/, | 
| 50 |  |  |  |  |  |  | "Missing regex found ok", | 
| 51 |  |  |  |  |  |  | ); | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | { | 
| 55 | 1 |  |  |  |  | 283 | local $oProject->rhConfig->{run_file}->[0]->{rex} = 'abc('; | 
|  | 1 |  |  |  |  | 4 |  | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | throws_ok( | 
| 58 | 1 |  |  | 1 |  | 17 | sub { $oProject->rhConfigTypeForFile(file => $fileTest, keyConfig => "run_file") }, | 
| 59 | 1 |  |  |  |  | 35 | qr/Invalid rex value in config/, | 
| 60 |  |  |  |  |  |  | "Invalid regex found ok", | 
| 61 |  |  |  |  |  |  | ); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | { | 
| 67 | 1 |  |  |  |  | 256 | local $oProject->rhConfig->{run_file} = []; | 
|  | 1 |  |  |  |  | 3 |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | throws_ok( | 
| 70 | 1 |  |  | 1 |  | 17 | sub { $oProject->rhConfigTypeForFile(file => $fileTest, keyConfig => "run_file") }, | 
| 71 | 1 |  |  |  |  | 34 | qr/No run_perl rex matched the/, | 
| 72 |  |  |  |  |  |  | "No matching type found ok", | 
| 73 |  |  |  |  |  |  | ); | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 1 |  |  |  |  | 195 | my $rhConfigType; | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 1 |  |  |  |  | 3 | ok($rhConfigType = $oProject->rhConfigTypeForFile(file => "abc.t", keyConfig => "run_file"), "Identify a .t file"); | 
| 80 | 1 |  |  |  |  | 185 | is($rhConfigType->{moniker}, "Test", "  correct moniker"); | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 1 |  |  |  |  | 190 | ok($rhConfigType = $oProject->rhConfigTypeForFile(file => "abc.pm", keyConfig => "run_file"), "Identify a .pm file"); | 
| 83 | 1 |  |  |  |  | 186 | is($rhConfigType->{moniker}, "Module", "  correct moniker"); | 
| 84 |  |  |  |  |  |  |  | 
| 85 | 1 |  |  |  |  | 187 | ok($rhConfigType = $oProject->rhConfigTypeForFile(file => "abc.pl", keyConfig => "run_file"), "Identify a .pl file"); | 
| 86 | 1 |  |  |  |  | 195 | is($rhConfigType->{moniker}, "Script", "  correct moniker"); | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 1 |  |  |  |  | 184 | ok($rhConfigType = $oProject->rhConfigTypeForFile(file => "abc", keyConfig => "run_file"), "Identify everything else"); | 
| 89 | 1 |  |  |  |  | 184 | is($rhConfigType->{moniker}, "Script (no .pl)", "  correct moniker"); | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 1 |  |  |  |  | 185 | note("Run test file inside dir"); | 
| 99 |  |  |  |  |  |  | { | 
| 100 |  |  |  |  |  |  | #This is to avoid identifying the .PerlySenseProject directory | 
| 101 |  |  |  |  |  |  | #_of_the_development_project_ to interfere with the test which | 
| 102 |  |  |  |  |  |  | #expects a free way all the way up to the root without any | 
| 103 |  |  |  |  |  |  | #projects. | 
| 104 | 1 |  |  | 1 |  | 36 | no warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 1878 |  | 
| 105 |  |  |  |  |  |  | local *Devel::PerlySense::Project::newFindExplicit = sub { | 
| 106 | 1 |  |  | 1 |  | 8 | undef; | 
| 107 | 1 |  |  |  |  | 4 | }; | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 1 |  |  |  |  | 2 | my $dirBase = "data/project/with-dir"; | 
| 111 | 1 |  |  |  |  | 2 | my $dirProject = "$dirBase/source"; | 
| 112 | 1 |  |  |  |  | 3 | my $dirTest = "$dirProject/t"; | 
| 113 | 1 |  |  |  |  | 2 | my $fileTest = "$dirTest/Game-Lawn.t"; | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  |  | 
| 116 | 1 |  |  |  |  | 4 | ok( | 
| 117 |  |  |  |  |  |  | my $oPerlySense = Devel::PerlySense->new(), | 
| 118 |  |  |  |  |  |  | "New PerlySense object ok", | 
| 119 |  |  |  |  |  |  | ); | 
| 120 | 1 |  |  |  |  | 185 | ok( | 
| 121 |  |  |  |  |  |  | my $rhRun = $oPerlySense->rhRunFile(file => $fileTest), | 
| 122 |  |  |  |  |  |  | "rhRunFile returned a data structure", | 
| 123 |  |  |  |  |  |  | ); | 
| 124 | 1 |  |  |  |  | 278 | is(scalar keys %$rhRun, 3, "  correct item count"); | 
| 125 | 1 |  |  |  |  | 187 | is($rhRun->{type_source_file}, "Test", "    type_source_file"); | 
| 126 | 1 |  |  |  |  | 187 | like( | 
| 127 |  |  |  |  |  |  | $rhRun->{command_run}, | 
| 128 |  |  |  |  |  |  | qr|prove --nocolor -v "-I." "-Ilib" "t.Game-Lawn.t"|, | 
| 129 |  |  |  |  |  |  | "    command_run", | 
| 130 |  |  |  |  |  |  | ); | 
| 131 | 1 |  |  |  |  | 187 | like($rhRun->{dir_run_from}, qr|t.data.project.with-dir.source|, "    dir_run_from"); | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  |  | 
| 138 | 1 |  |  |  |  | 195 | note("Run test .pm file inside dir with config"); | 
| 139 |  |  |  |  |  |  | { | 
| 140 | 1 |  |  |  |  | 45 | my $dirBase = "data/project/with-perlysenseproject"; | 
|  | 1 |  |  |  |  | 2 |  | 
| 141 | 1 |  |  |  |  | 2 | my $dirProject = "$dirBase/source"; | 
| 142 | 1 |  |  |  |  | 3 | my $dirTest = "$dirProject/bogus/t"; | 
| 143 | 1 |  |  |  |  | 2 | my $fileTest = "$dirTest/Game-Lawn.t"; | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  |  | 
| 146 | 1 |  |  |  |  | 6 | ok( | 
| 147 |  |  |  |  |  |  | my $oPerlySense = Devel::PerlySense->new(), | 
| 148 |  |  |  |  |  |  | "New PerlySense object ok", | 
| 149 |  |  |  |  |  |  | ); | 
| 150 | 1 |  |  |  |  | 188 | ok( | 
| 151 |  |  |  |  |  |  | my $rhRun = $oPerlySense->rhRunFile(file => $fileTest), | 
| 152 |  |  |  |  |  |  | "rhRunFile returned a data structure", | 
| 153 |  |  |  |  |  |  | ); | 
| 154 | 1 |  |  |  |  | 213 | is_deeply( | 
| 155 |  |  |  |  |  |  | $oPerlySense->rhConfig->{project}->{inc_dir}, | 
| 156 |  |  |  |  |  |  | [ | 
| 157 |  |  |  |  |  |  | "glib/perl5lib", | 
| 158 |  |  |  |  |  |  | "deps/perl5lib", | 
| 159 |  |  |  |  |  |  | "../../with-dir/source/lib", | 
| 160 |  |  |  |  |  |  | ], | 
| 161 |  |  |  |  |  |  | "Correct project config with inc dir found", | 
| 162 |  |  |  |  |  |  | ); | 
| 163 | 1 |  |  |  |  | 441 | is(scalar keys %$rhRun, 3, "  correct item count"); | 
| 164 | 1 |  |  |  |  | 188 | is($rhRun->{type_source_file}, "Test", "    type_source_file"); | 
| 165 | 1 |  |  |  |  | 187 | like( | 
| 166 |  |  |  |  |  |  | $rhRun->{command_run}, | 
| 167 |  |  |  |  |  |  | qr|prove -v "-Iglib.perl5lib" "-Ideps.perl5lib" "-I......with-dir.source.lib" "-I." "-Ilib" "bogus.t.Game-Lawn.t"|, | 
| 168 |  |  |  |  |  |  | "    command_run", | 
| 169 |  |  |  |  |  |  | ); | 
| 170 | 1 |  |  |  |  | 189 | like( | 
| 171 |  |  |  |  |  |  | $rhRun->{dir_run_from}, | 
| 172 |  |  |  |  |  |  | qr|project.with-perlysenseproject.source|, | 
| 173 |  |  |  |  |  |  | "    dir_run_from is project root", | 
| 174 |  |  |  |  |  |  | ); | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | } | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  |  | 
| 182 | 1 |  |  |  |  | 190 | note("Run test .pl file inside dir with config"); | 
| 183 |  |  |  |  |  |  | { | 
| 184 | 1 |  |  |  |  | 38 | my $dirBase = "data/project/with-perlysenseproject"; | 
|  | 1 |  |  |  |  | 3 |  | 
| 185 | 1 |  |  |  |  | 2 | my $dirProject = "$dirBase/source"; | 
| 186 | 1 |  |  |  |  | 2 | my $dirBin = "$dirProject/bogus/bin"; | 
| 187 | 1 |  |  |  |  | 2 | my $fileBin = "$dirBin/worms.pl"; | 
| 188 |  |  |  |  |  |  |  | 
| 189 | 1 |  |  |  |  | 7 | ok( | 
| 190 |  |  |  |  |  |  | my $oPerlySense = Devel::PerlySense->new(), | 
| 191 |  |  |  |  |  |  | "New PerlySense object ok", | 
| 192 |  |  |  |  |  |  | ); | 
| 193 | 1 |  |  |  |  | 187 | ok( | 
| 194 |  |  |  |  |  |  | my $rhRun = $oPerlySense->rhRunFile(file => $fileBin), | 
| 195 |  |  |  |  |  |  | "rhRunFile returned a data structure", | 
| 196 |  |  |  |  |  |  | ); | 
| 197 | 1 |  |  |  |  | 229 | is_deeply( | 
| 198 |  |  |  |  |  |  | $oPerlySense->rhConfig->{project}->{inc_dir}, | 
| 199 |  |  |  |  |  |  | [ | 
| 200 |  |  |  |  |  |  | "glib/perl5lib", | 
| 201 |  |  |  |  |  |  | "deps/perl5lib", | 
| 202 |  |  |  |  |  |  | "../../with-dir/source/lib", | 
| 203 |  |  |  |  |  |  | ], | 
| 204 |  |  |  |  |  |  | "Correct project config with inc dir found", | 
| 205 |  |  |  |  |  |  | ); | 
| 206 | 1 |  |  |  |  | 428 | is($rhRun->{type_source_file}, "Script", "    type_source_file"); | 
| 207 | 1 |  |  |  |  | 221 | like( | 
| 208 |  |  |  |  |  |  | $rhRun->{command_run}, | 
| 209 |  |  |  |  |  |  | qr|perl "-I${up}.${up}.glib.perl5lib" "-I${up}.${up}.deps.perl5lib" "-I${up}.${up}.${up}.${up}.with-dir.source.lib" "-I${up}.${up}" "-I${up}.${up}.lib" "worms.pl"|, | 
| 210 |  |  |  |  |  |  | "    command_run has relative paths for includes", | 
| 211 |  |  |  |  |  |  | ); | 
| 212 | 1 |  |  |  |  | 191 | like( | 
| 213 |  |  |  |  |  |  | $rhRun->{dir_run_from}, | 
| 214 |  |  |  |  |  |  | qr|project.with-perlysenseproject.source.bogus.bin|, | 
| 215 |  |  |  |  |  |  | "    dir_run_from is file dir", | 
| 216 |  |  |  |  |  |  | ); | 
| 217 |  |  |  |  |  |  |  | 
| 218 |  |  |  |  |  |  | } | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  |  | 
| 221 |  |  |  |  |  |  |  | 
| 222 |  |  |  |  |  |  |  | 
| 223 | 1 |  |  |  |  | 186 | note("Run Alernate Command test .pl file inside dir with config"); | 
| 224 |  |  |  |  |  |  | { | 
| 225 | 1 |  |  |  |  | 41 | my $dirBase = "data/project/with-perlysenseproject"; | 
|  | 1 |  |  |  |  | 2 |  | 
| 226 | 1 |  |  |  |  | 2 | my $dirProject = "$dirBase/source"; | 
| 227 | 1 |  |  |  |  | 3 | my $dirBin = "$dirProject/bogus/bin"; | 
| 228 | 1 |  |  |  |  | 1 | my $fileBin = "$dirBin/worms.pl"; | 
| 229 |  |  |  |  |  |  |  | 
| 230 | 1 |  |  |  |  | 6 | ok( | 
| 231 |  |  |  |  |  |  | my $oPerlySense = Devel::PerlySense->new(), | 
| 232 |  |  |  |  |  |  | "New PerlySense object ok", | 
| 233 |  |  |  |  |  |  | ); | 
| 234 | 1 |  |  |  |  | 186 | ok( | 
| 235 |  |  |  |  |  |  | my $rhRun = $oPerlySense->rhRunFile( | 
| 236 |  |  |  |  |  |  | file               => $fileBin, | 
| 237 |  |  |  |  |  |  | keyConfigCommand => "alternate_command", | 
| 238 |  |  |  |  |  |  | ), | 
| 239 |  |  |  |  |  |  | "rhRunFile returned a data structure with keyConfigCommand", | 
| 240 |  |  |  |  |  |  | ); | 
| 241 | 1 |  |  |  |  | 202 | is($rhRun->{type_source_file}, "Script", "    type_source_file"); | 
| 242 | 1 |  |  |  |  | 191 | like( | 
| 243 |  |  |  |  |  |  | $rhRun->{command_run}, | 
| 244 |  |  |  |  |  |  | qr|Alternate File|, | 
| 245 |  |  |  |  |  |  | "    command_run is the alternate_command one", | 
| 246 |  |  |  |  |  |  | ); | 
| 247 |  |  |  |  |  |  |  | 
| 248 |  |  |  |  |  |  | } | 
| 249 |  |  |  |  |  |  |  | 
| 250 |  |  |  |  |  |  |  | 
| 251 |  |  |  |  |  |  |  | 
| 252 |  |  |  |  |  |  |  | 
| 253 |  |  |  |  |  |  | __END__ |