summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2023-03-25 11:32:18 +0100
committerYves Orton <demerphq@gmail.com>2023-03-28 21:50:24 +0800
commitda545c2e71dbd42b4e90bd9e223203257bf043fd (patch)
treebe117fe7596ce1ef8af52bc8a552f4da2d4eda55 /t
parent024665c496f50e61ab29b1956e08b878f11bbe1a (diff)
downloadperl-da545c2e71dbd42b4e90bd9e223203257bf043fd.tar.gz
t/harness - rework App::Prove::State setup to not warn and use customizable state file
Currently we only store state if we are running parallel tests, so if you run the tests in series we do not store data on how long they took, and we can't use that information in a follow up parallel test run. We also do not allow the state file to be customized to be outside of the repo, so git clean -dfx wipes it. This means you can't keep your test data over time, which can be a bit annoying. We also currently construct the state object twice during setup, resulting in two (useless) warnings when the state file is missing, which also doubles the time to set up the tests because the yaml file gets read twice, and not very efficiently either. This patch changes the logic so that we initialize the state object only once during startup, and we use the state file if we are going to run tests, parallel or not, provided the user does not explicitly disable it (see below). The order that tests are run is affected only when the tests are run in parallel. It also allows the user to specify where the state file should live, with the $ENV{PERL_TEST_STATE_FILE} environment variable, which can be set to 0 or the empty string to disable use of the state file if needed. We also take care to silence the warning about an empty state file, except in the case where the user has overriden the file name with the $ENV{PERL_TEST_STATE_FILE}. Lastly this patch disables loading the state data /at all/, when the dump_tests option is invoked. There is no need nor point to load the state data when we are simply going to dump out the list of tests we will run.
Diffstat (limited to 't')
-rw-r--r--t/harness20
1 files changed, 16 insertions, 4 deletions
diff --git a/t/harness b/t/harness
index ce686eb171..50801fa0bf 100644
--- a/t/harness
+++ b/t/harness
@@ -139,7 +139,6 @@ sub _extract_tests {
}
my %total_time;
-
sub _compute_tests_and_ordering($) {
my @tests = $_[0]->@*;
@@ -147,10 +146,23 @@ sub _compute_tests_and_ordering($) {
my %all_dirs;
my %map_file_to_dir;
- if ($jobs > 1) {
+ if (!$dump_tests) {
require App::Prove::State;
- $state = App::Prove::State->new({ store => 'test_state' });
- $state->apply_switch('slow', 'save');
+ if (!$state) {
+ # silence unhelpful warnings from App::Prove::State about not having
+ # a save state, unless we actually set the PERL_TEST_STATE we don't care
+ # and we don't need to know if its fresh or not.
+ local $SIG{__WARN__} = $ENV{PERL_TEST_STATE} ? $SIG{__WARN__} : sub {
+ return if $_[0] and $_[0]=~/No saved state/;
+ warn $_[0];
+ };
+ my $state_file = $ENV{PERL_TEST_STATE_FILE} // 'test_state';
+ if ($state_file) { # set PERL_TEST_STATE_FILE to 0 to skip this
+ $state = App::Prove::State->new({ store => $state_file });
+ $state->apply_switch('save');
+ $state->apply_switch('slow') if $jobs > 1;
+ }
+ }
# For some reason get_tests returns *all* the tests previously run,
# (in the right order), not simply the selection in @tests
# (in the right order). Not sure if this is a bug or a feature.