summaryrefslogtreecommitdiff
path: root/t/spin/errors.t
diff options
context:
space:
mode:
authorRuss Allbery <rra@cpan.org>2021-09-09 14:47:31 -0700
committerRuss Allbery <rra@cpan.org>2021-09-09 14:47:31 -0700
commit99933cd7ba67347a5043ffdfc4b369d35f6a06f8 (patch)
tree4693ccd6b65d500d9ee36f15c03156fb35b46bad /t/spin/errors.t
parentddbbdc7f480aa390be5a2d1da2d98e1ef251a7c4 (diff)
Add a test suite for thread errors
Test error handling in App::DocKnot::Spin::Thread and adjust the output of some of the error messages to make them easier to read.
Diffstat (limited to 't/spin/errors.t')
-rwxr-xr-xt/spin/errors.t46
1 files changed, 46 insertions, 0 deletions
diff --git a/t/spin/errors.t b/t/spin/errors.t
new file mode 100755
index 0000000..6c27a87
--- /dev/null
+++ b/t/spin/errors.t
@@ -0,0 +1,46 @@
+#!/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.
+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:2: invalid macro placeholder \2 (greater than 1)
+errors.th:2: invalid macro argument count for \badcount
+errors.th:4: unknown variable \=UNKNOWN
+errors.th:4: unknown command or macro \unknown
+errors.th:5: space in anchor "#foo bar"
+errors.th:5: no package release information available
+errors.th:5: no sitemap file found
+errors.th:5: no package version information available
+errors.th:5: 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_file($input);
+};
+
+# Strip off the prefix and simplify the file name, and then check against the
+# expected output.
+$stderr =~ s{ ^ \S+ [ ] spin:/[^:]+/errors[.]th }{errors.th}xmsg;
+$stderr =~ s{ (cannot [ ] stat [^:]+): .* }{$1\n}xms;
+is($stderr, $EXPECTED_ERRORS, 'errors are correct');