| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- use strict;
- use warnings;
- use Test::More;
- use File::Temp qw{tempfile};
- use_ok('Test::Mapper');
- # Spin up a temp DB for each test run
- my ( undef, $dbfile ) = tempfile( UNLINK => 1, SUFFIX => '.db' );
- my $mapper = Test::Mapper->new(
- db => $dbfile,
- product => 'TestProduct',
- environment => 'linux',
- );
- isa_ok( $mapper, 'Test::Mapper' );
- # Map a test to some resources
- $mapper->map_test(
- test => 't/acceptance/login.t',
- resources => [ 'lib/MyApp/Auth.pm', 'lib/MyApp/Session.pm' ],
- );
- # Map a second test to a partially overlapping set
- $mapper->map_test(
- test => 't/acceptance/logout.t',
- resources => [ 'lib/MyApp/Session.pm' ],
- );
- # Resource that only login.t touches
- my @tests = $mapper->tests_for_resources( resources => ['lib/MyApp/Auth.pm'] );
- is( scalar @tests, 1, 'one test for Auth.pm' );
- is( $tests[0], 't/acceptance/login.t', 'correct test for Auth.pm' );
- # Resource shared by both tests
- my @shared = sort $mapper->tests_for_resources( resources => ['lib/MyApp/Session.pm'] );
- is( scalar @shared, 2, 'two tests for Session.pm' );
- is_deeply( \@shared, [ 't/acceptance/login.t', 't/acceptance/logout.t' ],
- 'correct tests for Session.pm' );
- # Resource not mapped to anything
- my @none = $mapper->tests_for_resources( resources => ['lib/MyApp/Unknown.pm'] );
- is( scalar @none, 0, 'no tests for unmapped resource' );
- # Idempotency: mapping same test+resource again should not create duplicates
- $mapper->map_test(
- test => 't/acceptance/login.t',
- resources => ['lib/MyApp/Auth.pm'],
- );
- my @dedup = $mapper->tests_for_resources( resources => ['lib/MyApp/Auth.pm'] );
- is( scalar @dedup, 1, 'duplicate mapping is idempotent' );
- done_testing;
|