>From d3a3e33471ce0342652ca51760e3a3267e53c3c6 Mon Sep 17 00:00:00 2001 From: Matthias Paulmier Date: Thu, 30 Aug 2018 16:33:16 +0200 Subject: [PATCH 2/4] Add extension for perl tests using Test::Simple This extension is for Perl tests written with the help of the Test::Simple. * t/pm/Version.pl: Replace it with Version.plt as an example. --- t/list-of-tests.mk | 2 +- t/local.mk | 4 +- t/pm/Version.pl | 127 --------------------------------------------- t/pm/Version.plt | 122 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 129 deletions(-) delete mode 100644 t/pm/Version.pl create mode 100644 t/pm/Version.plt diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk index ec2d106a2..7cc0e6585 100644 --- a/t/list-of-tests.mk +++ b/t/list-of-tests.mk @@ -40,7 +40,7 @@ t/pm/Condition-t.pl \ t/pm/DisjConditions.pl \ t/pm/DisjConditions-t.pl \ t/pm/General.pl \ -t/pm/Version.pl \ +t/pm/Version.plt \ t/pm/Wrap.pl perf_TESTS = \ 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/Version.pl b/t/pm/Version.pl deleted file mode 100644 index e4372fffb..000000000 --- a/t/pm/Version.pl +++ /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 . - -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 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 . + +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'); -- 2.18.0