How can I run Perl test suite automatically when files change?

后端 未结 7 581
余生分开走
余生分开走 2021-01-06 05:50

Is there a tool that would watch file changes in a directory tree of a Perl application and re-run the test suite every time I save changes to some module? Something akin to

相关标签:
7条回答
  • 2021-01-06 05:58

    The old school unix solution would be to write up a Makefile and trigger it regularly through a cron job (as frequently as once a minute), and have it mail you the results if something broke.

    Alternatively if you use a revision control system such as svn, you could use a commit hook to kick off a build/test cycle when you commit a file.

    One other thing you could do is write a wrapper script around your editor (such that when you close or save a file, the build/test cycle is triggered).

    0 讨论(0)
  • 2021-01-06 05:58

    Win32::FileNotify can help with monitoring changes to the file system if you are on Windows.

    0 讨论(0)
  • 2021-01-06 05:59

    I don't know of any generic filesystem monitoring widget, but here's the Perl specific half.

    sub run_tests {
        my $prove_out = `prove -lr`;
        my $tests_passed = $? == 0;
    
        return "" if $tests_passed;
        return $prove_out;
    }
    

    This uses the prove utility that comes with Test::Harness 3. It exits non-zero on test failure. Plug that into your filesystem monitoring thing and you're set.

    0 讨论(0)
  • 2021-01-06 06:01

    Have a look at Test::Continuous

    Some Test::Continuous links:

    • Video presentation with slides from YAPC::Asia 2008
    • Run continuous tests on remote host
    • Github repo
    0 讨论(0)
  • 2021-01-06 06:10

    The basic way to do this is through source control and an continuous integration package, say, like Smolder. When you check in files, the CI server notices the changes and runs the test suite for you.

    Many CI products collect cross-run information for you and can show you trends in your tests, test cover, and so on.

    0 讨论(0)
  • 2021-01-06 06:10

    I haven't managed to get Test::Continuous installed successfully on Windows, I use the following script, and it works pretty well for me:

    use File::ChangeNotify;
    
    $| = 1;
    
    my $watcher = File::ChangeNotify->instantiate_watcher(
        directories => [ 't', 'lib' ],
        filter => qr/\.t|\.pl|\.pm/,
    );
    
    while (my @events = $watcher->wait_for_events) {
        print `prove -l -r -t --timer`;
    }
    
    0 讨论(0)
提交回复
热议问题