Debian Codegraph @

html/t/score.t

raw
1 #!perl
2 # Copyright 2022 Jeffrey Kegler
3 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
4 # redistribute it and/or modify it under the terms of the GNU Lesser
5 # General Public License as published by the Free Software Foundation,
6 # either version 3 of the License, or (at your option) any later version.
7 #
8 # Marpa::R2 is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser
14 # General Public License along with Marpa::R2. If not, see
15 # http://www.gnu.org/licenses/.
16
17 use 5.010001;
18 use strict;
19 use warnings;
20
21 use English qw( -no_match_vars );
22 use Fatal qw(open close);
23 use File::Spec;
24 use Test::More;
25
26 BEGIN {
27 use lib 'html/tool/lib';
28 my $eval_result = eval { require Marpa::R2::HTML::Test::Util; 1 };
29 if ( !$eval_result ) {
30 Test::More::plan tests => 1;
31 Test::More::fail(
32 "Could not load Marpa::R2::HTML::Test::Util; $EVAL_ERROR");
33 exit 0;
34 } ## end if ( !$eval_result )
35 } ## end BEGIN
36
37 # The script will require HTML::Parser, so we need to check here,
38 # even though we do not use it
39 BEGIN { Marpa::R2::HTML::Test::Util::load_or_skip_all('HTML::Parser'); }
40
41 use Test::More tests => 2;
42
43 use lib 'tool/lib';
44 use lib 'html/tool/lib';
45 use Marpa::R2::Test;
46 use Marpa::R2::HTML::Test::Util;
47
48 my $blib = $ENV{MARPA_TEST_BLIB} // 'blib';
49 my $script_dir = File::Spec->catdir( $blib, 'script' );
50
51 my @data_dir = qw( html t fmt_t_data );
52
53 for my $test (qw(1 2)) {
54 my $expected;
55 my $output = Marpa::R2::HTML::Test::Util::run_command(
56 File::Spec->catfile( $script_dir, 'marpa_r2_html_score' ),
57 File::Spec->catfile( @data_dir, ( 'input' . $test . '.html' ) )
58 );
59 $output =~ s/\A [^\n]* \n//xms;
60 open my $fh, q{<},
61 File::Spec->catfile( @data_dir,
62 ( 'score_expected' . $test . '.html' ) );
63 $expected = <$fh>;
64 local $RS = undef;
65 $expected = <$fh>;
66 close $fh;
67 Marpa::R2::Test::is( $output, $expected, 'marpa_r2_html_score test' );
68 } ## end for my $test (qw(1 2))
69