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
|
#!/usr/bin/perl
# Formal testing for CSS::Tiny
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use Test::More tests => 7;
my $new_called = 0;
# This won't work if a testing module uses Clone
SKIP: {
skip( "Clone unexpectedly already in use", 13 ) if $INC{'Clone.pm'};
# Create the broken fake Clone
$INC{'Clone.pm'} = "FAKED";
$Clone::VERSION = '10';
*Clone::import = sub {
die "Clone is busted";
};
# Get rid of some spurious warnings
*main::foo = *Clone::import;
# Loads ok when Clone busted?
use_ok('CSS::Tiny');
# Replace the new sub with one that signals it was called
sub mynew {
$new_called = 1;
return bless {}, shift;
}
*CSS::Tiny::new = *mynew;
*main::foo = *CSS::Tiny::new;
# Retry some tests to make sure the fake new works the same
# Test trivial creation
my $Trivial = CSS::Tiny->new();
isa_ok( $Trivial, 'CSS::Tiny' );
ok( scalar keys %$Trivial == 0, '->new returns an empty object' );
# Try to read in a config
my $Config = CSS::Tiny->read( 'test.css' );
isa_ok( $Config, 'CSS::Tiny' );
# Repeat the clone tests from 02_main.t
$new_called = 0;
my $copy = $Config->clone;
isa_ok( $copy, 'CSS::Tiny' );
is_deeply( $copy, $Config, '->clone works as expected' );
is( $new_called, 1, 'The inline ->clone was used as expected' );
}
|