This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
/
Markdown.pm
108 lines (76 loc) · 2.58 KB
/
Markdown.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Copyright (C) 2008-2009, Parrot Foundation.
# $Id$
package Parrot::Test::Markdown;
require Parrot::Test;
=head1 Testing routines specific to 'Markdown'.
=head2 Description
Call 'Markdown'.
=head2 Methods
=head3 new
Yet another constructor.
=cut
use strict;
use warnings;
use File::Spec;
sub new {
return bless {};
}
my %language_test_map = (
output_is => 'is_eq',
output_like => 'like',
output_isnt => 'isnt_eq',
);
foreach my $func ( keys %language_test_map ) {
no strict 'refs';
*{"Parrot::Test::Markdown::$func"} = sub {
my $self = shift;
my ( $code, $output, $desc, %options ) = @_;
my $count = $self->{builder}->current_test + 1;
my $params = $options{params} || q{};
my $parrot = File::Spec->catfile( $self->{relpath}, $self->{parrot} );
# flatten filenames (don't use directories)
my $lang_fn = File::Spec->rel2abs( Parrot::Test::per_test( '.text', $count ) );
my $out_fn = File::Spec->rel2abs( Parrot::Test::per_test( '.html', $count ) );
my @test_prog = (
"$parrot markdown.pbc $lang_fn",
);
# This does not create byte code, but lua code
Parrot::Test::write_code_to_file( $code, $lang_fn )
if (defined $code);
# STDERR is written into same output file
my $exit_code = Parrot::Test::run_command(
\@test_prog,
STDOUT => $out_fn,
STDERR => $out_fn,
);
my $builder_func = $language_test_map{$func};
# set a todo-item for Test::Builder to find
my $call_pkg = $self->{builder}->exported_to() || '';
local *{ $call_pkg . '::TODO' } = ## no critic Variables::ProhibitConditionalDeclarations
\$options{todo} if defined $options{todo};
# That's the reason for: no strict 'refs';
my $pass =
$self->{builder}
->$builder_func( Parrot::Test::slurp_file($out_fn), $output, $desc );
unless ($pass) {
my $diag = q{};
my $test_prog = join ' && ', @test_prog;
$diag .= "'$test_prog' failed with exit code $exit_code."
if $exit_code;
$self->{builder}->diag($diag) if $diag;
}
# The generated files are left in the t/* directories.
# Let 'make clean' and 'svn:ignore' take care of them.
return $pass;
}
}
=head2 History
Mostly taken from F<languages/lua/t/Parrot/Test/Lua.pm>.
=cut
1;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: