|
| 1 | +package Test2::Plugin::Immiscible; |
| 2 | +use strict; |
| 3 | +use warnings; |
| 4 | + |
| 5 | +use Test2::API qw/context/; |
| 6 | + |
| 7 | +our $VERSION = '2.000000'; |
| 8 | + |
| 9 | +our $LOCK; |
| 10 | + |
| 11 | +sub import { |
| 12 | + my $class = shift; |
| 13 | + my ($skip_cb) = @_; |
| 14 | + |
| 15 | + my $ctx = context(); |
| 16 | + |
| 17 | + if ($skip_cb && $skip_cb->()) { |
| 18 | + $ctx->note("Immiscibility enforcement skipped due to callback."); |
| 19 | + } |
| 20 | + else { |
| 21 | + if (-w '.') { |
| 22 | + if (open($LOCK, '>>', './.immiscible-test.lock')) { |
| 23 | + require Fcntl; |
| 24 | + if (flock($LOCK, Fcntl::LOCK_EX)) { |
| 25 | + $ctx->note("Immiscibility enforcement success."); |
| 26 | + } |
| 27 | + else { |
| 28 | + $ctx->plan(0, SKIP => "could not get lock '$!', cannot guarentee immiscibility."); |
| 29 | + } |
| 30 | + } |
| 31 | + else { |
| 32 | + $ctx->plan(0, SKIP => "could not get lock '$!', cannot guarentee immiscibility."); |
| 33 | + } |
| 34 | + } |
| 35 | + else { |
| 36 | + $ctx->plan(0, SKIP => "'.' is not writable, cannot guarentee immiscibility."); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + $ctx->release; |
| 41 | +} |
| 42 | + |
| 43 | +1; |
| 44 | + |
| 45 | +__END__ |
| 46 | +
|
| 47 | +=pod |
| 48 | +
|
| 49 | +=encoding UTF-8 |
| 50 | +
|
| 51 | +=head1 NAME |
| 52 | +
|
| 53 | +Test2::Plugin::Immiscible - Prevent tests with this module from running |
| 54 | +together in the same test suite. |
| 55 | +
|
| 56 | +=head1 DESCRIPTION |
| 57 | +
|
| 58 | +Prevent any 2 tests with this module loaded from running together in the same |
| 59 | +repo. |
| 60 | +
|
| 61 | +=head1 SYNOPSIS |
| 62 | +
|
| 63 | + use Test2::Plugin::Immiscible; |
| 64 | +
|
| 65 | +or |
| 66 | +
|
| 67 | + Test2::Plugin::Immiscible(sub { $ENV{SKIP_IMMISCIBILITY_CHECK } ? 1 : 0 ); |
| 68 | +
|
| 69 | +The second form allows you to skip the protection if certain conditions are |
| 70 | +met. The callback sub should return true if the protection should be skipped. |
| 71 | +
|
| 72 | +=over 4 |
| 73 | +
|
| 74 | +=back |
| 75 | +
|
| 76 | +=head1 SOURCE |
| 77 | +
|
| 78 | +The source code repository for Test2-Harness can be found at |
| 79 | +L<http://github.com/Test-More/Test2-Harness/>. |
| 80 | +
|
| 81 | +=head1 MAINTAINERS |
| 82 | +
|
| 83 | +=over 4 |
| 84 | +
|
| 85 | +=item Chad Granum E<lt>[email protected]E<gt> |
| 86 | +
|
| 87 | +=back |
| 88 | +
|
| 89 | +=head1 AUTHORS |
| 90 | +
|
| 91 | +=over 4 |
| 92 | +
|
| 93 | +=item Chad Granum E<lt>[email protected]E<gt> |
| 94 | +
|
| 95 | +=back |
| 96 | +
|
| 97 | +=head1 COPYRIGHT |
| 98 | +
|
| 99 | +Copyright Chad Granum E<lt>[email protected]E<gt>. |
| 100 | +
|
| 101 | +This program is free software; you can redistribute it and/or |
| 102 | +modify it under the same terms as Perl itself. |
| 103 | +
|
| 104 | +See L<http://dev.perl.org/licenses/> |
| 105 | +
|
| 106 | +=cut |
| 107 | +
|
0 commit comments