xref: /openbsd/gnu/usr.bin/perl/cpan/CPAN-Meta-YAML/t/tml (revision b8851fcc)
16fb12b70Safresh1#!/usr/bin/env perl
26fb12b70Safresh1use strict;
36fb12b70Safresh1use warnings;
46fb12b70Safresh1use lib 'lib', 't/lib/';
5*b8851fccSafresh1use Test::More 0.88;
6*b8851fccSafresh1use SubtestCompat;
76fb12b70Safresh1use Getopt::Long qw/:config passthrough/;
86fb12b70Safresh1use List::Util qw/first/;
96fb12b70Safresh1use TestBridge;
106fb12b70Safresh1use TestUtils;
116fb12b70Safresh1
126fb12b70Safresh1#--------------------------------------------------------------------------#
136fb12b70Safresh1# Note: This program is both the proxy to select .tml files for 'prove' and the
146fb12b70Safresh1# test-runner that 'prove' executes.
156fb12b70Safresh1#--------------------------------------------------------------------------#
166fb12b70Safresh1
176fb12b70Safresh1# match path prefix under t/
186fb12b70Safresh1my %BRIDGE_MAP = (
196fb12b70Safresh1    'tml-local/dump-error'      => \&test_dump_error,
206fb12b70Safresh1    'tml-local/load-error'      => \&test_load_error,
21*b8851fccSafresh1    'tml-local/load-warning'    => \&test_load_warning,
226fb12b70Safresh1    'tml-local/perl-to-yaml'    => \&test_perl_to_yaml,
236fb12b70Safresh1    'tml-local/yaml-roundtrip'  => \&test_yaml_roundtrip,
246fb12b70Safresh1    'tml-spec/basic-data.tml'   => \&test_yaml_json,
256fb12b70Safresh1    'tml-spec/unicode.tml'      => \&test_code_point,
266fb12b70Safresh1    'tml-world'                 => \&test_yaml_roundtrip,
276fb12b70Safresh1);
286fb12b70Safresh1
296fb12b70Safresh1sub main {
306fb12b70Safresh1    my ($verbose, $run_tests);
316fb12b70Safresh1    GetOptions(
326fb12b70Safresh1        'run_test' => \$run_tests,
336fb12b70Safresh1    );
346fb12b70Safresh1
356fb12b70Safresh1    if ( $run_tests ) {
366fb12b70Safresh1        my $file = shift @ARGV;
376fb12b70Safresh1        exit 0 unless -f $file;
386fb12b70Safresh1        my ($bridge) = first { $file =~ m{^t/\Q$_} } keys %BRIDGE_MAP;
396fb12b70Safresh1        die "No bridge found for $file" unless $bridge;
406fb12b70Safresh1
416fb12b70Safresh1        run_testml_file(
426fb12b70Safresh1            $file,
436fb12b70Safresh1            sub {
446fb12b70Safresh1                my ($file, $blocks) = @_;
456fb12b70Safresh1                subtest "TestML dev runner: $file" => sub {
466fb12b70Safresh1                    $BRIDGE_MAP{$bridge}->($_) for @$blocks;
476fb12b70Safresh1                };
486fb12b70Safresh1                done_testing;
496fb12b70Safresh1            },
506fb12b70Safresh1        );
516fb12b70Safresh1    }
526fb12b70Safresh1    else {
536fb12b70Safresh1        my (@opts, @files, @patterns);
546fb12b70Safresh1        for (@ARGV) {
556fb12b70Safresh1            if ( /^-/ ) {
566fb12b70Safresh1                push @opts, $_;
576fb12b70Safresh1            }
586fb12b70Safresh1            elsif ( -f ) {
596fb12b70Safresh1                push @files, $_;
606fb12b70Safresh1            }
616fb12b70Safresh1            else {
626fb12b70Safresh1                push @patterns, $_;
636fb12b70Safresh1            }
646fb12b70Safresh1        }
656fb12b70Safresh1
666fb12b70Safresh1        # if we got no files or patterns, treat that as taking anything
676fb12b70Safresh1        @patterns = "." if !@patterns && !@files;
686fb12b70Safresh1
696fb12b70Safresh1        if (@patterns) {
706fb12b70Safresh1            FILE: for my $file ( find_tml_files('t') ) {
716fb12b70Safresh1                if ( first { $file =~ /$_/ } @patterns ) {
726fb12b70Safresh1                        push @files, $file;
736fb12b70Safresh1                }
746fb12b70Safresh1            }
756fb12b70Safresh1        }
766fb12b70Safresh1
776fb12b70Safresh1        exec( 'prove', @opts, '--exec', "$0 --run_test", @files )
786fb12b70Safresh1            if @files;
796fb12b70Safresh1    }
806fb12b70Safresh1}
816fb12b70Safresh1
826fb12b70Safresh1main;
836fb12b70Safresh1
846fb12b70Safresh1__END__
856fb12b70Safresh1
866fb12b70Safresh1=head1 NAME
876fb12b70Safresh1
886fb12b70Safresh1t/tml - run .tml files matching a pattern
896fb12b70Safresh1
906fb12b70Safresh1=head1 SYNOPSIS
916fb12b70Safresh1
926fb12b70Safresh1    t/tml [prove options] [patterns]
936fb12b70Safresh1
946fb12b70Safresh1=head1 USAGE
956fb12b70Safresh1
966fb12b70Safresh1This program runs F<prove> against a set of F<.tml> files using their
976fb12b70Safresh1corresponding test bridge functions.
986fb12b70Safresh1
996fb12b70Safresh1Any arguments beginning with C<-> will be passed through to F<prove>.  All
1006fb12b70Safresh1other arguments will be used as patterns to select F<.tml> files found anywhere
1016fb12b70Safresh1under the F<t> directory.  You can use shell globbing syntax, and let the shell
1026fb12b70Safresh1expand the patterns, or you can quote/escape the patterns and let them be
1036fb12b70Safresh1treated as Perl regular expressions.
1046fb12b70Safresh1
1056fb12b70Safresh1For example:
1066fb12b70Safresh1
1076fb12b70Safresh1    t/tml unicode       # paths matching qr/unicode/
1086fb12b70Safresh1    t/tml basic uni     # paths matching qr/basic/ or qr/uni/
1096fb12b70Safresh1    t/tml 'local.*re'   # paths matching qr/local.*re/
1106fb12b70Safresh1    t/tml '\d+'         # paths matching qr/\d+/
1116fb12b70Safresh1
1126fb12b70Safresh1Examples of options for prove:
1136fb12b70Safresh1
1146fb12b70Safresh1    t/tml -v quoting    # verbose run of paths matching qr/quoting/
1156fb12b70Safresh1    t/tml -j9 world     # parallel run of paths matching qr/world/
1166fb12b70Safresh1    t/tml -j9           # parallel run of all .tml files
1176fb12b70Safresh1
1186fb12b70Safresh1=cut
119