Emacs' default "compile" command isn't really smart enough to work well if you're working in a source tree containing multiple modules.Also, if you're using mode-compile, it will just try to run the current module, which is not what I normally want.

This little program can be called instead and it will find the top-level makefile for the current tree, run "make test" on it, and fix error messages to create sane filenames (so "C-x `" etc can be used to go to the right source file for the errors)

This will probably also work for other editors/IDEs.

#!/usr/bin/perl -w # # Compile and test the current perl source tree from anywhere # in the tree. # # This program can be called from any point in a fairly typical # perl source tree (like the ones created by h2xs) # # It will try to find the toplevel Makefile.PL and run it to # create a Makefile in the same directory if needed # then runs "make test" and fixes error messages so they can # be used immediately by whatever system you have in place for # editing the offending files. (that would be Emacs in my case) # # it translates error messages to the actual source files (for # instance, "$path/blib/lib/Something/Else.pm" can be translated to # "$path/lib/Something/Else.pm" or "$path/Else/Else.pm" - whichever # exists) # # put this script in your PATH somewhere as "perl-test" # # --------------------------------------------------------------- # # emacs configuration: # # use # # M-x compile RET (or equivalent key chord) # to run perl-test instead of "make -k" # # or if you're using mode-compile, add the following to your .emacs fi +le: # # ;; use perl-test script to compile & test perl modules # ;; using mode-compile # (setq perl-command "perl-test") # (setq perl-dbg-flags "") # # --------------------------------------------------------------- # # (c) 2007 Joost Diepenmaat, joost@zeekat.nl # # This program is free software; you can redistribute it and/or modify + it under # the same terms as Perl itself. # # See http://www.perl.com/perl/misc/Artistic.html # # use strict; use Cwd; my $dir = getcwd; # find the top-level Makefile.PL while ((! -f "Makefile.PL") || (-f "../Makefile.PL")) { chdir ".."; my $newdir = getcwd; die "No Makefile.PL found!" if ($newdir eq $dir); $dir = $newdir; } if (!-f "Makefile") { system("perl Makefile.PL") and die "Error running Makefile.PL"; } open MAKE,"make test 2>&1|" or die "Can't make test: $!"; while (<MAKE>) { # create absolute paths s/( at )([^\/].*?)( line \d+\.)$/$1$dir\/$2$3/; # resolve blib files s/( at )(.*?\bblib\/.*?)( line \d+\.)$/"$1".blibtonormal($2)."$3"/e; print; } close MAKE; exit $? >> 8; # pass on exit code from make command sub blibtonormal { my ($blib) = @_; my $norm = $blib; $norm =~ s/.*\bblib\///; return $norm if (-f $norm); if ($norm =~ /\/([^\/]+)\.(pm|xs)$/) { my $test = "$dir/$1/$1.$2"; return $test if -f $test; } return $blib; # can't figure it out - just leave it }