2
0

Version.pl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Copyright (C) 2002-2017 Free Software Foundation, Inc.
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2, or (at your option)
  6. # any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use Automake::Version;
  16. my $failed = 0;
  17. sub test_version_compare
  18. {
  19. my ($left, $right, $result) = @_;
  20. my @leftver = Automake::Version::split ($left);
  21. my @rightver = Automake::Version::split ($right);
  22. if ($#leftver == -1)
  23. {
  24. print "can't grok \"$left\"\n";
  25. $failed = 1;
  26. return;
  27. }
  28. if ($#rightver == -1)
  29. {
  30. print "can't grok \"$right\"\n";
  31. $failed = 1;
  32. return;
  33. }
  34. my $res = Automake::Version::compare (@leftver, @rightver);
  35. if ($res != $result)
  36. {
  37. print "compare (\"$left\", \"$right\") = $res! (not $result?)\n";
  38. $failed = 1;
  39. }
  40. my $check_expected = ($result == 0 || $result == 1) ? 0 : 1;
  41. # Exception for 'foo' fork.
  42. $check_expected = 1
  43. if ($right =~ /foo/ && !($left =~ /foo/));
  44. my $check = Automake::Version::check ($left, $right);
  45. if ($check != $check_expected)
  46. {
  47. print "check (\"$left\", \"$right\") = $check! (not $check_expected?)\n";
  48. $failed = 1;
  49. }
  50. }
  51. sub test_bad_versions
  52. {
  53. my ($ver) = @_;
  54. my @version = Automake::Version::split ($ver);
  55. if ($#version != -1)
  56. {
  57. print "shouldn't grok \"$ver\"\n";
  58. $failed = 1;
  59. }
  60. }
  61. my @tests = (
  62. # basics
  63. ['1.0', '2.0', -1],
  64. ['2.0', '1.0', 1],
  65. ['1.2', '1.2', 0],
  66. ['1.1', '1.2', -1],
  67. ['1.2', '1.1', 1],
  68. # alphas
  69. ['1.4', '1.4g', -1],
  70. ['1.4g', '1.5', -1],
  71. ['1.4g', '1.4', 1],
  72. ['1.5', '1.4g', 1],
  73. ['1.4a', '1.4g', -1],
  74. ['1.5a', '1.3g', 1],
  75. ['1.6a', '1.6a', 0],
  76. # micros
  77. ['1.5.1', '1.5', 1],
  78. ['1.5.0', '1.5', 0],
  79. ['1.5.4', '1.6.1', -1],
  80. # micros and alphas
  81. ['1.5a', '1.5.1', 1],
  82. ['1.5a', '1.5.1a', 1],
  83. ['1.5a', '1.5.1f', 1],
  84. ['1.5', '1.5.1a', -1],
  85. ['1.5.1a', '1.5.1f', -1],
  86. ['1.5.1f', '1.5.1a', 1],
  87. ['1.5.1f', '1.5.1f', 0],
  88. # special exceptions
  89. ['1.6-p5a', '1.6.5a', 0],
  90. ['1.6', '1.6-p5a', -1],
  91. ['1.6-p4b', '1.6-p5a', -1],
  92. ['1.6-p4b', '1.6-foo', 1],
  93. ['1.6-p4b', '1.6a-foo', -1],
  94. ['1.6-p5', '1.6.5', 0],
  95. ['1.6a-foo', '1.6a-foo', 0],
  96. );
  97. my @bad_versions = (
  98. '', 'a', '1', '1a', '1.2.3.4', '-1.2'
  99. );
  100. test_version_compare (@{$_}) foreach @tests;
  101. test_bad_versions ($_) foreach @bad_versions;
  102. exit $failed;
  103. ### Setup "GNU" style for perl-mode and cperl-mode.
  104. ## Local Variables:
  105. ## perl-indent-level: 2
  106. ## perl-continued-statement-offset: 2
  107. ## perl-continued-brace-offset: 0
  108. ## perl-brace-offset: 0
  109. ## perl-brace-imaginary-offset: 0
  110. ## perl-label-offset: -2
  111. ## cperl-indent-level: 2
  112. ## cperl-brace-offset: 0
  113. ## cperl-continued-brace-offset: 0
  114. ## cperl-label-offset: -2
  115. ## cperl-extra-newline-before-brace: t
  116. ## cperl-merge-trailing-else: nil
  117. ## cperl-continued-statement-offset: 2
  118. ## End: