Debian Codegraph @

t/tml

raw
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use lib 'lib', 't/lib/';
5 use Test::More 0.88;
6 use SubtestCompat;
7 use Getopt::Long qw/:config passthrough/;
8 use List::Util qw/first/;
9 use TestBridge;
10 use 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/
18 my %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
29 sub 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
82 main;
83
84 __END__
85
86 =head1 NAME
87
88 =for stopwords tml
89
90 t/tml - run .tml files matching a pattern
91
92 =head1 SYNOPSIS
93
94 t/tml [prove options] [patterns]
95
96 =head1 USAGE
97
98 This program runs F<prove> against a set of F<.tml> files using their
99 corresponding test bridge functions.
100
101 Any arguments beginning with C<-> will be passed through to F<prove>. All
102 other arguments will be used as patterns to select F<.tml> files found anywhere
103 under the F<t> directory. You can use shell globbing syntax, and let the shell
104 expand the patterns, or you can quote/escape the patterns and let them be
105 treated as Perl regular expressions.
106
107 For example:
108
109 t/tml unicode # paths matching qr/unicode/
110 t/tml basic uni # paths matching qr/basic/ or qr/uni/
111 t/tml 'local.*re' # paths matching qr/local.*re/
112 t/tml '\d+' # paths matching qr/\d+/
113
114 Examples of options for prove:
115
116 t/tml -v quoting # verbose run of paths matching qr/quoting/
117 t/tml -j9 world # parallel run of paths matching qr/world/
118 t/tml -j9 # parallel run of all .tml files
119
120 =cut