From: Ralf Wildenhues Date: Sun, 18 Oct 2009 10:01:46 +0000 (+0200) Subject: Coverage and fixes for Condition.pm. X-Git-Tag: ng-0.5a~460^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fef9e8391f113bd733d4b3c3be7140d3d14ae91;p=thirdparty%2Fautomake.git Coverage and fixes for Condition.pm. * lib/Automake/Condition.pm (new): Catch common programming errors better by checking type of passed argument before munging them to all be strings through split. * lib/Automake/tests/Condition.pl (test_basics): Also test ->human. (test_merge): New function, test ->merge, ->merge_conds, ->strip. * lib/Automake/tests/Condition-t.pl (test_basics, test_merge): Likewise changes, but including state copies across thread creation. * lib/Automake/tests/Cond2.pl: New test for programming error. * lib/Automake/tests/Cond3.pl: Likewise. * lib/Automake/tests/Makefile.am (TESTS, XFAIL_TESTS): Update. Signed-off-by: Ralf Wildenhues --- diff --git a/ChangeLog b/ChangeLog index 6ae4243b4..a0f652556 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2009-10-18 Ralf Wildenhues + Coverage and fixes for Condition.pm. + * lib/Automake/Condition.pm (new): Catch common programming + errors better by checking type of passed argument before + munging them to all be strings through split. + * lib/Automake/tests/Condition.pl (test_basics): Also test + ->human. + (test_merge): New function, test ->merge, ->merge_conds, + ->strip. + * lib/Automake/tests/Condition-t.pl (test_basics, test_merge): + Likewise changes, but including state copies across thread + creation. + * lib/Automake/tests/Cond2.pl: New test for programming error. + * lib/Automake/tests/Cond3.pl: Likewise. + * lib/Automake/tests/Makefile.am (TESTS, XFAIL_TESTS): Update. + Coverage for Wrap.pm. * lib/Automake/tests/Wrap.pl (@tests): Add test for word with trailing space. diff --git a/lib/Automake/Condition.pm b/lib/Automake/Condition.pm index 276c04abc..5c54b8beb 100644 --- a/lib/Automake/Condition.pm +++ b/lib/Automake/Condition.pm @@ -180,18 +180,21 @@ sub new ($;@) }; bless $self, $class; - # Accept strings like "FOO BAR" as shorthand for ("FOO", "BAR"). - @conds = map { split (' ', $_) } @conds; - for my $cond (@conds) { - next if $cond eq 'TRUE'; - # Catch some common programming errors: # - A Condition passed to new confess "`$cond' is a reference, expected a string" if ref $cond; # - A Condition passed as a string to new confess "`$cond' does not look like a condition" if $cond =~ /::/; + } + + # Accept strings like "FOO BAR" as shorthand for ("FOO", "BAR"). + @conds = map { split (' ', $_) } @conds; + + for my $cond (@conds) + { + next if $cond eq 'TRUE'; # Detect cases when @conds can be simplified to FALSE. if (($cond eq 'FALSE' && $#conds > 0) diff --git a/lib/Automake/tests/Cond2.pl b/lib/Automake/tests/Cond2.pl new file mode 100644 index 000000000..4ad0e1c4d --- /dev/null +++ b/lib/Automake/tests/Cond2.pl @@ -0,0 +1,6 @@ +# Catch common programming error: +# A Condition passed as a string to 'new'. +use Automake::Condition; + +my $cond = new Automake::Condition ('TRUE'); +new Automake::Condition ($cond); diff --git a/lib/Automake/tests/Cond3.pl b/lib/Automake/tests/Cond3.pl new file mode 100644 index 000000000..dc957af28 --- /dev/null +++ b/lib/Automake/tests/Cond3.pl @@ -0,0 +1,6 @@ +# Catch common programming error: +# A Condition passed as a string to 'new'. +use Automake::Condition; + +my $cond = new Automake::Condition ("COND1_TRUE"); +new Automake::Condition ("$cond"); diff --git a/lib/Automake/tests/Condition-t.pl b/lib/Automake/tests/Condition-t.pl index 0f1dde815..99004acf2 100644 --- a/lib/Automake/tests/Condition-t.pl +++ b/lib/Automake/tests/Condition-t.pl @@ -34,15 +34,15 @@ use Automake::Condition qw/TRUE FALSE/; sub test_basics () { - my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string] - [[], 1, 0, 'TRUE', ''], - [['TRUE'], 1, 0, 'TRUE', ''], - [['FALSE'], 0, 1, 'FALSE', '#'], - [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@'], + my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string, human] + [[], 1, 0, 'TRUE', '', 'TRUE'], + [['TRUE'], 1, 0, 'TRUE', '', 'TRUE'], + [['FALSE'], 0, 1, 'FALSE', '#', 'FALSE'], + [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@', 'A'], [['A_TRUE', 'B_FALSE'], - 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@'], - [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#'], - [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#']); + 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@', 'A and !B'], + [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#', 'FALSE'], + [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#', 'FALSE']); for (@tests) { @@ -55,6 +55,7 @@ sub test_basics () return 1 if $_->[2] != ($a == FALSE); return 1 if $_->[3] ne $a->string; return 1 if $_->[4] ne $a->subst_string; + return 1 if $_->[5] ne $a->human; })->join; } return 0; @@ -283,7 +284,33 @@ sub test_reduce_or () return $failed; } -exit (test_basics || test_true_when || test_reduce_and || test_reduce_or); +sub test_merge () +{ + my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE"; + return threads->new(sub { + my $other = new Automake::Condition "COND3_FALSE"; + return threads->new(sub { + my $both = $cond->merge ($other); + return threads->new(sub { + my $both2 = $cond->merge_conds ("COND3_FALSE"); + return threads->new(sub { + $cond = $both->strip ($other); + my @conds = $cond->conds; + return 1 if $both->string ne "COND1_TRUE COND2_FALSE COND3_FALSE"; + return 1 if $cond->string ne "COND1_TRUE COND2_FALSE"; + return 1 if $both != $both2; + })->join; + })->join; + })->join; + })->join; + return 0; +} + +exit (test_basics + || test_true_when + || test_reduce_and + || test_reduce_or + || test_merge); ### Setup "GNU" style for perl-mode and cperl-mode. ## Local Variables: diff --git a/lib/Automake/tests/Condition.pl b/lib/Automake/tests/Condition.pl index 86f174564..e330e5330 100644 --- a/lib/Automake/tests/Condition.pl +++ b/lib/Automake/tests/Condition.pl @@ -1,4 +1,4 @@ -# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +# Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. # # This file is part of GNU Automake. # @@ -19,15 +19,15 @@ use Automake::Condition qw/TRUE FALSE/; sub test_basics () { - my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string] - [[], 1, 0, 'TRUE', ''], - [['TRUE'], 1, 0, 'TRUE', ''], - [['FALSE'], 0, 1, 'FALSE', '#'], - [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@'], + my @tests = (# [[Conditions], is_true?, is_false?, string, subst-string, human] + [[], 1, 0, 'TRUE', '', 'TRUE'], + [['TRUE'], 1, 0, 'TRUE', '', 'TRUE'], + [['FALSE'], 0, 1, 'FALSE', '#', 'FALSE'], + [['A_TRUE'], 0, 0, 'A_TRUE', '@A_TRUE@', 'A'], [['A_TRUE', 'B_FALSE'], - 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@'], - [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#'], - [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#']); + 0, 0, 'A_TRUE B_FALSE', '@A_TRUE@@B_FALSE@', 'A and !B'], + [['B_TRUE', 'FALSE'], 0, 1, 'FALSE', '#', 'FALSE'], + [['B_TRUE', 'B_FALSE'], 0, 1, 'FALSE', '#', 'FALSE']); for (@tests) { @@ -38,6 +38,7 @@ sub test_basics () return 1 if $_->[2] != ($a == FALSE); return 1 if $_->[3] ne $a->string; return 1 if $_->[4] ne $a->subst_string; + return 1 if $_->[5] ne $a->human; } return 0; } @@ -240,7 +241,25 @@ sub test_reduce_or () return $failed; } -exit (test_basics || test_true_when || test_reduce_and || test_reduce_or); +sub test_merge () +{ + my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE"; + my $other = new Automake::Condition "COND3_FALSE"; + my $both = $cond->merge ($other); + my $both2 = $cond->merge_conds ("COND3_FALSE"); + $cond = $both->strip ($other); + my @conds = $cond->conds; + return 1 if $both->string ne "COND1_TRUE COND2_FALSE COND3_FALSE"; + return 1 if $cond->string ne "COND1_TRUE COND2_FALSE"; + return 1 if $both != $both2; + return 0; +} + +exit (test_basics + || test_true_when + || test_reduce_and + || test_reduce_or + || test_merge); ### Setup "GNU" style for perl-mode and cperl-mode. ## Local Variables: diff --git a/lib/Automake/tests/Makefile.am b/lib/Automake/tests/Makefile.am index 19d100fa6..cb5ed1ab7 100644 --- a/lib/Automake/tests/Makefile.am +++ b/lib/Automake/tests/Makefile.am @@ -22,6 +22,8 @@ TEST_EXTENSIONS = .pl TESTS = \ Condition.pl \ Condition-t.pl \ +Cond2.pl \ +Cond3.pl \ DisjConditions.pl \ DisjConditions-t.pl \ Version.pl \ @@ -30,6 +32,8 @@ Version3.pl \ Wrap.pl XFAIL_TESTS = \ +Cond2.pl \ +Cond3.pl \ Version2.pl \ Version3.pl diff --git a/lib/Automake/tests/Makefile.in b/lib/Automake/tests/Makefile.in index 2e38ba5e8..6402adeb1 100644 --- a/lib/Automake/tests/Makefile.in +++ b/lib/Automake/tests/Makefile.in @@ -228,6 +228,8 @@ TEST_EXTENSIONS = .pl TESTS = \ Condition.pl \ Condition-t.pl \ +Cond2.pl \ +Cond3.pl \ DisjConditions.pl \ DisjConditions-t.pl \ Version.pl \ @@ -236,6 +238,8 @@ Version3.pl \ Wrap.pl XFAIL_TESTS = \ +Cond2.pl \ +Cond3.pl \ Version2.pl \ Version3.pl