Files
perl-Test-Log-Log4perl/perl-Test-Log-Log4perl.spec
2025-08-12 18:17:46 +02:00

105 lines
3.3 KiB
RPMSpec

#
# spec file for package perl-Test-Log-Log4perl
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%define cpan_name Test-Log-Log4perl
Name: perl-Test-Log-Log4perl
Version: 0.320.0
Release: 0
# 0.32 -> normalize -> 0.320.0
%define cpan_version 0.32
License: Artistic-1.0 OR GPL-1.0-or-later
Summary: Test log4perl
URL: https://metacpan.org/release/%{cpan_name}
Source0: https://cpan.metacpan.org/authors/id/C/CL/CLKAO/%{cpan_name}-%{cpan_version}.tar.gz
Source100: README.md
BuildArch: noarch
BuildRequires: perl
BuildRequires: perl-macros
BuildRequires: perl(ExtUtils::MakeMaker) >= 6.59
BuildRequires: perl(Log::Log4perl)
BuildRequires: perl(Test::Exception)
Requires: perl(Log::Log4perl)
Requires: perl(Test::Exception)
Provides: perl(Log::Log4perl::Logger::IgnoreAll)
Provides: perl(Log::Log4perl::Logger::Interception)
Provides: perl(Test::Log::Log4perl) = %{version}
%undefine __perllib_provides
%{perl_requires}
%description
This module can be used to test that you're logging the right thing with
Log::Log4perl. It checks that we get what, and only what, we expect logged
by your code.
The basic process is very simple. Within your test script you get one or
more loggers from *Test::Log::Log4perl* with the 'get_logger' method just
like you would with *Log::Log4perl*. You're going to use these loggers to
declare what you think the code you're going to test should be logging.
# declare a bunch of test loggers
my $tlogger = Test::Log::Log4perl->get_logger("Foo::Bar");
Then, for each test you want to do you need to start up the module.
# start the test
Test::Log::Log4perl->start();
This diverts all subsequent attempts *Log::Log4perl* makes to log stuff and
records them internally rather than passing them though to the Log4perl
appenders as normal.
You then need to declare with the loggers we created earlier what we hope
Log4perl will be asked to log. This is the same syntax as
Test::Log::Log4perl uses, except if you want you can use regular
expressions:
$tlogger->debug("fish");
$tlogger->warn(qr/bar/);
You then need to run your code that you're testing.
# call some code that hopefully will call the log4perl methods
# 'debug' with "fish" and 'warn' with something that contains 'bar'
some_code();
We finally need to tell *Test::Log4Perl* that we're done and it should do
the comparisons.
# start the test
Test::Log::Log4perl->end("test name");
%prep
%autosetup -n %{cpan_name}-%{cpan_version}
%build
PERL_USE_UNSAFE_INC=1 perl Makefile.PL INSTALLDIRS=vendor
%make_build
%check
make test
%install
%perl_make_install
%perl_process_packlist
%perl_gen_filelist
%files -f %{name}.files
%doc Changes README
%changelog