Files
perl-Test-Abortable/perl-Test-Abortable.spec
2025-08-12 18:17:37 +02:00

125 lines
4.3 KiB
RPMSpec

#
# spec file for package perl-Test-Abortable
#
# 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-Abortable
Name: perl-Test-Abortable
Version: 0.3.0
Release: 0
# 0.003 -> normalize -> 0.3.0
%define cpan_version 0.003
License: Artistic-1.0 OR GPL-1.0-or-later
Summary: Subtests that you can die your way out of ... but survive
URL: https://metacpan.org/release/%{cpan_name}
Source0: https://cpan.metacpan.org/authors/id/R/RJ/RJBS/%{cpan_name}-%{cpan_version}.tar.gz
Source100: README.md
BuildArch: noarch
BuildRequires: perl
BuildRequires: perl-macros
BuildRequires: perl(ExtUtils::MakeMaker) >= 6.78
BuildRequires: perl(Sub::Exporter)
BuildRequires: perl(Test2::API) >= 1.302075
BuildRequires: perl(Test::More) >= 0.96
BuildRequires: perl(Test::Needs)
Requires: perl(Sub::Exporter)
Requires: perl(Test2::API) >= 1.302075
Provides: perl(Test::Abortable) = %{version}
%undefine __perllib_provides
%{perl_requires}
%description
Test::Abortable provides a simple system for catching some exceptions and
turning them into test events. For example, consider the code below:
use Test::More;
use Test::Abortable;
use My::API; # code under test
my $API = My::API->client;
subtest "collection distinction" => sub {
my $result = $API->do_first_thing;
is($result->documents->first->title, "The Best Thing");
isnt($result->documents->last->title, "The Best Thing");
};
subtest "document transcendence" => sub { ... };
subtest "semiotic multiplexing" => sub { ... };
subtest "homoiousios type vectors" => sub { ... };
done_testing;
In this code, '$result->documents' is a collection. It has a 'first' method
that will throw an exception if the collection is empty. If that happens in
our code, our test program will die and most of the other subtests won't
run. We'd rather that we only abort the _subtest_. We could do that in a
bunch of ways, like adding:
return fail("no documents in response") if $result->documents->is_empty;
...but this becomes less practical as the number of places that might throw
these kinds of exceptions grows. To minimize code that boils down to "and
then stop unless it makes sense to go on," Test::Abortable provides a means
to communicate, via exceptions, that the running subtest should be aborted,
possibly with some test output, and that the program should then continue.
Test::Abortable exports a 'subtest' routine that behaves like the one in
Test::More|Test::More/subtest but will handle and recover from abortable
exceptions (defined below). It also exports 'testeval', which behaves like
a block eval that only catches abortable exceptions.
For an exception to be "abortable," in this sense, it must respond to a
'as_test_abort_events' method. This method must return an arrayref of
arrayrefs that describe the Test2 events to emit when the exception is
caught. For example, the exception thrown by our sample code above might
have a 'as_test_abort_events' method that returns:
[
[ Ok => (pass => 0, name => "->first called on empty collection") ],
]
It's permissible to have passing Ok events, or only Diag events, or
multiple events, or none although providing none might lead to some
serious confusion.
Right now, any exception that provides this method will be honored. In the
future, a facility for only allowing abortable exceptions of a given class
may be added.
%prep
%autosetup -n %{cpan_name}-%{cpan_version}
%build
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
%license LICENSE
%changelog