melo / scripts

My personal script stash

scripts / bin / x-test-continuous
100755 46 lines (34 sloc) 0.792 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env perl
 
use strict;
use warnings;
use Mac::FSEvents;
use IO::Select;
 
if (!@ARGV) {
  print STDERR <<'...';
  Usage: x-test-continuous command_to_run
 
    This utility watches the ./lib and ./t for modifications.
    If any modification is detected, the command_to_run is executed
 
    My usual use case is:
 
      x-test-continuous prove -l -v t
 
...
 
  exit(1);
}
 
my @paths = ('./lib', './t');
my %fh_map;
my $sel = IO::Select->new;
 
foreach my $path (@paths) {
  my $fs = Mac::FSEvents->new({
    path => $path,
    latency => 1.0,
  });
  my $fh = $fs->watch;
  $sel->add($fh);
  $fh_map{$fh} = $fs;
}
 
while (my @fhs = $sel->can_read) {
  foreach my $fh (@fhs) {
    my @events = $fh_map{$fh}->read_events;
    system(@ARGV)
  }
}
 
END { map { $_->stop } keys %fh_map }