]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
Modify all tests to use the Test::Simple lib
authorMatthias Paulmier <matt@mpaulmier.home>
Thu, 2 Aug 2018 15:15:24 +0000 (17:15 +0200)
committerMatthias Paulmier <matt@mpaulmier.home>
Thu, 2 Aug 2018 18:21:33 +0000 (20:21 +0200)
All tests now use the Test::Simple library.  We keep the distinction between
pl (pure perl) and plt (perl + Test::Simple) in case someone wants to write a
perl tests without this lib.

- t/pm/*: All tests now use the plt extension and the Test::Simple library.
- t/pm/CondStack.pl: Remove it as it was not well built and the test results
  were false.

14 files changed:
t/list-of-tests.mk
t/pm/Channels.plt [moved from t/pm/Channels.pl with 91% similarity]
t/pm/CondStack.pl [deleted file]
t/pm/Condition-t.plt [moved from t/pm/Condition-t.pl with 96% similarity]
t/pm/Condition.plt [moved from t/pm/Condition.pl with 95% similarity]
t/pm/DisjConditions-t.plt [moved from t/pm/DisjConditions-t.pl with 97% similarity]
t/pm/DisjConditions.plt [moved from t/pm/DisjConditions.pl with 97% similarity]
t/pm/General.plt [moved from t/pm/General.pl with 84% similarity]
t/pm/SilentRules.pl [deleted file]
t/pm/SilentRules.plt [new file with mode: 0644]
t/pm/Utils.plt [moved from t/pm/Utils.pl with 51% similarity]
t/pm/Version.pl [deleted file]
t/pm/Version.plt [new file with mode: 0644]
t/pm/Wrap.plt [moved from t/pm/Wrap.pl with 77% similarity]

index c91bd8c6fbababd30ef93018c997e39e037e4314..c4e3844a0038527104b69f197a371445be43b2f5 100644 (file)
@@ -34,19 +34,17 @@ t/remake-am-pr10111.sh \
 t/remake-m4-pr10111.sh
 
 perl_tap_TESTS = \
-t/pm/File.plt
-
-perl_TESTS = \
-t/pm/Channels.pl \
-t/pm/Condition.pl \
-t/pm/Condition-t.pl \
-t/pm/CondStack.pl \
-t/pm/DisjConditions.pl \
-t/pm/DisjConditions-t.pl \
-t/pm/General.pl \
-t/pm/Utils.pl \
-t/pm/Version.pl \
-t/pm/Wrap.pl
+t/pm/Channels.plt \
+t/pm/Condition.plt \
+t/pm/Condition-t.plt \
+t/pm/DisjConditions.plt \
+t/pm/DisjConditions-t.plt \
+t/pm/File.plt \
+t/pm/General.plt \
+t/pm/SilentRules.plt \
+t/pm/Utils.plt \
+t/pm/Version.plt \
+t/pm/Wrap.plt
 
 perf_TESTS = \
 t/perf/cond.sh \
similarity index 91%
rename from t/pm/Channels.pl
rename to t/pm/Channels.plt
index b7d0b0a194f270e7d24b0c6bd8e4f63839780f84..4014ebf49ba304a5e59c153e4a312c71cdf2fe5e 100644 (file)
@@ -1,3 +1,4 @@
+# -*- mode:perl -*-
 # Copyright (C) 2018  Matthias Paulmier
 
 # This program is free software; you can redistribute it and/or
 
 use Automake::Channels;
 use Automake::Location;
+use Test::Simple tests => 1;
 
 eval { msg ('test-fatal', new Automake::Location ('.'), "Test Message") };
 
 warn $@ if $@;
 
-exit 0 if $@;
-exit 1;
+ok ($@, "Test fatal error");
diff --git a/t/pm/CondStack.pl b/t/pm/CondStack.pl
deleted file mode 100644 (file)
index 5e28e69..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-# 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
-# of the License, 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 <http://www.gnu.org/licenses/>.
-
-use Automake::CondStack;
-use Automake::Condition qw (TRUE FALSE);
-use Automake::Location;
-
-# The different test cases.  What happens with IF alone?
-my @tests = (['IF', 'ELSE', 'ENDIF'],
-            ['ELSE', 'ENDIF'],
-            ['IF', 'ENDIF'],
-            ['ENDIF'],
-            ['IF', 'ELSE', 'IF', 'ELSE', 'ENDIF']);
-
-my @exp_res = (0, 1, 0, 1, 0);
-
-my $where = new Automake::Location "/dev/null:0";
-
-sub test_cond_stack ()
-{
-  my @real_res = ();
-  for (@tests)
-    {
-      # Reset conditional stack for each test case
-      @cond_stack = ();
-      my $res = 0;
-      my $else_called = 0;
-      for my $test (@$_)
-        {
-         if ($test eq 'IF')
-           {
-             cond_stack_if (undef, 'FALSE', $where);
-           }
-         if ($test eq 'ELSE')
-            {
-              $else_called = 1;
-             if (cond_stack_else ('!', 'FALSE', $where) == FALSE)
-               {
-                 $res = 1;
-                 last;
-               }
-           }
-         if ($test eq 'ENDIF')
-            {
-              my $cond = ($else_called ? TRUE : FALSE);
-             if (cond_stack_else (undef, undef, $where) == $cond)
-                {
-                 $res = 1;
-                 last;
-               }
-           }
-        }
-      push @real_res, $res;
-    }
-  print "@real_res\n";
-  print "@exp_res\n";
-  for my $i (0 .. $#exp_res)
-    {
-      return 1 if $real_res[$i] ne $exp_res[$i];
-    }
-  return 0;
-}
-
-exit (test_cond_stack);
similarity index 96%
rename from t/pm/Condition-t.pl
rename to t/pm/Condition-t.plt
index 18d30eaf0d8f7785afedca5e2de8c6c906ede8f9..364230d821071670def923c12a16931198f5f163 100644 (file)
@@ -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');
similarity index 95%
rename from t/pm/Condition.pl
rename to t/pm/Condition.plt
index 58f89b3ae7f5f8da5df6d4af69e9aa3ebd22146d..c019b5fdc848120c515cab5f39bb3f474e84a10b 100644 (file)
@@ -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 ()
 {
@@ -262,7 +264,6 @@ sub test_bad_declarations ()
   my $cond1 = new Automake::Condition ('TRUE');
   eval { new Automake::Condition ($cond1) };
 
-  warn $@ if $@;
   $failed = 1 unless $@;
   $@ = '';
 
@@ -271,14 +272,13 @@ sub test_bad_declarations ()
   my $cond2 = new Automake::Condition ("COND1_TRUE");
   eval { new Automake::Condition ("$cond2") };
 
-  warn $@ if $@;
   $failed = 1 unless $@;
   return $failed;
 }
 
-exit (test_basics
-      || test_true_when
-      || test_reduce_and
-      || test_reduce_or
-      || test_merge
-      || test_bad_declarations);
+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');
similarity index 97%
rename from t/pm/DisjConditions-t.pl
rename to t/pm/DisjConditions-t.plt
index 33c6c2d7569fa73d157586239f6a7286fe863948..976d7a82e83f8b5d08c3e530f28735db803c551d 100644 (file)
@@ -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');
similarity index 97%
rename from t/pm/DisjConditions.pl
rename to t/pm/DisjConditions.plt
index bdcafd2bb2c7a27ead5fa5de44d54da95fd7f98f..c5ec25be0a6bb7658e6d05dd3b4947d157b92f68 100644 (file)
@@ -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 ()
 {
@@ -403,9 +405,9 @@ sub test_bad_declarations
   return $failed;
 }
 
-exit (test_basics
-      || test_invert
-      || test_simplify
-      || test_sub_conditions
-      || test_ambig
-      || test_bad_declarations);
+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');
similarity index 84%
rename from t/pm/General.pl
rename to t/pm/General.plt
index 0caefe7cf2226780e93c6ba1b9ecac3443ca7dcb..645886d9ce9536ed04fe37dc23d5a6f40a9c4704 100644 (file)
@@ -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
 # 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/SilentRules.pl b/t/pm/SilentRules.pl
deleted file mode 100644 (file)
index 7397c3a..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-# 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
-# of the License, 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 <http://www.gnu.org/licenses/>.
-
-use Automake::SilentRules;
-
-my @test_vars = qw (FOO BAR BAZ TEST);
-
-
-sub test_verbose_flag
-{
-  my @res = map { verbose_flag $_ } @test_vars;
-  print "Test verbose_flag:\n";
-  print "Variable names: @test_vars\n";
-  print "Result: @res\n\n";
-  for my $i (0 .. $#res)
-    {
-      return 1
-          unless $res[$i] eq '$(AM_V_' . $test_vars[$i] . ')';
-    }
-  return 0;
-}
-
-
-sub test_verbose_nodep_flag
-{
-  my @res = map { verbose_nodep_flag $_ } @test_vars;
-  print "Test verbose_nodep_flag:\n";
-  print "Variable names: @test_vars\n";
-  print "Result: @res\n\n";
-  for my $i (0 .. $#res)
-    {
-      return 1
-          unless $res[$i] eq '$(AM_V_' . $test_vars[$i] . '@am__nodep@)';
-    }
-  return 0;
-}
-
-
-sub test_silent_flag
-{
-  return 1 
-      unless silent_flag eq '$(AM_V_at)';
-  print "silent_flag: OK\n\n";
-  return 0;
-}
-
-
-exit (test_verbose_flag | test_verbose_nodep_flag | test_silent_flag);
diff --git a/t/pm/SilentRules.plt b/t/pm/SilentRules.plt
new file mode 100644 (file)
index 0000000..506d4b2
--- /dev/null
@@ -0,0 +1,22 @@
+# -*- mode:perl -*-
+# 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
+# of the License, 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 <http://www.gnu.org/licenses/>.
+
+use Automake::SilentRules;
+use Test::Simple tests => 3;
+
+ok (verbose_flag 'FOO' eq '$(AM_V_FOO)', 'verbose_flag');
+ok (verbose_nodep_flag 'FOO' eq '$(AM_V_FOO@am__nodep@)', 'verbose_nodep_flag');
+ok (silent_flag eq '$(AM_V_at)', 'silent_flag');
similarity index 51%
rename from t/pm/Utils.pl
rename to t/pm/Utils.plt
index ad8fc35be339d3cc91e24d3909077a6515a352cf..7bb0fe75087272c45bf9780bb2820924a990b725 100644 (file)
@@ -1,3 +1,4 @@
+# -*- mode:perl -*-
 # Copyright (C) 2018  Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 use Automake::Utils;
+use Test::Simple tests => 3;
 
-sub check_subst
-{
-  my @inputs = qw (AC_FOO AC_BAR AC_BAZ);
-  my @expected_outputs = map {
-    (my $exp = $_) =~ s/(.*)/\@$1\@/;
-    $exp;
-  } @inputs;
+ok (subst 'AC_FOO' eq '@AC_FOO@', 'subst');
 
-  for my $i (0 .. $#inputs)
-    {
-      return 1 if (subst $inputs[$i]) ne $expected_outputs[$i];
-    }
-  return 0;
-}
+##########################################
 
-sub check_flatten
-{
-  my $test_str = "\
+my $test_str = "\
 
   Aliquam posuere.  Nunc aliquet, augue nec adipiscing interdum, lacus tellus
 malesuada massa, quis varius mi purus     non odio.  Pellentesque condimentum,
@@ -44,24 +33,19 @@ sit amet urna.  Curabitur vulputate vestibulum lorem.  Fusce sagittis, libero
 lacinia eros.
 ";
 
-  my $expected_res = "Aliquam posuere. Nunc aliquet, augue nec adipiscing " .
-      "interdum, lacus tellus malesuada massa, quis varius mi purus non " .
-      "odio. Pellentesque condimentum, magna ut suscipit hendrerit, ipsum " .
-      "augue ornare nulla, non luctus diam neque sit amet urna. Curabitur " .
-      "vulputate vestibulum lorem. Fusce sagittis, libero non molestie " .
-      "mollis, magna orci ultrices dolor, at vulputate neque nulla lacinia " .
-      "eros.";
+my $expected_res = "Aliquam posuere. Nunc aliquet, augue nec adipiscing " .
+    "interdum, lacus tellus malesuada massa, quis varius mi purus non " .
+    "odio. Pellentesque condimentum, magna ut suscipit hendrerit, ipsum " .
+    "augue ornare nulla, non luctus diam neque sit amet urna. Curabitur " .
+    "vulputate vestibulum lorem. Fusce sagittis, libero non molestie " .
+    "mollis, magna orci ultrices dolor, at vulputate neque nulla lacinia " .
+    "eros.";
 
-  return 1 if (flatten $test_str) ne $expected_res;
-  return 0;
-}
+ok ((flatten $test_str) eq $expected_res, 'flatten');
 
-sub check_locate_aux_dir
-{
-  locate_aux_dir;
-  # The install-sh script is located in $(top_scrdir)/lib/
-  return 1 if ($am_config_aux_dir ne "$(top_srcdir)/lib/");
-  return 0;
-}
+#####################################################
 
-exit (check_subst || check_flatten);
+locate_aux_dir;
+# The install-sh script is located in $(top_scrdir)/lib/
+print "$am_config_aux_dir\n";
+ok ($am_config_aux_dir eq '$(top_srcdir)', 'locate_aux_dir');
diff --git a/t/pm/Version.pl b/t/pm/Version.pl
deleted file mode 100644 (file)
index e4372ff..0000000
+++ /dev/null
@@ -1,127 +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;
-  }
-}
-
-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 $@;
-  $failed = 1 unless $@;
-}
-
-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 (file)
index 0000000..4684453
--- /dev/null
@@ -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');
similarity index 77%
rename from t/pm/Wrap.pl
rename to t/pm/Wrap.plt
index 995569a4fe5ab47ea097c6d9c05b314c93c010ce..fdfdab3bfc0c9cf842504fd2a8329b4c04cfd40f 100644 (file)
@@ -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');