Debian Codegraph @

tests/datamash-i18n-de.pl

raw
1 #!/usr/bin/env perl
2 =pod
3 Unit Tests for GNU Datamash - check German locale (de_DE.UTF-8).
4
5 Copyright (C) 2013-2021 Assaf Gordon <[email protected]>
6 Copyright (C) 2022-2025 Timothy Rice <[email protected]>
7
8 This file is part of GNU Datamash.
9
10 GNU Datamash is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 GNU Datamash is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GNU Datamash. If not, see <https://www.gnu.org/licenses/>.
22
23 Written by Assaf Gordon and Timothy Rice.
24 =cut
25 use strict;
26 use warnings;
27
28 # Until a better way comes along to auto-use Coreutils Perl modules
29 # as in the coreutils' autotools system.
30 use Coreutils;
31 use CuSkip;
32 use CuTmpdir qw(datamash);
33 use MIME::Base64 ;
34
35 ## Skip this test if Deutsche (German) locale not found.
36 use POSIX qw(locale_h);
37 use locale;
38 my $lc_de = setlocale(LC_ALL, "de_DE.utf8");
39 CuSkip::skip "requires de_DE.utf8 locale\n"
40 unless defined($lc_de);
41
42 (my $program_name = $0) =~ s|.*/||;
43 my $prog_bin = 'datamash';
44
45 ## Cross-Compiling portability hack:
46 ## under qemu/binfmt, argv[0] (which is used to report errors) will contain
47 ## the full path of the binary, if the binary is on the $PATH.
48 ## So we try to detect what is the actual returned value of the program
49 ## in case of an error.
50 my $prog = `$prog_bin ---print-progname`;
51 $prog = $prog_bin unless $prog;
52
53 ## Portability hack
54 ## Check if the system's sort supports stable sorting ('-s').
55 ## If it doesn't - skip some tests
56 my $rc = system("sort -s < /dev/null > /dev/null 2>/dev/null");
57 die "testing framework failure: failed to execute sort -s"
58 if ( ($rc == -1) || ($rc & 127) );
59 my $sort_exit_code = ($rc >> 8);
60 my $have_stable_sort = ($sort_exit_code==0);
61
62
63 # Deutsche Prüfungen
64 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('de_DE.utf8') x 3;
65
66 my @Prufungen =
67 (
68 # Prüfen Sie, ob das Komma als Dezimaltrennzeichen funktioniert
69 ['de1', 'sum 1', {IN_PIPE=>"1,1\n"}, {OUT=>"1,1\n"}],
70 ['de2', 'sum 1,2', {IN_PIPE=>"1,1\t2,2\n"}, {OUT=>"1,1\t2,2\n"}],
71 ['de3', 'count 1,2,3', {IN_PIPE=>"1,1\t2,2\t3,3\n"}, {OUT=>"1\t1\t1\n"}],
72
73 # There is a bug where the bin operation does not respect
74 # the locale's choice of decimal separator.
75 # TODO: Be able to uncomment the following line.
76 #['de4', 'bin:0,1 1' {IN_PIPE=>"1,15\n"}, {OUT=>"1,1\n"}],
77
78 # Comma as field separator is problematic for numeric operations
79 ['de5', '-t, cut 2,1', {IN_PIPE=>"1,2\n"}, {OUT=>"2,1\n"}],
80 ['de6', '-t, unique 1,2', {IN_PIPE=>"1,2\n"}, {OUT=>"1,2\n"}],
81 ['de7', '-t, count 1,2', {IN_PIPE=>"1,2\n"}, {OUT=>"1,1\n"}],
82 ['de8', '-t, countunique 1,2', {IN_PIPE=>"1,2\n"}, {OUT=>"1,1\n"}],
83 ['de9', '-t, rmdup 1', {IN_PIPE=>"1,2\n"}, {OUT=>"1,2\n"}],
84 ['de10', '-t, rmdup 2', {IN_PIPE=>"1,2\n"}, {OUT=>"1,2\n"}],
85 ['de11', '-t, sum 1,2', {IN_PIPE=>"1,2\n"}, {OUT=>"1,2\n"}],
86 ['de12', '-t, sum 1,2,3', {IN_PIPE=>"1,2,3\n"}, {OUT=>"1,2,3\n"}],
87 ['de13', '-st, groupby 1 sum 2,3',
88 {IN_PIPE=>"a,14,1\nb,1,14\na,2,1\n"}, {OUT=>"a,16,2\nb,1,14\n"}],
89
90 # TODO: make the getnum operation locale-aware
91 #['de14', 'getnum 1', {IN_PIPE=>"bar-1,2\n"}, {OUT=>"1,2\n"}],
92 #['de15', 'getnum:p 1', {IN_PIPE=>"bar-1,2\n"}, {OUT=>"1,2\n"}],
93 #['de16', 'getnum:d 1', {IN_PIPE=>"bar-1,2\n"}, {OUT=>"-1,2\n"}],
94
95 );
96
97 my $save_temps = $ENV{SAVE_TEMPS};
98 my $verbose = $ENV{VERBOSE};
99
100 my $fail = run_tests ($program_name, $prog, \@Prufungen, $save_temps, $verbose);
101
102 exit $fail;