summaryrefslogtreecommitdiff
path: root/t/update/basic.t
blob: a21343f82dc6a235fa75180893b033c8630ed5c6 (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
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl
#
# Tests for the App::DocKnot::Update module API.
#
# Copyright 2020-2021 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT

use 5.024;
use autodie;
use warnings;

use lib 't/lib';

use File::Temp;
use File::Spec;
use Perl6::Slurp qw(slurp);
use Test::RRA qw(is_file_contents);

use Test::More;

# Isolate from the environment.
local $ENV{XDG_CONFIG_HOME} = '/nonexistent';
local $ENV{XDG_CONFIG_DIRS} = '/nonexistent';

# Load the module.
BEGIN { use_ok('App::DocKnot::Update') }

# We have a set of test cases in the data directory.  Each of them contains
# an old directory for the old files and a docknot.yaml file for the results.
my $dataroot = File::Spec->catfile('t', 'data', 'update');
opendir(my $tests, $dataroot);
my @tests = File::Spec->no_upwards(readdir($tests));
closedir($tests);

# For each of those cases, initialize an object, generate the updated
# configuration, and compare it with the test output file.
my $tempdir = File::Temp->newdir();
for my $test (@tests) {
    my $metadata_path = File::Spec->catfile($dataroot, $test, 'old');
    my $expected_path = File::Spec->catfile($dataroot, $test, 'docknot.yaml');
    my $output_path   = File::Spec->catfile($tempdir,  "$test.yaml");
    my $docknot       = App::DocKnot::Update->new(
        {
            metadata => $metadata_path,
            output   => $output_path,
        },
    );
    isa_ok($docknot, 'App::DocKnot::Update', "for $test");
    $docknot->update();
    my $got = slurp($output_path);
    is_file_contents($got, $expected_path, "output for $test");
}

# Check that we ran the correct number of tests.
done_testing(1 + scalar(@tests) * 2);