Config-IOD

 view release on metacpan or  search on metacpan

lib/Test/Config/IOD.pm  view on Meta::CPAN

package Test::Config::IOD;

## no critic (Modules::ProhibitAutomaticExportation)

use 5.010;
use strict;
use warnings;

use Test::Differences;
use Test::Exception;
use Test::More;
use Config::IOD;

use Exporter qw(import);

our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2022-05-02'; # DATE
our $DIST = 'Config-IOD'; # DIST
our $VERSION = '0.353'; # VERSION

our @EXPORT = qw(test_modify_doc);

sub test_modify_doc {
    my $opts;
    if (ref($_[0]) eq 'HASH') {
        $opts = shift;
    } else {
        $opts = {};
    }
    my ($code, $doc1, $doc2, $name) = @_;

    subtest +($name // "test_modify_doc") => sub {
        my $iod = Config::IOD->new;
        my $doc = $iod->read_string($doc1);
        if ($opts->{dies}) {
            dies_ok { $code->($doc) } "dies"
                or return 0;
            return 1;
        } else {
            lives_ok { $code->($doc) } "lives"
                or return 0;
        }
        eq_or_diff $doc->as_string, $doc2, "result";
    };
}

1;
# ABSTRACT: Testing routines for Config::IOD

__END__

=pod

=encoding UTF-8

=head1 NAME

Test::Config::IOD - Testing routines for Config::IOD

=head1 VERSION

This document describes version 0.353 of Test::Config::IOD (from Perl distribution Config-IOD), released on 2022-05-02.

=head1 FUNCTIONS

=head2 test_modify_doc($code, $doc1, $doc2[, $test_name]) => bool

Parse string C<$doc1> into a L<Config::IOD::Document> object, then run C<<
$code->($doc_obj) >>, then compare C<< $doc_obj->as_string >> with string



( run in 1.012 second using v1.01-cache-2.11-cpan-39bf76dae61 )