summaryrefslogtreecommitdiff
path: root/t/spin/errors.t
blob: d4cc565f470ade7764f0a8425d659390d7ae176c (plain)
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
#!/usr/bin/perl
#
# Test errors generated by App::DocKnot::Spin::Thread.
#
# Copyright 2021 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT

use 5.024;
use autodie;
use warnings;

use Capture::Tiny qw(capture);
use File::Spec;
use File::Temp;

use Test::More tests => 2;

# Expected errors from spinning the error file.  The line numbers are still
# not entirely correct because line tracking is very complicated and still not
# entirely correct.
my $EXPECTED_ERRORS = <<'ERRORS';
errors.th:1: cannot find argument 2: Did not find opening bracket after prefix: "\s*", detected at offset 2
errors.th:3: invalid macro placeholder \2 (greater than 1)
errors.th:5: invalid macro argument count for \badcount
errors.th:9: unknown variable \=UNKNOWN
errors.th:11: unknown command or macro \unknown
errors.th:14: space in anchor "#foo bar"
errors.th:15: no package release information available
errors.th:16: no sitemap file found
errors.th:17: no package version information available
errors.th:17: cannot stat file nonexistent-file
ERRORS

require_ok('App::DocKnot::Spin::Thread');

# Spin the errors file with output captured.
my $input = File::Spec->catfile('t', 'data', 'spin', 'errors', 'errors.th');
my $spin = App::DocKnot::Spin::Thread->new();
my ($stdout, $stderr) = capture {
    $spin->spin_thread_file($input);
};

# Simplify the file name, and then check against the expected output.
$stderr =~ s{ ^ [^:]+/errors[.]th: }{errors.th:}xmsg;
$stderr =~ s{ (cannot [ ] stat [^:]+): .* }{$1\n}xms;
is($stderr, $EXPECTED_ERRORS, 'errors are correct');