2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

improve output and disable python checks for now

This commit is contained in:
Stig Sandbeck Mathisen 2014-10-04 23:52:40 +02:00
parent 673303f127
commit 9b01da77ba

127
t/test.t
View File

@ -47,69 +47,117 @@ sub process_file {
if ( $interpreter =~ m{/bin/sh} ) { if ( $interpreter =~ m{/bin/sh} ) {
subtest $filename => sub { subtest $filename => sub {
plan tests => 2; plan tests => 2;
ok( check_file_with( [ 'sh', '-n', $file ] ), "sh syntax check" ); run_check(
ok( check_file_with( [ 'checkbashisms', $file ] ), { command => [ 'sh', '-n', $file ],
"checkbashisms" ); description => 'sh syntax check'
}
);
run_check(
{ command => [ 'checkbashisms', $file ],
description => 'checkbashisms'
}
);
}; };
} }
elsif ( $interpreter =~ m{/bin/ksh} ) { elsif ( $interpreter =~ m{/bin/ksh} ) {
ok( check_file_with( [ 'ksh', '-n', $file ] ), run_check(
$filename . " ksh syntax check" ); { command => [ 'ksh', '-n', $file ],
description => 'ksh syntax check',
filename => $filename
} }
elsif ( $interpreter =~ m{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', '--rcfile=/dev/null',
'--errors-only', '--report=no',
$file
]
),
$filename . " python syntax check"
); );
} }
elsif ( $interpreter =~ m{bash} ) {
run_check(
{ command => [ 'bash', '-n', $file ],
description => 'bash syntax check',
filename => $filename
}
);
}
elsif ( $interpreter =~ m{perl} ) {
run_check(
{ command => [ 'perl', '-cw', $file ],
description => 'perl syntax check',
filename => $filename
}
);
}
elsif ( $interpreter =~ m{python} ) {
SKIP: {
skip 'need better syntax check for python', 1;
run_check(
{ command => [
'pylint', '--rcfile=/dev/null',
'--errors-only', '--report=no',
$file
],
description => 'python syntax check',
filename => $filename
}
);
}
}
elsif ( $interpreter =~ m{php} ) { elsif ( $interpreter =~ m{php} ) {
ok( check_file_with( [ 'php', '-l', $file ] ), run_check(
$filename . " php syntax check" ); { command => [ 'php', '-l', $file ],
description => 'php syntax check',
filename => $filename
}
);
} }
elsif ( $interpreter =~ m{j?ruby} ) { elsif ( $interpreter =~ m{j?ruby} ) {
ok( check_file_with( [ 'ruby', '-cw', $file ] ), run_check(
$filename . " ruby syntax check" ); { command => [ 'ruby', '-cw', $file ],
description => 'ruby syntax check',
filename => $filename
}
);
} }
elsif ( $interpreter =~ m{gawk} ) { elsif ( $interpreter =~ m{gawk} ) {
ok( check_file_with( run_check(
[ 'gawk', '--source', 'BEGIN { exit(0) } END { exit(0) }', { command => [
'gawk', '--source', 'BEGIN { exit(0) } END { exit(0) }',
'--file', $file '--file', $file
] ],
), description => 'gawk syntax check',
$filename . " gawk syntax check" filename => $filename
}
); );
} }
elsif ( $interpreter =~ m{expect} ) { elsif ( $interpreter =~ m{expect} ) {
pass( SKIP: {
"No idea how to check expect scripts, pretending everything is ok" skip 'no idea how to check expect scripts', 1;
); pass("No pretending everything is ok");
}
} }
else { else {
fail( $filename . " unknown interpreter " . $interpreter ); fail( $filename . " unknown interpreter " . $interpreter );
} }
} }
sub check_file_with { sub run_check {
my ($check_command) = @_; my ($args) = @_;
my $check_command = $args->{command};
my $description = $args->{description};
my $filename = $args->{filename};
my $message;
if ($filename) {
$message = sprintf( '%s: %s', $filename, $description );
}
else {
$message = $description;
}
my ( $stdout, $stderr, $exit ) = capture { my ( $stdout, $stderr, $exit ) = capture {
system( @{$check_command} ); system( @{$check_command} );
}; };
if ( $exit == 0 ) {
return 1; ok( ( $exit == 0 ), $message );
}
else { if ($exit) {
diag( diag(
sprintf( sprintf(
"\nCommand: %s\n\nSTDOUT:\n\n%s\n\nSTDERR:\n\n%s\n\n", "\nCommand: %s\n\nSTDOUT:\n\n%s\n\nSTDERR:\n\n%s\n\n",
@ -117,7 +165,6 @@ sub check_file_with {
$stdout, $stderr $stdout, $stderr
) )
); );
return;
} }
} }