summaryrefslogtreecommitdiff
path: root/test/src
diff options
context:
space:
mode:
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2018-01-18 22:55:15 +0100
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2018-01-18 22:55:15 +0100
commit50936073b7f81a4ca991809d02c77f6fd7813c80 (patch)
treed4cdd774ea41a40332562f603f129423c63f3645 /test/src
parente7ae83be731ad82537bc906560e91f29b81be088 (diff)
Testsuite: Try harder to locate the tools
Diffstat (limited to 'test/src')
-rw-r--r--test/src/locate.pl51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/src/locate.pl b/test/src/locate.pl
new file mode 100644
index 000000000..6f752c137
--- /dev/null
+++ b/test/src/locate.pl
@@ -0,0 +1,51 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use File::Find;
+use Cwd;
+
+my @dirs = grep { /^\// && -d } split(/:/, $ENV{PATH}), qw(
+ /bin
+ /usr/bin
+ /usr/sbin
+ /usr/libexec
+ /usr/local/bin
+ /usr/local/sbin
+ /usr/local
+ /opt
+);
+
+my %path = map { $_ => locate($_, @dirs) } @ARGV;
+
+mkdir 'bin.sys'
+ or die "bin.sys: $!"
+ if not -d 'bin.sys';
+
+foreach my $tool (keys %path) {
+ next if not defined $path{$tool};
+ print "$tool $path{$tool}\n";
+
+ unlink "bin.sys/$tool";
+ symlink $path{$tool}, "bin.sys/$tool"
+ or warn "bin.sys/$tool -> $path{$tool}: $!\n";
+}
+
+sub locate {
+ my ($tool, @dirs) = @_;
+
+ # use die to break out of the find as soon
+ # as we found it
+ my $cwd = cwd;
+ eval {
+ find(
+ sub {
+ return unless $tool eq $_ and -x $_ and -f _;
+ die { found => $File::Find::name };
+ },
+ @dirs
+ );
+ };
+ chdir $cwd;
+
+ return (ref $@ eq ref {} and $@->{found}) ? $@->{found} : undef;
+}