automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] t/pm: Use Test::Simple for Perl tests


From: Matthias Paulmier
Subject: [PATCH] t/pm: Use Test::Simple for Perl tests
Date: Wed, 05 Sep 2018 22:56:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)


This patch enables the use of the Test::Simple (and Test::More) library
for the Perl lib tests.  One point that may need reflexion is wether or
not to keep the "old" way of testing Perl libraries into Automake (that
is without using Test::Simple/More).

This patch is part of my GSoC project.  I am sorry it took so long and
will make sure to submit the rest of my modifications in the comming days.

--
Matthias Paulmier
>From b0a682a918242b3a74147cd60aadf4e543eb5ce0 Mon Sep 17 00:00:00 2001
From: Matthias Paulmier <address@hidden>
Date: Thu, 30 Aug 2018 16:30:19 +0200
Subject: [PATCH] t/pm: Use Test::Simple for the tests of the Perl libraries

This allows to have more tests using the TAP protocol for tests.  We can also
use other libraries such as Test::More.  For these tests, we use a new
extension (.plt) for those tests.  This change does not exclude the "old" way
of doing things as the .pl extension still exists in t/local.mk in case
someone wants to test the old way.

* t/pm: Use eval to fix fail XFAIL perl test and catch fatal errors.
* t/pm: Regroup tests by module (consequence of the above).
* t/pm: Add a new extension for Perl tests using Test::Simple (.plt).
* t/pm: Move all current tests to the .plt extension.
* lib/Automake: Move END to its own submodule to fix a termination bug with
  Test::Simple where STDOUT was closed and then reopened.
---
 bin/aclocal.in                                |   1 +
 bin/automake.in                               |   1 +
 lib/Automake/End.pm                           |  47 +++++++
 lib/Automake/General.pm                       |  24 +---
 lib/Automake/local.mk                         |   1 +
 t/list-of-tests.mk                            |  33 ++---
 t/local.mk                                    |   4 +-
 t/pm/Cond2.pl                                 |  22 ----
 t/pm/Cond3.pl                                 |  22 ----
 t/pm/{Condition-t.pl => Condition-t.plt}      |  12 +-
 t/pm/{Condition.pl => Condition.plt}          |  34 ++++-
 t/pm/DisjCon2.pl                              |  24 ----
 t/pm/DisjCon3.pl                              |  23 ----
 ...sjConditions-t.pl => DisjConditions-t.plt} |  12 +-
 .../{DisjConditions.pl => DisjConditions.plt} |  36 +++++-
 t/pm/{General.pl => General.plt}              |  10 +-
 t/pm/Version.pl                               | 112 ----------------
 t/pm/Version.plt                              | 122 ++++++++++++++++++
 t/pm/Version2.pl                              |  20 ---
 t/pm/Version3.pl                              |  20 ---
 t/pm/{Wrap.pl => Wrap.plt}                    |  23 ++--
 21 files changed, 277 insertions(+), 326 deletions(-)
 mode change 100644 => 100755 bin/aclocal.in
 create mode 100644 lib/Automake/End.pm
 delete mode 100644 t/pm/Cond2.pl
 delete mode 100644 t/pm/Cond3.pl
 rename t/pm/{Condition-t.pl => Condition-t.plt} (96%)
 rename t/pm/{Condition.pl => Condition.plt} (90%)
 delete mode 100644 t/pm/DisjCon2.pl
 delete mode 100644 t/pm/DisjCon3.pl
 rename t/pm/{DisjConditions-t.pl => DisjConditions-t.plt} (97%)
 rename t/pm/{DisjConditions.pl => DisjConditions.plt} (93%)
 rename t/pm/{General.pl => General.plt} (84%)
 delete mode 100644 t/pm/Version.pl
 create mode 100644 t/pm/Version.plt
 delete mode 100644 t/pm/Version2.pl
 delete mode 100644 t/pm/Version3.pl
 rename t/pm/{Wrap.pl => Wrap.plt} (77%)

diff --git a/bin/aclocal.in b/bin/aclocal.in
old mode 100644
new mode 100755
index 722affa55..09d8b89de
--- a/bin/aclocal.in
+++ b/bin/aclocal.in
@@ -34,6 +34,7 @@ use Automake::Channels;
 use Automake::ChannelDefs;
 use Automake::XFile;
 use Automake::FileUtils;
+use Automake::End;
 use File::Basename;
 use File::Path ();
 
diff --git a/bin/automake.in b/bin/automake.in
index b4ae8f43f..8c783074b 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -55,6 +55,7 @@ use Automake::XFile;
 use Automake::Channels;
 use Automake::ChannelDefs;
 use Automake::Configure_ac;
+use Automake::End;
 use Automake::FileUtils;
 use Automake::Location;
 use Automake::Condition qw/TRUE FALSE/;
diff --git a/lib/Automake/End.pm b/lib/Automake/End.pm
new file mode 100644
index 000000000..7946d814b
--- /dev/null
+++ b/lib/Automake/End.pm
@@ -0,0 +1,47 @@
+# Copyright (C) 2018 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+package Automake::End;
+
+use Exporter;
+use File::Basename;
+
+use vars (@ISA, @EXPORT);
+
address@hidden = qw (Exporter);
address@hidden = qw ($me);
+
+# Variable we share with the main package.  Be sure to have a single
+# copy of them: using 'my' together with multiple inclusion of this
+# package would introduce several copies.
+use vars qw ($me);
+$me = basename ($0);
+
+# END
+# ---
+# Exit nonzero whenever closing STDOUT fails.
+sub END
+{
+  # This is required if the code might send any output to stdout
+  # E.g., even --version or --help.  So it's best to do it unconditionally.
+  if (! close STDOUT)
+    {
+      print STDERR "$me: closing standard output: $!\n";
+      $? = 74; # EX_IOERR
+      return;
+    }
+}
+
+1;
diff --git a/lib/Automake/General.pm b/lib/Automake/General.pm
index aa2de38b8..646608552 100644
--- a/lib/Automake/General.pm
+++ b/lib/Automake/General.pm
@@ -23,29 +23,7 @@ use File::Basename;
 use vars qw (@ISA @EXPORT);
 
 @ISA = qw (Exporter);
address@hidden = qw (&uniq &none $me);
-
-# Variable we share with the main package.  Be sure to have a single
-# copy of them: using 'my' together with multiple inclusion of this
-# package would introduce several copies.
-use vars qw ($me);
-$me = basename ($0);
-
-# END
-# ---
-# Exit nonzero whenever closing STDOUT fails.
-sub END
-{
-  # This is required if the code might send any output to stdout
-  # E.g., even --version or --help.  So it's best to do it unconditionally.
-  if (! close STDOUT)
-    {
-      print STDERR "$me: closing standard output: $!\n";
-      $? = 74; # EX_IOERR
-      return;
-    }
-}
-
address@hidden = qw (uniq none);
 
 # @RES
 # uniq (@LIST)
diff --git a/lib/Automake/local.mk b/lib/Automake/local.mk
index fbb21f3f1..75cfda75c 100644
--- a/lib/Automake/local.mk
+++ b/lib/Automake/local.mk
@@ -26,6 +26,7 @@ dist_perllib_DATA = \
   %D%/Condition.pm \
   %D%/Configure_ac.pm \
   %D%/DisjConditions.pm \
+  %D%/End.pm \
   %D%/FileUtils.pm \
   %D%/General.pm \
   %D%/Getopt.pm \
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index 84dd29af0..c1ad773a9 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -17,16 +17,6 @@
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
-# FIXME: this "expected failures" are in truth an hack used to
-# FIXME: to verify that some incorrect usages of our perl libraries
-# FIXME: raise an error.  We should find a cleaner way to check that.
-perl_fake_XFAIL_TESTS = \
-t/pm/Cond2.pl \
-t/pm/Cond3.pl \
-t/pm/DisjCon2.pl \
-t/pm/DisjCon3.pl \
-t/pm/Version2.pl \
-t/pm/Version3.pl
 
 XFAIL_TESTS = \
 t/all.sh \
@@ -42,23 +32,16 @@ t/objext-pr10128.sh \
 t/remake-timing-bug-pr8365.sh \
 t/lex-subobj-nodep.sh \
 t/remake-am-pr10111.sh \
-t/remake-m4-pr10111.sh \
-$(perl_fake_XFAIL_TESTS)
+t/remake-m4-pr10111.sh
 
 perl_TESTS = \
-t/pm/Cond2.pl \
-t/pm/Cond3.pl \
-t/pm/Condition.pl \
-t/pm/Condition-t.pl \
-t/pm/DisjCon2.pl \
-t/pm/DisjCon3.pl \
-t/pm/DisjConditions.pl \
-t/pm/DisjConditions-t.pl \
-t/pm/General.pl \
-t/pm/Version.pl \
-t/pm/Version2.pl \
-t/pm/Version3.pl \
-t/pm/Wrap.pl
+t/pm/Condition.plt \
+t/pm/Condition-t.plt \
+t/pm/DisjConditions.plt \
+t/pm/DisjConditions-t.plt \
+t/pm/General.plt \
+t/pm/Version.plt \
+t/pm/Wrap.plt
 
 perf_TESTS = \
 t/perf/cond.sh \
diff --git a/t/local.mk b/t/local.mk
index 0d0aee6ad..14b3e61b3 100644
--- a/t/local.mk
+++ b/t/local.mk
@@ -21,13 +21,15 @@
 # Run the tests with a proper shell detected at configure time.
 LOG_COMPILER = ./pre-inst-env $(AM_TEST_RUNNER_SHELL)
 
-TEST_EXTENSIONS = .pl .sh .tap
+TEST_EXTENSIONS = .pl .plt .sh .tap
 SH_LOG_COMPILER = $(LOG_COMPILER)
 TAP_LOG_COMPILER = $(LOG_COMPILER)
 PL_LOG_COMPILER = ./pre-inst-env $(PERL)
+PLT_LOG_COMPILER = $(PL_LOG_COMPILER)
 AM_PL_LOG_FLAGS = -Mstrict -w
 
 TAP_LOG_DRIVER = AM_TAP_AWK='$(AWK)' $(SHELL) $(srcdir)/lib/tap-driver.sh
+PLT_LOG_DRIVER = $(TAP_LOG_DRIVER)
 
 AM_TAP_LOG_DRIVER_FLAGS = --merge
 
diff --git a/t/pm/Cond2.pl b/t/pm/Cond2.pl
deleted file mode 100644
index f586a67b9..000000000
--- a/t/pm/Cond2.pl
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright (C) 2011-2018 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-# 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/t/pm/Cond3.pl b/t/pm/Cond3.pl
deleted file mode 100644
index 769d01b9a..000000000
--- a/t/pm/Cond3.pl
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright (C) 2011-2018 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-# 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/t/pm/Condition-t.pl b/t/pm/Condition-t.plt
similarity index 96%
rename from t/pm/Condition-t.pl
rename to t/pm/Condition-t.plt
index 18d30eaf0..364230d82 100644
--- a/t/pm/Condition-t.pl
+++ b/t/pm/Condition-t.plt
@@ -1,3 +1,4 @@
+# -*- mode:perl -*-
 # Copyright (C) 2001-2018 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -28,6 +29,7 @@ BEGIN {
     }
 }
 use Automake::Condition qw/TRUE FALSE/;
+use Test::Simple tests => 5;
 
 sub test_basics ()
 {
@@ -303,8 +305,8 @@ sub test_merge ()
   return 0;
 }
 
-exit (test_basics
-      || test_true_when
-      || test_reduce_and
-      || test_reduce_or
-      || test_merge);
+ok (test_basics == 0, 'Test basic conditions');
+ok (test_true_when == 0, 'Test implied conditions when declaring a new one');
+ok (test_reduce_and == 0, 'Test "and" reduction');
+ok (test_reduce_or == 0, 'Test "or" reduction');
+ok (test_merge == 0, 'Test the merge method');
diff --git a/t/pm/Condition.pl b/t/pm/Condition.plt
similarity index 90%
rename from t/pm/Condition.pl
rename to t/pm/Condition.plt
index 21021b555..c019b5fdc 100644
--- a/t/pm/Condition.pl
+++ b/t/pm/Condition.plt
@@ -1,3 +1,4 @@
+# -*- mode:perl -*-
 # Copyright (C) 2001-2018 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -14,6 +15,7 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 use Automake::Condition qw/TRUE FALSE/;
+use Test::Simple tests => 6;
 
 sub test_basics ()
 {
@@ -253,8 +255,30 @@ sub test_merge ()
   return 0;
 }
 
-exit (test_basics
-      || test_true_when
-      || test_reduce_and
-      || test_reduce_or
-      || test_merge);
+sub test_bad_declarations ()
+{
+  my $failed = 0;
+
+  # Catch error:
+  # A condition object passed to 'new'
+  my $cond1 = new Automake::Condition ('TRUE');
+  eval { new Automake::Condition ($cond1) };
+
+  $failed = 1 unless $@;
+  $@ = '';
+
+  # Catch common programming error:
+  # A Condition passed as a string to 'new'.
+  my $cond2 = new Automake::Condition ("COND1_TRUE");
+  eval { new Automake::Condition ("$cond2") };
+
+  $failed = 1 unless $@;
+  return $failed;
+}
+
+ok (test_basics == 0, 'Test basic conditions');
+ok (test_true_when == 0, 'Test implied conditions when declaring a new one');
+ok (test_reduce_and == 0, 'Test "and" reduction');
+ok (test_reduce_or == 0, 'Test "or" reduction');
+ok (test_merge == 0, 'Test the merge method');
+ok (test_bad_declarations == 0, 'Test bad condition declarations');
diff --git a/t/pm/DisjCon2.pl b/t/pm/DisjCon2.pl
deleted file mode 100644
index e5f204db6..000000000
--- a/t/pm/DisjCon2.pl
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright (C) 2011-2018 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-# Catch common programming error:
-# A non-Condition reference passed to new.
-
-use Automake::Condition;
-use Automake::DisjConditions;
-
-my $cond = new Automake::Condition ('TRUE');
-my $cond2 = new Automake::DisjConditions ($cond);
-new Automake::DisjConditions ($cond2);
diff --git a/t/pm/DisjCon3.pl b/t/pm/DisjCon3.pl
deleted file mode 100644
index cc1f467fd..000000000
--- a/t/pm/DisjCon3.pl
+++ /dev/null
@@ -1,23 +0,0 @@
-# Copyright (C) 2011-2018 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-# Catch common programming error:
-# A non-reference passed to new.
-
-use Automake::Condition qw/TRUE FALSE/;
-use Automake::DisjConditions;
-
-my $cond = new Automake::Condition ("COND1_TRUE");
-new Automake::DisjConditions ("$cond");
diff --git a/t/pm/DisjConditions-t.pl b/t/pm/DisjConditions-t.plt
similarity index 97%
rename from t/pm/DisjConditions-t.pl
rename to t/pm/DisjConditions-t.plt
index 33c6c2d75..976d7a82e 100644
--- a/t/pm/DisjConditions-t.pl
+++ b/t/pm/DisjConditions-t.plt
@@ -1,3 +1,4 @@
+# -*- mode:perl -*-
 # Copyright (C) 2001-2018 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -29,6 +30,7 @@ BEGIN {
 }
 use Automake::Condition qw/TRUE FALSE/;
 use Automake::DisjConditions;
+use Test::Simple tests => 5;
 
 sub test_basics ()
 {
@@ -437,8 +439,8 @@ sub test_ambig ()
   return $failed;
 }
 
-exit (test_basics
-      || test_invert
-      || test_simplify
-      || test_sub_conditions
-      || test_ambig);
+ok (test_basics == 0, 'Basic tests');
+ok (test_invert == 0, 'Test inverts');
+ok (test_simplify == 0, 'Test condition simplifications');
+ok (test_sub_conditions == 0, 'Test sub conditions');
+ok (test_ambig == 0, 'Test ambiguous conditions');
diff --git a/t/pm/DisjConditions.pl b/t/pm/DisjConditions.plt
similarity index 93%
rename from t/pm/DisjConditions.pl
rename to t/pm/DisjConditions.plt
index f4075b0be..c5ec25be0 100644
--- a/t/pm/DisjConditions.pl
+++ b/t/pm/DisjConditions.plt
@@ -1,3 +1,4 @@
+# -*- mode:perl -*-
 # Copyright (C) 2001-2018 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -15,6 +16,7 @@
 
 use Automake::Condition qw/TRUE FALSE/;
 use Automake::DisjConditions;
+use Test::Simple tests => 6;
 
 sub test_basics ()
 {
@@ -380,8 +382,32 @@ sub test_ambig ()
   return 0;
 }
 
-exit (test_basics
-      || test_invert
-      || test_simplify
-      || test_sub_conditions
-      || test_ambig);
+sub test_bad_declarations
+{
+  my $failed;
+  my $cond = new Automake::Condition ('TRUE');
+  my $cond2 = new Automake::DisjConditions ($cond);
+
+  eval { new Automake::DisjConditions ($cond2) };
+
+  warn $@ if $@;
+  $failed = 1 unless $@;
+
+  $@ = '';
+
+  my $cond3 = new Automake::Condition ("COND1_TRUE");
+
+  eval { new Automake::DisjConditions ("$cond3") };
+
+  warn $@ if $@;
+  $failed = 1 unless $@;
+
+  return $failed;
+}
+
+ok (test_basics == 0, 'Basic tests');
+ok (test_invert == 0, 'Test inverts');
+ok (test_simplify == 0, 'Test condition simplifications');
+ok (test_sub_conditions == 0, 'Test sub conditions');
+ok (test_ambig == 0, 'Test ambiguous conditions');
+ok (test_bad_declarations == 0, 'Test wrong condition declarations');
diff --git a/t/pm/General.pl b/t/pm/General.plt
similarity index 84%
rename from t/pm/General.pl
rename to t/pm/General.plt
index 0caefe7cf..645886d9c 100644
--- a/t/pm/General.pl
+++ b/t/pm/General.plt
@@ -1,3 +1,4 @@
+# -*- mode:perl -*-
 # Copyright (C) 2018 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -14,14 +15,11 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 use Automake::General;
-
-my $failed = 0;
+use Test::Simple tests => 2;
 
 # Check 'none'.
 my $none_positive = none { $_[0] < 0 } (1, 7, 3, 8, 9);
-$failed = 1 if ($none_positive == 0);
+ok ($none_positive != 0, 'Test none on positive values');
 
 my $none_gt_8 = none { $_[0] >= 8 } (1, 7, 3, 8, 9);
-$failed = 1 if ($none_gt_8 == 1);
-
-exit $failed;
+ok ($none_gt_8 == 0, 'Test none on values > 8');
diff --git a/t/pm/Version.pl b/t/pm/Version.pl
deleted file mode 100644
index 3177c0361..000000000
--- a/t/pm/Version.pl
+++ /dev/null
@@ -1,112 +0,0 @@
-# Copyright (C) 2002-2018 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-use Automake::Version;
-
-my $failed = 0;
-
-sub test_version_compare
-{
-  my ($left, $right, $result) = @_;
-  my @leftver = Automake::Version::split ($left);
-  my @rightver = Automake::Version::split ($right);
-  if ($#leftver == -1)
-  {
-    print "can't grok \"$left\"\n";
-    $failed = 1;
-    return;
-  }
-  if ($#rightver == -1)
-  {
-    print "can't grok \"$right\"\n";
-    $failed = 1;
-    return;
-  }
-  my $res = Automake::Version::compare (@leftver, @rightver);
-  if ($res != $result)
-  {
-    print "compare (\"$left\", \"$right\") = $res! (not $result?)\n";
-    $failed = 1;
-  }
-
-  my $check_expected = ($result == 0 || $result == 1) ? 0 : 1;
-  # Exception for 'foo' fork.
-  $check_expected = 1
-    if ($right =~ /foo/ && !($left =~ /foo/));
-
-  my $check = Automake::Version::check ($left, $right);
-  if ($check != $check_expected)
-  {
-    print "check (\"$left\", \"$right\") = $check! (not $check_expected?)\n";
-    $failed = 1;
-  }
-}
-
-sub test_bad_versions
-{
-  my ($ver) = @_;
-  my @version = Automake::Version::split ($ver);
-  if ($#version != -1)
-  {
-    print "shouldn't grok \"$ver\"\n";
-    $failed = 1;
-  }
-}
-
-my @tests = (
-# basics
-  ['1.0', '2.0', -1],
-  ['2.0', '1.0', 1],
-  ['1.2', '1.2', 0],
-  ['1.1', '1.2', -1],
-  ['1.2', '1.1', 1],
-# alphas
-  ['1.4', '1.4g', -1],
-  ['1.4g', '1.5', -1],
-  ['1.4g', '1.4', 1],
-  ['1.5', '1.4g', 1],
-  ['1.4a', '1.4g', -1],
-  ['1.5a', '1.3g', 1],
-  ['1.6a', '1.6a', 0],
-# micros
-  ['1.5.1', '1.5', 1],
-  ['1.5.0', '1.5', 0],
-  ['1.5.4', '1.6.1', -1],
-# micros and alphas
-  ['1.5a', '1.5.1', 1],
-  ['1.5a', '1.5.1a', 1],
-  ['1.5a', '1.5.1f', 1],
-  ['1.5', '1.5.1a', -1],
-  ['1.5.1a', '1.5.1f', -1],
-  ['1.5.1f', '1.5.1a', 1],
-  ['1.5.1f', '1.5.1f', 0],
-# special exceptions
-  ['1.6-p5a', '1.6.5a', 0],
-  ['1.6', '1.6-p5a', -1],
-  ['1.6-p4b', '1.6-p5a', -1],
-  ['1.6-p4b', '1.6-foo', 1],
-  ['1.6-p4b', '1.6a-foo', -1],
-  ['1.6-p5', '1.6.5', 0],
-  ['1.6a-foo', '1.6a-foo', 0],
-);
-
-my @bad_versions = (
-  '', 'a', '1', '1a', '1.2.3.4', '-1.2'
-);
-
-test_version_compare (@{$_}) foreach @tests;
-test_bad_versions ($_) foreach @bad_versions;
-
-exit $failed;
diff --git a/t/pm/Version.plt b/t/pm/Version.plt
new file mode 100644
index 000000000..4684453af
--- /dev/null
+++ b/t/pm/Version.plt
@@ -0,0 +1,122 @@
+# -*- mode:perl -*-
+# Copyright (C) 2002-2018 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+use Automake::Version;
+use Test::Simple tests => 34;
+
+sub test_version_compare
+{
+  my ($left, $right, $result) = @_;
+  my @leftver = Automake::Version::split ($left);
+  my @rightver = Automake::Version::split ($right);
+  if ($#leftver == -1)
+  {
+    print "can't grok \"$left\"\n";
+    return 1;
+  }
+  if ($#rightver == -1)
+  {
+    print "can't grok \"$right\"\n";
+    return 1;
+  }
+  my $res = Automake::Version::compare (@leftver, @rightver);
+  if ($res != $result)
+  {
+    print "compare (\"$left\", \"$right\") = $res! (not $result?)\n";
+    return 1;
+  }
+
+  my $check_expected = ($result == 0 || $result == 1) ? 0 : 1;
+  # Exception for 'foo' fork.
+  $check_expected = 1
+    if ($right =~ /foo/ && !($left =~ /foo/));
+
+  my $check = Automake::Version::check ($left, $right);
+  if ($check != $check_expected)
+    {
+      print "check (\"$left\", \"$right\") = $check! (not $check_expected?)\n";
+      return 1;
+    }
+  return 0;
+}
+
+sub test_bad_versions
+{
+  my ($ver) = @_;
+  my @version = Automake::Version::split ($ver);
+  if ($#version != -1)
+    {
+      print "shouldn't grok \"$ver\"\n";
+      return 1;
+    }
+  return 0;
+}
+
+sub test_bad_declarations
+{
+  eval { Automake::Version::check ('', '1.2.3') };
+
+  warn $@ if $@;
+  $failed = 1 unless $@;
+
+  $@ = '';
+
+  eval { Automake::Version::check ('1.2.3', '') };
+
+  warn $@ if $@;
+  return 1 unless $@;
+  return 0;
+}
+
+ok (test_version_compare ('2.0', '1.0', 1) == 0, 'Test comparing versions 
basics 2');
+ok (test_version_compare ('1.2', '1.2', 0) == 0, 'Test comparing versions 
basics 3');
+ok (test_version_compare ('1.1', '1.2', -1) == 0, 'Test comparing versions 
basics 4');
+ok (test_version_compare ('1.2', '1.1', 1) == 0, 'Test comparing versions 
basics 5');
+
+ok (test_version_compare ('1.4', '1.4g', -1) == 0, 'Test comparing versions 
with alphas 1');
+ok (test_version_compare ('1.4g', '1.5', -1) == 0, 'Test comparing versions 
with alphas 2');
+ok (test_version_compare ('1.4g', '1.4', 1) == 0, 'Test comparing versions 
with alphas 3');
+ok (test_version_compare ('1.5', '1.4g', 1) == 0, 'Test comparing versions 
with alphas 4');
+ok (test_version_compare ('1.4a', '1.4g', -1) == 0, 'Test comparing versions 
with alphas 5');
+ok (test_version_compare ('1.5a', '1.3g', 1) == 0, 'Test comparing versions 
with alphas 6');
+ok (test_version_compare ('1.6a', '1.6a', 0) == 0, 'Test comparing versions 
with alphas 7');
+
+ok (test_version_compare ('1.5.1', '1.5', 1) == 0, 'Test comparing versions 
micros 1');
+ok (test_version_compare ('1.5.0', '1.5', 0) == 0, 'Test comparing versions 
micros 2');
+ok (test_version_compare ('1.5.4', '1.6.1', -1) == 0, 'Test comparing versions 
micros 3');
+
+ok (test_version_compare ('1.5a', '1.5.1', 1) == 0, 'Test comparing versions 
micros and alphas 1');
+ok (test_version_compare ('1.5a', '1.5.1a', 1) == 0, 'Test comparing versions 
micros and alphas 2');
+ok (test_version_compare ('1.5a', '1.5.1f', 1) == 0, 'Test comparing versions 
micros and alphas 3');
+ok (test_version_compare ('1.5', '1.5.1a', -1) == 0, 'Test comparing versions 
micros and alphas 4');
+ok (test_version_compare ('1.5.1a', '1.5.1f', -1) == 0, 'Test comparing 
versions micros and alphas 5');
+ok (test_version_compare ('1.5.1f', '1.5.1a', 1) == 0, 'Test comparing 
versions micros and alphas 6');
+ok (test_version_compare ('1.5.1f', '1.5.1f', 0) == 0, 'Test comparing 
versions micros and alphas 7');
+
+ok (test_version_compare ('1.6-p5a', '1.6.5a', 0) == 0, 'Test comparing 
versions special exceptions 1');
+ok (test_version_compare ('1.6', '1.6-p5a', -1) == 0, 'Test comparing versions 
special exceptions 1');
+ok (test_version_compare ('1.6-p4b', '1.6-p5a', -1) == 0, 'Test comparing 
versions special exceptions 1');
+ok (test_version_compare ('1.6-p4b', '1.6-foo', 1) == 0, 'Test comparing 
versions special exceptions 1');
+ok (test_version_compare ('1.6-p4b', '1.6a-foo', -1) == 0, 'Test comparing 
versions special exceptions 1');
+ok (test_version_compare ('1.6-p5', '1.6.5', 0) == 0, 'Test comparing versions 
special exceptions 1');
+ok (test_version_compare ('1.6a-foo', '1.6a-foo', 0) == 0, 'Test comparing 
versions special exceptions 1');
+
+ok (test_bad_versions ('') == 0, 'Test bad version numbers empty str');
+ok (test_bad_versions ('a') == 0, 'Test bad version numbers only alpha');
+ok (test_bad_versions ('1') == 0, 'Test bad version numbers only major');
+ok (test_bad_versions ('1a') == 0, 'Test bad version numbers only major with 
alpha');
+ok (test_bad_versions ('1.2.3.4') == 0, 'Test bad version numbers to many 
minor versions');
+ok (test_bad_versions ('-1.2') == 0, 'Test bad version numbers negative');
diff --git a/t/pm/Version2.pl b/t/pm/Version2.pl
deleted file mode 100644
index d6d0111dd..000000000
--- a/t/pm/Version2.pl
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright (C) 2011-2018 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-# prog_error due to invalid $VERSION.
-
-use Automake::Version;
-
-Automake::Version::check ('', '1.2.3');
diff --git a/t/pm/Version3.pl b/t/pm/Version3.pl
deleted file mode 100644
index f1583c081..000000000
--- a/t/pm/Version3.pl
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright (C) 2011-2018 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-# prog_error due to invalid $REQUIRED.
-
-use Automake::Version;
-
-Automake::Version::check ('1.2.3', '');
diff --git a/t/pm/Wrap.pl b/t/pm/Wrap.plt
similarity index 77%
rename from t/pm/Wrap.pl
rename to t/pm/Wrap.plt
index 995569a4f..fdfdab3bf 100644
--- a/t/pm/Wrap.pl
+++ b/t/pm/Wrap.plt
@@ -1,3 +1,4 @@
+# -*- mode:perl -*-
 # Copyright (C) 2003-2018 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -14,8 +15,7 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 use Automake::Wrap qw/wrap makefile_wrap/;
-
-my $failed = 0;
+use Test::Simple tests => 9;
 
 sub test_wrap
 {
@@ -25,20 +25,21 @@ sub test_wrap
   if ($out ne $exp_out)
     {
       print STDERR "For: @$in\nGot:\n$out\nInstead of:\n$exp_out\n---\n";
-      ++$failed;
+      return 1;
     }
+  return 0;
 }
 
 sub test_makefile_wrap
 {
   my ($in, $exp_out) = @_;
-
   my $out = &makefile_wrap (@$in);
   if ($out ne $exp_out)
     {
       print STDERR "For: @$in\nGot:\n$out\nInstead of:\n$exp_out\n---\n";
-      ++$failed;
+      return 1;
     }
+  return 0;
 }
 
 my @tests = (
@@ -89,7 +90,13 @@ my @makefile_tests = (
 \tunlike in the second line
 "]);
 
-test_wrap (@{$_}) foreach @tests;
-test_makefile_wrap (@{$_}) foreach @makefile_tests;
+ok (test_wrap (@{$tests[0]}) == 0, 'test_wrap 0');
+ok (test_wrap (@{$tests[1]}) == 0, 'test_wrap 1');
+ok (test_wrap (@{$tests[2]}) == 0, 'test_wrap 2');
+ok (test_wrap (@{$tests[3]}) == 0, 'test_wrap 3');
+ok (test_wrap (@{$tests[4]}) == 0, 'test_wrap 4');
 
-exit $failed;
+ok (test_makefile_wrap (@{$makefile_tests[0]}) == 0, 'test_makefile_wrap 0');
+ok (test_makefile_wrap (@{$makefile_tests[1]}) == 0, 'test_makefile_wrap 1');
+ok (test_makefile_wrap (@{$makefile_tests[2]}) == 0, 'test_makefile_wrap 2');
+ok (test_makefile_wrap (@{$makefile_tests[3]}) == 0, 'test_makefile_wrap 3');
-- 
2.18.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]