Skip to content

Commit

Permalink
Individual test directories for programs (#166)
Browse files Browse the repository at this point in the history
* Give existing program tests their own directory

* Templates for tests

* Don't load optional modules in BEGIN because it interferes with -c

* pod fix

* Use Test::Warnings instead because of done_testing sorcery

* Use done_testing because Test::Warnings handles it all

* Don't skip commands if the dir already exists

We'll skip test files if they already exist

* Use done_testing because Test::Warnings hooks into that already

* Don't load runtime stuff at compile time because it messes with -c

* Individual tests for commands

* Fix pod error

* Quotes around arguments in case they have whitespace

* Use proper argument

* Output when we add a test file

* show PERL5LIB when we debug

* Compile stuff moves to individual files, now check other things

* Rename test now that it isn't checking every file

* Add meta tests

* Add metadata

* Allow for the possibility of empty values

* Update MANIFEST
  • Loading branch information
briandfoy committed Jun 16, 2023
1 parent ede4118 commit 460169d
Show file tree
Hide file tree
Showing 393 changed files with 6,101 additions and 58 deletions.
397 changes: 382 additions & 15 deletions MANIFEST

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions bin/ar
Expand Up @@ -7,6 +7,8 @@ Description: create and maintain library archives
Author: dkulp
License: perl
=end metadata
=cut

use POSIX qw(strftime);
Expand All @@ -18,9 +20,6 @@ if ($ARGV[0] !~ /^\-/) { $ARGV[0] = '-' . $ARGV[0]; }

require "getopts.pl";
Getopts("dmpqrtxabciouv");
=end metadata
=cut

# take only one of the following major opts
if (($opt_d + $opt_m + $opt_p + $opt_q + $opt_r + $opt_t + $opt_x) != 1) {
Expand Down
2 changes: 1 addition & 1 deletion bin/awk
Expand Up @@ -17,7 +17,7 @@ License: perl

use strict;

BEGIN {
SANITY: {
my $external_module = 'App::a2p';
my $rc = eval "require $external_module; $external_module->import; 1";
die "This program needs the $external_module module.\n" unless $rc;
Expand Down
2 changes: 1 addition & 1 deletion bin/date
Expand Up @@ -346,7 +346,7 @@ please open an issue: L<https://github.com/briandfoy/PerlPowerTools/issues>.
If you look in the C<date> file, you'll see a simple text list at the end
that we use for Windows.
=se back
=back
=cut

Expand Down
4 changes: 2 additions & 2 deletions bin/mimedecode
Expand Up @@ -14,14 +14,14 @@ License:
use v5.12.0;
use Getopt::Std;

BEGIN {
SANITY: {
my $external_module = 'MIME::Parser';
my $rc = eval "require $external_module; $external_module->import; 1";
die "This program needs the $external_module module.\n" unless $rc;
}

{package PerlPowerTools::MIME::Parser;
use base 'MIME::Parser';
push @INC, 'MIME::Parser'; # this is old school so -c doesn't complain

sub new_body_for
{
Expand Down
11 changes: 11 additions & 0 deletions bin/perlpowertools
Expand Up @@ -2,6 +2,17 @@
#
# perlpowertools - helper script for PerlPowerTools

=begin metadata
Name: perlpowertools
Description: a program launcher for Perl Power Tools
Author: kal247, https://github.com/kal247
License: artistic2
=end metadata
=cut

use strict;
use warnings;
use utf8;
Expand Down
29 changes: 29 additions & 0 deletions t/000.basic.t
@@ -0,0 +1,29 @@
use Test::More 1;

use File::Basename;
use File::Spec::Functions;

my @programs =
map { basename($_) }
grep { ! /\.bat\z/ }
glob( 'blib/script/*' );

my @expected_test_files =
map { basename($_) }
glob( catfile( qw(util test_templates *.t) ) );

foreach my $program ( @programs ) {
test_dir($program);
}

done_testing();

sub test_dir {
my( $program ) = @_;
ok -d catfile( 't', $program ), "t/$program is a directory";

foreach my $t_file ( @expected_test_files ) {
ok -e catfile( 't', $program, $t_file ), "Found test file $t_file";
}
}

10 changes: 10 additions & 0 deletions t/addbib/000.basic.t
@@ -0,0 +1,10 @@
use strict;
use warnings;

use Test::More;

require './t/lib/common.pl';

sanity_test();

done_testing();
25 changes: 25 additions & 0 deletions t/addbib/910.meta.t
@@ -0,0 +1,25 @@
#!/usr/bin/perl
use strict;
use warnings;

use JSON qw(decode_json);
use Test::More;

require './t/lib/common.pl';

my $program = program_name();
ok -e $program, "$program exists";

my $output = `"$^X" util/extract_metadata $program`;
my $json = decode_json( $output );

subtest "required keys" => sub {
my $this = $json->{$program};
my @keys = qw(Name Description Author License);

ok( exists $this->{$_}, "has $_ key" ) for @keys;
};

done_testing();

__END__
10 changes: 10 additions & 0 deletions t/addbib/990.pod.t
@@ -0,0 +1,10 @@
#!/usr/bin/perl

use Test::Pod;

require './t/lib/common.pl';
my $program = program_name(__FILE__);

pod_file_ok( $program, "Valid POD in <$program>" );

done_testing();
10 changes: 10 additions & 0 deletions t/apply/000.basic.t
@@ -0,0 +1,10 @@
use strict;
use warnings;

use Test::More;

require './t/lib/common.pl';

sanity_test();

done_testing();
25 changes: 25 additions & 0 deletions t/apply/910.meta.t
@@ -0,0 +1,25 @@
#!/usr/bin/perl
use strict;
use warnings;

use JSON qw(decode_json);
use Test::More;

require './t/lib/common.pl';

my $program = program_name();
ok -e $program, "$program exists";

my $output = `"$^X" util/extract_metadata $program`;
my $json = decode_json( $output );

subtest "required keys" => sub {
my $this = $json->{$program};
my @keys = qw(Name Description Author License);

ok( exists $this->{$_}, "has $_ key" ) for @keys;
};

done_testing();

__END__
10 changes: 10 additions & 0 deletions t/apply/990.pod.t
@@ -0,0 +1,10 @@
#!/usr/bin/perl

use Test::Pod;

require './t/lib/common.pl';
my $program = program_name(__FILE__);

pod_file_ok( $program, "Valid POD in <$program>" );

done_testing();
10 changes: 10 additions & 0 deletions t/ar/000.basic.t
@@ -0,0 +1,10 @@
use strict;
use warnings;

use Test::More;

require './t/lib/common.pl';

sanity_test();

done_testing();
25 changes: 25 additions & 0 deletions t/ar/910.meta.t
@@ -0,0 +1,25 @@
#!/usr/bin/perl
use strict;
use warnings;

use JSON qw(decode_json);
use Test::More;

require './t/lib/common.pl';

my $program = program_name();
ok -e $program, "$program exists";

my $output = `"$^X" util/extract_metadata $program`;
my $json = decode_json( $output );

subtest "required keys" => sub {
my $this = $json->{$program};
my @keys = qw(Name Description Author License);

ok( exists $this->{$_}, "has $_ key" ) for @keys;
};

done_testing();

__END__
10 changes: 10 additions & 0 deletions t/ar/990.pod.t
@@ -0,0 +1,10 @@
#!/usr/bin/perl

use Test::Pod;

require './t/lib/common.pl';
my $program = program_name(__FILE__);

pod_file_ok( $program, "Valid POD in <$program>" );

done_testing();
10 changes: 10 additions & 0 deletions t/arch/000.basic.t
@@ -0,0 +1,10 @@
use strict;
use warnings;

use Test::More;

require './t/lib/common.pl';

sanity_test();

done_testing();
25 changes: 25 additions & 0 deletions t/arch/910.meta.t
@@ -0,0 +1,25 @@
#!/usr/bin/perl
use strict;
use warnings;

use JSON qw(decode_json);
use Test::More;

require './t/lib/common.pl';

my $program = program_name();
ok -e $program, "$program exists";

my $output = `"$^X" util/extract_metadata $program`;
my $json = decode_json( $output );

subtest "required keys" => sub {
my $this = $json->{$program};
my @keys = qw(Name Description Author License);

ok( exists $this->{$_}, "has $_ key" ) for @keys;
};

done_testing();

__END__
10 changes: 10 additions & 0 deletions t/arch/990.pod.t
@@ -0,0 +1,10 @@
#!/usr/bin/perl

use Test::Pod;

require './t/lib/common.pl';
my $program = program_name(__FILE__);

pod_file_ok( $program, "Valid POD in <$program>" );

done_testing();
10 changes: 10 additions & 0 deletions t/arithmetic/000.basic.t
@@ -0,0 +1,10 @@
use strict;
use warnings;

use Test::More;

require './t/lib/common.pl';

sanity_test();

done_testing();
25 changes: 25 additions & 0 deletions t/arithmetic/910.meta.t
@@ -0,0 +1,25 @@
#!/usr/bin/perl
use strict;
use warnings;

use JSON qw(decode_json);
use Test::More;

require './t/lib/common.pl';

my $program = program_name();
ok -e $program, "$program exists";

my $output = `"$^X" util/extract_metadata $program`;
my $json = decode_json( $output );

subtest "required keys" => sub {
my $this = $json->{$program};
my @keys = qw(Name Description Author License);

ok( exists $this->{$_}, "has $_ key" ) for @keys;
};

done_testing();

__END__
10 changes: 10 additions & 0 deletions t/arithmetic/990.pod.t
@@ -0,0 +1,10 @@
#!/usr/bin/perl

use Test::Pod;

require './t/lib/common.pl';
my $program = program_name(__FILE__);

pod_file_ok( $program, "Valid POD in <$program>" );

done_testing();
10 changes: 10 additions & 0 deletions t/asa/000.basic.t
@@ -0,0 +1,10 @@
use strict;
use warnings;

use Test::More;

require './t/lib/common.pl';

sanity_test();

done_testing();
25 changes: 25 additions & 0 deletions t/asa/910.meta.t
@@ -0,0 +1,25 @@
#!/usr/bin/perl
use strict;
use warnings;

use JSON qw(decode_json);
use Test::More;

require './t/lib/common.pl';

my $program = program_name();
ok -e $program, "$program exists";

my $output = `"$^X" util/extract_metadata $program`;
my $json = decode_json( $output );

subtest "required keys" => sub {
my $this = $json->{$program};
my @keys = qw(Name Description Author License);

ok( exists $this->{$_}, "has $_ key" ) for @keys;
};

done_testing();

__END__
10 changes: 10 additions & 0 deletions t/asa/990.pod.t
@@ -0,0 +1,10 @@
#!/usr/bin/perl

use Test::Pod;

require './t/lib/common.pl';
my $program = program_name(__FILE__);

pod_file_ok( $program, "Valid POD in <$program>" );

done_testing();

0 comments on commit 460169d

Please sign in to comment.