App-autotest

 view release on metacpan or  search on metacpan

t/unit/autotest.t  view on Meta::CPAN

      my $result=$autotest->all_test_programs;
      eq_or_diff( [sort @$result], [sort @list] );
    };
  };

  describe 'changed_and_new_files' => sub {
    my $path     = TEST_PROGRAMS_DIRECTORY . '/1.t';
    my @expected = ($path);

    my $autotest = an_autotest();
    it 'should find changed files' => sub {
      my $event = stub( type => 'modify', path => $path );
      $autotest->watcher->stubs( wait_for_events => ($event) );

      my @got = $autotest->changed_and_new_files;
      eq_or_diff \@got, [\@expected];
    };

    it 'should find new files' => sub {
      my $event = stub( type => 'create', path => $path );
      $autotest->watcher->stubs( wait_for_events => ($event) );

      my @got = $autotest->changed_and_new_files;
      eq_or_diff \@got, [\@expected];
    };
  };

  describe 'pm_to_t' => sub {
    my $autotest = an_autotest();

    it 'calc rate of concordance test' => sub {
        eq_or_diff $autotest->calc_rate_of_concordance(['a', 'b', 'c', 'd'], ['a', 'd', 'f']), 0.5;
    };

    it 'calc rate of concordance non t test' => sub {
        eq_or_diff $autotest->calc_rate_of_concordance(['a', 'b', 'c', 'd'], ['g', 'z']), 0;
    };

    it 'calc rate of concordance non pm  test' => sub {
        eq_or_diff $autotest->calc_rate_of_concordance([], ['g', 'z']), 0;
    };

    it 'pm_to_t one hit' => sub {

        my $guard = mock_guard( 'App::autotest', { all_test_programs => sub { ['t/abcd.t', 't/ab_cd.t', 't/abcd_ef_gh.t'] } } );

        eq_or_diff $autotest->pm_to_t(['lib/abCd/efgh.pm']), ['t/ab_cd.t'];
        
    };

    it 'pm_to_t many hit' => sub {

        my $guard = mock_guard( 'App::autotest', { all_test_programs => sub { ['t/abcd.t', 't/ab_cd.t', 't/abcd_ef_gh.t', 't/aaa.t'] } } );

        eq_or_diff $autotest->pm_to_t(['lib/abCd/efgh.pm', 'lib/aaa/test.pm']), ['t/ab_cd.t', 't/aaa.t'];
    };
  };

  # it 'should run tests upon change or creation' => sub {
  #   my $autotest = an_autotest_that_just_checks_once_for_changed_or_new_files();
  #   $autotest->harness( a_harness_not_running_the_tests() );

  #   $autotest->expects('changed_and_new_files')->returns(SOME_TEST_PROGRAMS);
  #   ok $autotest->run_tests_upon_change_or_creation;
  # };
};

sub an_autotest { App::autotest->new(@_) }

sub an_autotest_that_just_checks_once_for_changed_or_new_files {
    my $autotest = an_autotest();
    $autotest->after_change_or_new_hook(
        AN_AFTER_CHANGE_OR_NEW_HOOK_THAT_EXISTS_IMMEDIATELY);
    return $autotest;
}
sub a_harness { return TAP::Harness->new(@_) }

runtests unless caller;



( run in 1.299 second using v1.01-cache-2.11-cpan-d7f47b0818f )