summaryrefslogtreecommitdiff
path: root/t/spin/file.t
blob: 354ec77a103215a34163e93399d5346271d4d87b (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
#!/usr/bin/perl
#
# Test running spin on a single file.
#
# Copyright 2021 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT

use 5.024;
use autodie;
use warnings;

use lib 't/lib';

use Capture::Tiny qw(capture_stdout);
use Cwd qw(getcwd);
use Fcntl qw(SEEK_SET);
use File::Spec;
use File::Temp;
use Perl6::Slurp qw(slurp);
use Test::DocKnot::Spin qw(is_spin_output);

use Test::More tests => 3;

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

# Spin a single file.
my $tempfile = File::Temp->new();
my $datadir  = File::Spec->catfile('t',       'data', 'spin');
my $inputdir = File::Spec->catfile($datadir,  'input');
my $input    = File::Spec->catfile($inputdir, 'index.th');
my $expected = File::Spec->catfile($datadir,  'output', 'index.html');
my $spin
  = App::DocKnot::Spin::Thread->new({ 'style-url' => '/~eagle/styles/' });
$spin->spin_thread_file($input, $tempfile->filename);
is_spin_output($tempfile, $expected, 'spin_thread_file with output path');

# The same but spin to standard output.
my $html = capture_stdout {
    $spin->spin_thread_file($input);
};
$tempfile->seek(0, SEEK_SET);
$tempfile->truncate(0);
print {$tempfile} $html or die "Cannot write to $tempfile: $!\n";
$tempfile->flush();
is_spin_output($tempfile->filename, $expected, 'spin_thread_file to stdout');