UNPKG

1.72 kBPlain TextView Raw
1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5
6use TestML;
7
8my $testml_path = $ARGV[0];
9
10open TESTML, $testml_path or
11 die "Can't open '$testml_path' for input";
12
13my $testml = do {local $/; <TESTML>};
14
15close TESTML;
16
17$testml =~ s/\A\s*%TestML\s+\d.*\n+//;
18
19$testml = "%TestML 0.1.0\n\n$testml";
20
21{
22 package Bridge;
23 use base 'TestML::Bridge';
24 use TestML::Util;
25 use File::Temp qw/tempdir/;
26 use Capture::Tiny 'capture';
27 use Test::More;
28 use XXX;
29
30 sub undent {
31 my ($self, $text) = @_;
32 $text = $text->value;
33 $text =~ s/^ //mg;
34 return str $text;
35 }
36
37 sub compile {
38 my ($self, $testml, $import) = @_;
39 $testml = $testml->value;
40 $import = $import ? $import->value : undef;
41 $import = $self->parse_import($import);
42
43 my ($temp_dir) = tempdir or die;
44 my $temp_file = "$temp_dir/test.tml";
45 open my $temp_handle, '>', $temp_file
46 or die "Can't open '$temp_file' for output: $!";
47 print $temp_handle $testml;
48 close $temp_handle;
49
50 for my $file (keys %$import) {
51 my $temp_file = "$temp_dir/$file";
52 open my $temp_handle, '>', $temp_file
53 or die "Can't open '$temp_file' for output: $!";
54 print $temp_handle $import->{$file};
55 close $temp_handle;
56 }
57
58 my ($stdout, $stderr, $rc) = capture {
59 system("testml-compiler $temp_file");
60 };
61
62 die "Error while testing testml-compiler:\n$stderr"
63 if $rc != 0;
64
65 warn $stderr if $stderr;
66
67 return str $stdout;
68 }
69
70 sub parse_import {
71 my ($self, $import) = @_;
72
73 return {} unless $import;
74
75 my @import = split /^\+\+\+\ (.*)\n/m, $import;
76 shift @import;
77
78 return {@import};
79 }
80}
81
82TestML->new(
83 testml => $testml,
84 bridge => 'Bridge',
85)->run;