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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
use strict;
use warnings;
use Test::Builder::Tester;
use Test::More 0.95;
use Test::File;
require "t/setup_common";
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
my $file = 'min_file';
my $contents = do { open FH, $file; local $/; <FH> }; close FH;
my $pattern1 = 'x' x 11; $pattern1 = qr/(?mx:^ $pattern1 $)/;
my $pattern2 = 'x' x 40; $pattern2 = qr/(?mx:^ $pattern2 $)/;
my $bad_pattern = 'x' x 20; $bad_pattern = qr/(?mx:^ $bad_pattern $)/;
# like : single pattern
test_out( "ok 1 - min_file contains $pattern1" );
file_contains_like( $file, $pattern1 );
test_test();
test_out( "not ok 1 - bmoogle contains $pattern1" );
test_diag( 'File [bmoogle] does not exist!' );
test_fail(+1);
file_contains_like( 'bmoogle', $pattern1 );
test_test();
SKIP: {
skip "Superuser has special privileges", 1, if( $> == 0 or $< == 0 );
test_out( "not ok 1 - not_readable contains $pattern1" );
test_diag( 'File [not_readable] is not readable!' );
test_fail(+1);
file_contains_like( 'not_readable', $pattern1 );
test_test();
}
test_out( "not ok 1 - min_file contains $bad_pattern" );
test_fail(+2);
like_diag($contents, $bad_pattern, "doesn't match");
file_contains_like( 'min_file', $bad_pattern );
test_test();
# unlike : single pattern
test_out( "ok 1 - min_file doesn't contain $bad_pattern" );
file_contains_unlike( $file, $bad_pattern );
test_test();
test_out( "not ok 1 - bmoogle doesn't contain $bad_pattern" );
test_diag( 'File [bmoogle] does not exist!' );
test_fail(+1);
file_contains_unlike( 'bmoogle', $bad_pattern );
test_test();
SKIP: {
skip "Superuser has special privileges", 1, if( $> == 0 or $< == 0 );
test_out( "not ok 1 - not_readable doesn't contain $bad_pattern" );
test_diag( 'File [not_readable] is not readable!' );
test_fail(+1);
file_contains_unlike( 'not_readable', $bad_pattern );
test_test();
}
test_out( "not ok 1 - min_file doesn't contain $pattern1" );
test_fail(+2);
like_diag($contents, $pattern1, "matches");
file_contains_unlike( 'min_file', $pattern1 );
test_test();
# like : multiple patterns
test_out( "ok 1 - min_file contains $pattern1" );
test_out( "ok 2 - min_file contains $pattern2" );
file_contains_like( $file, [ $pattern1, $pattern2 ] );
test_test();
test_out( "ok 1 - file has the goods" );
test_out( "ok 2 - file has the goods" );
file_contains_like( $file, [ $pattern1, $pattern2 ], 'file has the goods' );
test_test();
test_out( "not ok 1 - bmoogle contains $pattern1" );
test_diag( 'File [bmoogle] does not exist!' );
test_fail(+1);
file_contains_like( 'bmoogle', [ $pattern1, $pattern2 ] );
test_test();
SKIP: {
skip "Superuser has special privileges", 1, if( $> == 0 or $< == 0 );
test_out( "not ok 1 - not_readable contains $pattern1" );
test_diag( 'File [not_readable] is not readable!' );
test_fail(+1);
file_contains_like( 'not_readable', [ $pattern1, $pattern2 ] );
test_test();
}
test_out( "ok 1 - min_file contains $pattern1" );
test_out( "not ok 2 - min_file contains $bad_pattern" );
test_fail(+2);
like_diag($contents, $bad_pattern, "doesn't match");
file_contains_like( 'min_file', [ $pattern1, $bad_pattern ] );
test_test();
# unlike : multiple patterns
test_out( "ok 1 - min_file doesn't contain $bad_pattern" );
test_out( "ok 2 - min_file doesn't contain $bad_pattern" );
file_contains_unlike( $file, [ $bad_pattern, $bad_pattern ] );
test_test();
test_out( "ok 1 - file has the goods" );
test_out( "ok 2 - file has the goods" );
file_contains_unlike( $file, [ $bad_pattern, $bad_pattern ], 'file has the goods' );
test_test();
test_out( "not ok 1 - bmoogle doesn't contain $bad_pattern" );
test_diag( 'File [bmoogle] does not exist!' );
test_fail(+1);
file_contains_unlike( 'bmoogle', [ $bad_pattern, $bad_pattern ] );
test_test();
SKIP: {
skip "Superuser has special privileges", 1, if( $> == 0 or $< == 0 );
test_out( "not ok 1 - not_readable doesn't contain $bad_pattern" );
test_diag( 'File [not_readable] is not readable!' );
test_fail(+1);
file_contains_unlike( 'not_readable', [ $bad_pattern, $bad_pattern ] );
test_test();
}
test_out( "ok 1 - min_file doesn't contain $bad_pattern" );
test_out( "not ok 2 - min_file doesn't contain $pattern1" );
test_fail(+2);
like_diag($contents, $pattern1, "matches");
file_contains_unlike( 'min_file', [ $bad_pattern, $pattern1 ] );
test_test();
done_testing();
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
sub like_diag
{
my ($string, $pattern, $verb) = @_;
my $diag = ' ' x 18 . "'$string'\n";
$diag .= sprintf("%17s '%s'", $verb, $pattern);
$diag =~ s/^/# /mg;
test_err($diag);
}
|