test.pl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #! /usr/local/bin/perl -w
  2. # vim: tabstop=4
  3. # $Id: test.pl,v 1.1 2009-11-01 18:59:59 pertusus Exp $
  4. # Portable character conversion for Perl.
  5. # Copyright (C) 2002-2009 Guido Flohr <guido@imperia.net>,
  6. # all rights reserved.
  7. # This program is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU Library General Public License as published
  9. # by the Free Software Foundation; either version 2, or (at your option)
  10. # any later version.
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Library General Public License for more details.
  15. # You should have received a copy of the GNU Library General Public
  16. # License along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. # USA.
  19. # This is a safe wrapper for systems that lack a POSIX shell or have
  20. # a too low limit on the length of the command line.
  21. use strict;
  22. use File::Basename;
  23. use Test::Harness;
  24. use File::Spec;
  25. sub test_harness;
  26. my $here = dirname ($0);
  27. my $test_dir = $here . '/tests';
  28. my @lib_dirs = ($here . '/blib/lib', $here . '/blib/arch');
  29. local *DIR;
  30. opendir DIR, $test_dir or die "cannot open test directory '$test_dir': $!";
  31. @ARGV = sort map $test_dir . '/' . $_, grep /\.t$/, readdir DIR;
  32. closedir DIR;
  33. eval {
  34. require Encode;
  35. };
  36. unless ($@) {
  37. print "# Encode revision used is $Encode::VERSION.\n";
  38. }
  39. test_harness ($ENV{TEST_HARNESS} || 0, @lib_dirs);
  40. sub test_harness
  41. {
  42. $Test::Harness::verbose = shift;
  43. local @INC = @INC;
  44. unshift @INC, map { File::Spec->rel2abs($_) } @_;
  45. my $name = $0;
  46. $name =~ s,test\.pl$,xs_disabled,;
  47. local *HANDLE;
  48. open HANDLE, "<$name" or die "cannot open '$name': $!";
  49. my $xs_disabled = <HANDLE>;
  50. close HANDLE;
  51. unless ($xs_disabled) {
  52. # It is pointless to test the XS extension, if no German
  53. # locales are installed on the system. The results
  54. # vary in almost arbitrary ways.
  55. # FIXME: Do not rely on the de, resp. de_AT locales only.
  56. # We can simply try other combinations (fr_CA,
  57. # en_GB, pt_BR, and so on), since the actual
  58. # translations are not meaningful in our case.
  59. # We could therefore just test here for certain
  60. # combinations, and then create the mo files on
  61. # the fly by copying.
  62. require POSIX;
  63. require Locale::Messages;
  64. Locale::Messages::nl_putenv ("LANGUAGE=de_AT");
  65. Locale::Messages::nl_putenv ("LC_ALL=de_AT");
  66. Locale::Messages::nl_putenv ("LANG=de_AT");
  67. Locale::Messages::nl_putenv ("LC_MESSAGES=de_AT");
  68. Locale::Messages::nl_putenv ("OUTPUT_CHARSET=iso-8859-1");
  69. my $has_de_locale = POSIX::setlocale (POSIX::LC_ALL() => '');
  70. unless ($has_de_locale) {
  71. require Locale::Util;
  72. $has_de_locale =
  73. Locale::Util::set_locale (POSIX::LC_ALL(),
  74. 'de');
  75. undef $has_de_locale
  76. unless ($has_de_locale
  77. && $has_de_locale =~ /(?:germany|de)/i);
  78. }
  79. unless ($has_de_locale) {
  80. $xs_disabled = 1;
  81. print <<EOF;
  82. The XS version of libintl-perl cannot be tested on your system because
  83. the locale definitions for German do not exist.
  84. EOF
  85. }
  86. $xs_disabled = !$has_de_locale;
  87. }
  88. if ($xs_disabled) {
  89. Test::Harness::runtests (grep { ! /_xs.t$/ } sort
  90. {lc $a cmp lc $b } @ARGV);
  91. } else {
  92. Test::Harness::runtests (sort {lc $a cmp lc $b } @ARGV);
  93. }
  94. }
  95. __END__
  96. Local Variables:
  97. mode: perl
  98. perl-indent-level: 4
  99. perl-continued-statement-offset: 4
  100. perl-continued-brace-offset: 0
  101. perl-brace-offset: -4
  102. perl-brace-imaginary-offset: 0
  103. perl-label-offset: -4
  104. cperl-indent-level: 4
  105. cperl-continued-statement-offset: 2
  106. tab-width: 4
  107. End: