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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#!/usr/bin/perl
use strict;
use Test::More;
use Dpkg::IPC;
use File::Copy::Recursive 'dircopy';
use File::Path 'remove_tree';
# Prepare tree
remove_tree('test');
ok( dircopy( 't/simple', 'test' ), 'Test directory created' );
chdir 'test';
my $out;
# Main test
spawn(
exec => [qw(add-node-component abab)],
nocheck => 1,
wait_child => 1,
error_to_string => \$out,
);
if ($?) {
fail "add-node-component failed: $out";
}
else {
ok( $out =~ /Components added: abab/s, 'It displays result' );
ok( -e 'debian/gbp.conf', 'gbp.conf created' );
ok( foundStringInFile( 'component\s*=.*abab', 'debian/gbp.conf' ),
'Component added in debian/gbp.conf' );
ok( foundStringInFile( 'component=abab', 'debian/watch' ),
'Component added in debian/watch' );
ok( foundStringInFile( 'https?://.*abab', 'debian/copyright' ),
'Component source added in debian/copyright' );
spawn(
exec => [qw(del-node-component abab)],
nocheck => 1,
wait_child => 1,
error_to_string => \$out,
);
ok( !foundStringInFile( 'component\s*=.*abab', 'debian/gbp.conf' ),
'Component deleted from debian/gbp.conf' );
ok( !foundStringInFile( 'component=abab', 'debian/watch' ),
'Component deleted from debian/watch' );
}
# Banned test
spawn(
exec => [qw(add-node-component cross-spawn)],
nocheck => 1,
wait_child => 1,
error_to_string => \$out,
);
ok( $out =~ /cross-spawn.*banned/m, 'It detects that cross-spawn is banned' );
ok( !foundStringInFile( 'component\s*=.*cross-spawn', 'debian/gbp.conf' ),
'cross-spawn not added in debian/gbp.conf' );
ok( !foundStringInFile( 'component=abab', 'debian/watch' ),
'cross-spawn not added in debian/watch' );
chdir('..');
remove_tree('test');
done_testing();
sub foundStringInFile {
my ( $string, $file ) = @_;
my $f;
open( $f, '<', $file ) or fail($!);
my $found = 0;
while (<$f>) {
$found = 1 if /$string/;
}
close $f;
return $found;
}
|