mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
Add automated tests
This commit is contained in:
parent
613ba240a5
commit
80cb37418a
15
.travis.yml
Normal file
15
.travis.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
language: perl
|
||||
install:
|
||||
- sudo apt-get install devscripts python ruby php5-cli gawk
|
||||
#
|
||||
# Modules used by test script
|
||||
- cpanm --notest Test::More File::Find Capture::Tiny
|
||||
#
|
||||
# Modules used by plugins
|
||||
- cpanm --notest Asterisk::AMI Cache::Memcached BerkeleyDB DBD::Pg Data::Dump Device::SerialPort FCGI::Client File::ReadBackwards File::Tail::Multi Graphics::ColorNames IPC::Run3 IPC::ShareLite Modern::Perl MooseX::POE Net::Telnet Net::Telnet::Cisco POE Proc::ProcessTable Redis Sys::Virt WWW::Mechanize::TreeBuilder nvidia::ml
|
||||
# Modules used by plugins, but missing on cpan
|
||||
# - Sun::Solaris::Kstat
|
||||
# - VMware::VIRuntime
|
||||
# - MythTV
|
||||
script: "prove"
|
107
t/test.t
Normal file
107
t/test.t
Normal file
@ -0,0 +1,107 @@
|
||||
# -*- perl -*-
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
use File::Find ();
|
||||
use Capture::Tiny ':all';
|
||||
|
||||
use vars qw/*name *dir *prune/;
|
||||
*name = *File::Find::name;
|
||||
*dir = *File::Find::dir;
|
||||
*prune = *File::Find::prune;
|
||||
my $num_plugins = 0;
|
||||
|
||||
sub wanted {
|
||||
my ( $dev, $ino, $mode, $nlink, $uid, $gid, $interpreter );
|
||||
|
||||
( ( $dev, $ino, $mode, $nlink, $uid, $gid ) = lstat($_) )
|
||||
&& -f _
|
||||
&& ( $interpreter = hashbang("$_") )
|
||||
&& ++$num_plugins
|
||||
&& process_file( $_, $name, $interpreter );
|
||||
}
|
||||
|
||||
File::Find::find( { wanted => \&wanted }, 'plugins' );
|
||||
|
||||
sub hashbang {
|
||||
my ($filename) = @_;
|
||||
open my $file, '<', $filename;
|
||||
my $firstline = <$file>;
|
||||
close $file;
|
||||
|
||||
$firstline =~ m{ ^\#! # hashbang
|
||||
\s* # optional space
|
||||
(?:/usr/bin/env\s+)? # optional /usr/bin/env
|
||||
(?<interpreter>\S+) # interpreter
|
||||
}xm;
|
||||
|
||||
return $+{interpreter};
|
||||
}
|
||||
|
||||
sub process_file {
|
||||
my ( $file, $filename, $interpreter ) = @_;
|
||||
use v5.10.1;
|
||||
|
||||
if ( $interpreter =~ m{/bin/sh} ) {
|
||||
subtest $filename => sub {
|
||||
plan tests => 2;
|
||||
ok( check_file_with( [ 'sh', '-n', $file ] ), "sh syntax check" );
|
||||
ok( check_file_with( [ 'checkbashisms', $file ] ),
|
||||
"checkbashisms" );
|
||||
};
|
||||
}
|
||||
elsif ( $interpreter =~ m{/bin/bash} ) {
|
||||
ok( check_file_with( [ 'bash', '-n', $file ] ),
|
||||
$filename . " bash syntax check" );
|
||||
}
|
||||
elsif ( $interpreter =~ m{perl} ) {
|
||||
ok( check_file_with( [ 'perl', '-cw', $file ] ),
|
||||
$filename . " perl syntax check" );
|
||||
}
|
||||
elsif ( $interpreter =~ m{python} ) {
|
||||
ok( check_file_with(
|
||||
[ 'pylint', '--errors-only', '--report=no', $file ]
|
||||
),
|
||||
$filename . " python syntax check"
|
||||
);
|
||||
}
|
||||
elsif ( $interpreter =~ m{php} ) {
|
||||
ok( check_file_with( [ 'php', '-l', $file ] ),
|
||||
$filename . " php syntax check" );
|
||||
}
|
||||
elsif ( $interpreter =~ m{j?ruby} ) {
|
||||
ok( check_file_with( [ 'ruby', '-cw', $file ] ),
|
||||
$filename . " ruby syntax check" );
|
||||
}
|
||||
elsif ( $interpreter =~ m{gawk} ) {
|
||||
ok( check_file_with(
|
||||
[ 'gawk', '--source', "'BEGIN { exit(0) } END { exit(0) }'",
|
||||
'--file', $file
|
||||
]
|
||||
),
|
||||
$filename . " gawk syntax check"
|
||||
);
|
||||
}
|
||||
else {
|
||||
fail( $filename . " unknown interpreter " . $interpreter );
|
||||
}
|
||||
}
|
||||
|
||||
sub check_file_with {
|
||||
my ($check_command) = @_;
|
||||
my ( $stdout, $stderr, $exit ) = capture {
|
||||
system( @{$check_command} );
|
||||
};
|
||||
if ( $exit == 0 ) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
diag($stdout);
|
||||
diag($stderr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
done_testing($num_plugins);
|
Loading…
Reference in New Issue
Block a user