Thanks Karen. I think that's exactly what I need.
On Thu, Jan 30, 2020, 2:51 PM Karen Etheridge <p...@froods.org> wrote: > Exceptions can be tested safely with Test::Fatal (which is a thin > wrapper around Try::Tiny). > > use Test::Fatal; > like( > exception { > Data::ObjectStore->open_store( $source_dir ); > fail( "was able to open a store with an old incompatable > version" ); > }, > qr/Unable to open|lock file did not exist|Permission denied/i, > 'error message for opeining store with incompatable message', > ); > > This is orthogonal to the core failure issue though. > > On Thu, Jan 30, 2020 at 2:39 PM James E Keenan <jkee...@pobox.com> wrote: > > > > On 1/29/20 12:42 PM, Eric Wolf wrote: > > > I have a test that tries to catch a die in an eval. This works fine for > > > me locally, but the tester report indicates that it fails and bails at > > > this point. > > > To me this seems to indicate that the test harness is set up to barf on > > > this type of error or that my test is written or configured > incorrectly. > > > > > > Should I just skip this test or is there some easy magic that can be > > > done for it? > > > > > > Thanks in advance, > > > Eric Wolf aka canid > > > > > > *Test Code *(you can tell its genuine due to the speeling erorrs) > > > > > > 1159 eval { > > > 1160 my $store = Data::ObjectStore->open_store( $source_dir ); > > > 1161 fail( "was able to open a store with an old incompatable > > > version" ); > > > 1162 }; > > > 1163 like( $@, qr/Unable to open|lock file did not exist|Permission > > > denied/i, 'error message for opeining store with incompatable message' > ); > > > > > > > To me, seeing a Test::More test within an eval block is a code smell. > > There's always a chance that the test may crash in some way that sets $@ > > -- which would make the value of $@ ambiguous, at best. > > > > I don't completely understand what you're attempting to do, but ... Is > > there anything that prevents you from this? > > > > ##### > > my $store; > > eval { > > $store = Data::ObjectStore->open_store( $source_dir ); > > }; > > like( $@, > > qr/Unable to open|lock file did not exist|Permission denied/i, > > 'error message for opeining store with incompatable message' > > ); > > ok(! $store, "Was not able to open a store with an old incompatible > > version"); > > ##### > > > > > *Tester Output* > > > * > > > * > > > > > > Output from './Build test': > > > > > > Permission denied at > /tmp/loop_over_bdir-29197-caKZ6Z/Data-RecordStore-6.04-0/blib/lib/Data/RecordStore.pm > line 194. > > > at t/object_store.t line 20. > > > main::__ANON__(" Permission denied at > /tmp/loop_over_bdir-29197-caKZ6Z/Data-R"...) called at > /tmp/loop_over_bdir-29197-caKZ6Z/Data-RecordStore-6.04-0/blib/lib/Data/RecordStore.pm > line 194 > > > Data::RecordStore::open_store("Data::RecordStore", > "DATA_PROVIDER", "/tmp/NWPz3HLh2e", "BASE_PATH", > "/tmp/NWPz3HLh2e/RECORDSTORE") called at > /tmp/loop_over_bdir-29197-caKZ6Z/Data-ObjectStore-2.12-0/blib/lib/Data/ObjectStore.pm > line 53 > > > Data::ObjectStore::open_store("Data::ObjectStore", > "/tmp/NWPz3HLh2e") called at t/object_store.t line 1160 > > > *eval {...} called at t/object_store.t line 1159* > > > main::test_upgrade_db() called at t/object_store.t line 54 > > > Permission denied at > /tmp/loop_over_bdir-29197-caKZ6Z/Data-RecordStore-6.04-0/blib/lib/Data/RecordStore.pm > line 194. > > > at t/object_store.t line 20. > > > main::__ANON__(" Permission denied at > /tmp/loop_over_bdir-29197-caKZ6Z/Data-R"...) called at > /tmp/loop_over_bdir-29197-caKZ6Z/Data-RecordStore-6.04-0/blib/lib/Data/RecordStore.pm > line 194 > > > Data::RecordStore::open_store("Data::RecordStore", > "DATA_PROVIDER", "/tmp/NWPz3HLh2e", "BASE_PATH", > "/tmp/NWPz3HLh2e/RECORDSTORE") called at > /tmp/loop_over_bdir-29197-caKZ6Z/Data-ObjectStore-2.12-0/blib/lib/Data/ObjectStore.pm > line 53 > > > Data::ObjectStore::open_store("Data::ObjectStore", > "/tmp/NWPz3HLh2e") called at t/object_store.t line 1168 > > > main::test_upgrade_db() called at t/object_store.t line 54 > > > # Tests were run but no plan was declared and done_testing() was not > seen. > > > # Looks like your test exited with 13 just after 273. > > > t/object_store.t .. > > > Dubious, test returned 13 (wstat 3328, 0xd00) > > > All 273 subtests passed > > > t/cache.t ......... ok > > > > > > >