[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/5] Coverage and fixes for Condition.pm.
From: |
Ralf Wildenhues |
Subject: |
[PATCH 3/5] Coverage and fixes for Condition.pm. |
Date: |
Sun, 18 Oct 2009 17:45:21 +0200 |
User-agent: |
Mutt/1.5.20 (2009-08-09) |
* 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 <address@hidden>
---
This was interesting. I couldn't get the first 'confess' code branch to
ever go off. Took a bit to notice that 'split' turns everything into a
string.
Cheers,
Ralf
ChangeLog | 15 ++++++++++++
lib/Automake/Condition.pm | 13 ++++++----
lib/Automake/tests/Cond2.pl | 6 +++++
lib/Automake/tests/Cond3.pl | 6 +++++
lib/Automake/tests/Condition-t.pl | 45 +++++++++++++++++++++++++++++-------
lib/Automake/tests/Condition.pl | 39 +++++++++++++++++++++++--------
lib/Automake/tests/Makefile.am | 4 +++
lib/Automake/tests/Makefile.in | 4 +++
8 files changed, 108 insertions(+), 24 deletions(-)
create mode 100644 lib/Automake/tests/Cond2.pl
create mode 100644 lib/Automake/tests/Cond3.pl
diff --git a/ChangeLog b/ChangeLog
index 6ae4243..a0f6525 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2009-10-18 Ralf Wildenhues <address@hidden>
+ 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 276c04a..5c54b8b 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 0000000..4ad0e1c
--- /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 0000000..dc957af
--- /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 0f1dde8..99004ac 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 86f1745..e330e53 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 19d100f..cb5ed1a 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 2e38ba5..6402ade 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
--
1.6.5.1.31.gad12b