xref: /openbsd/gnu/usr.bin/perl/cpan/CPAN-Meta-YAML/t/tml (revision d415bd75)
1#!/usr/bin/env perl
2use strict;
3use warnings;
4use lib 'lib', 't/lib/';
5use Test::More 0.88;
6use SubtestCompat;
7use Getopt::Long qw/:config passthrough/;
8use List::Util qw/first/;
9use TestBridge;
10use TestUtils;
11
12#--------------------------------------------------------------------------#
13# Note: This program is both the proxy to select .tml files for 'prove' and the
14# test-runner that 'prove' executes.
15#--------------------------------------------------------------------------#
16
17# match path prefix under t/
18my %BRIDGE_MAP = (
19    'tml-local/dump-error'      => \&test_dump_error,
20    'tml-local/load-error'      => \&test_load_error,
21    'tml-local/load-warning'    => \&test_load_warning,
22    'tml-local/perl-to-yaml'    => \&test_perl_to_yaml,
23    'tml-local/yaml-roundtrip'  => \&test_yaml_roundtrip,
24    'tml-spec/basic-data.tml'   => \&test_yaml_json,
25    'tml-spec/unicode.tml'      => \&test_code_point,
26    'tml-world'                 => \&test_yaml_roundtrip,
27);
28
29sub main {
30    my ($verbose, $run_tests);
31    GetOptions(
32        'run_test' => \$run_tests,
33    );
34
35    if ( $run_tests ) {
36        my $file = shift @ARGV;
37        exit 0 unless -f $file;
38        my ($bridge) = first { $file =~ m{^t/\Q$_} } keys %BRIDGE_MAP;
39        die "No bridge found for $file" unless $bridge;
40
41        run_testml_file(
42            $file,
43            sub {
44                my ($file, $blocks) = @_;
45                subtest "TestML dev runner: $file" => sub {
46                    $BRIDGE_MAP{$bridge}->($_) for @$blocks;
47                };
48                done_testing;
49            },
50        );
51    }
52    else {
53        my (@opts, @files, @patterns);
54        for (@ARGV) {
55            if ( /^-/ ) {
56                push @opts, $_;
57            }
58            elsif ( -f ) {
59                push @files, $_;
60            }
61            else {
62                push @patterns, $_;
63            }
64        }
65
66        # if we got no files or patterns, treat that as taking anything
67        @patterns = "." if !@patterns && !@files;
68
69        if (@patterns) {
70            FILE: for my $file ( find_tml_files('t') ) {
71                if ( first { $file =~ /$_/ } @patterns ) {
72                        push @files, $file;
73                }
74            }
75        }
76
77        exec( 'prove', @opts, '--exec', "$0 --run_test", @files )
78            if @files;
79    }
80}
81
82main;
83
84__END__
85
86=head1 NAME
87
88t/tml - run .tml files matching a pattern
89
90=head1 SYNOPSIS
91
92    t/tml [prove options] [patterns]
93
94=head1 USAGE
95
96This program runs F<prove> against a set of F<.tml> files using their
97corresponding test bridge functions.
98
99Any arguments beginning with C<-> will be passed through to F<prove>.  All
100other arguments will be used as patterns to select F<.tml> files found anywhere
101under the F<t> directory.  You can use shell globbing syntax, and let the shell
102expand the patterns, or you can quote/escape the patterns and let them be
103treated as Perl regular expressions.
104
105For example:
106
107    t/tml unicode       # paths matching qr/unicode/
108    t/tml basic uni     # paths matching qr/basic/ or qr/uni/
109    t/tml 'local.*re'   # paths matching qr/local.*re/
110    t/tml '\d+'         # paths matching qr/\d+/
111
112Examples of options for prove:
113
114    t/tml -v quoting    # verbose run of paths matching qr/quoting/
115    t/tml -j9 world     # parallel run of paths matching qr/world/
116    t/tml -j9           # parallel run of all .tml files
117
118=cut
119