| 1 |
#!/usr/bin/env perl |
| 2 |
=pod |
| 3 |
Unit Tests for GNU Datamash - tests rand operations |
| 4 |
|
| 5 |
Copyright (C) 2022-2025 Timothy Rice <[email protected]> |
| 6 |
|
| 7 |
This file is part of GNU Datamash. |
| 8 |
|
| 9 |
GNU Datamash is free software: you can redistribute it and/or modify |
| 10 |
it under the terms of the GNU General Public License as published by |
| 11 |
the Free Software Foundation, either version 3 of the License, or |
| 12 |
(at your option) any later version. |
| 13 |
|
| 14 |
GNU Datamash is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
GNU General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License |
| 20 |
along with GNU Datamash. If not, see <https://www.gnu.org/licenses/>. |
| 21 |
|
| 22 |
Written by Tim Rice. |
| 23 |
=cut |
| 24 |
use strict; |
| 25 |
use warnings; |
| 26 |
|
| 27 |
# Until a better way comes along to auto-use Coreutils Perl modules |
| 28 |
# as in the coreutils' autotools system. |
| 29 |
use Coreutils; |
| 30 |
use CuSkip; |
| 31 |
use CuTmpdir qw(datamash); |
| 32 |
|
| 33 |
(my $program_name = $0) =~ s|.*/||; |
| 34 |
my $prog_bin = 'datamash'; |
| 35 |
|
| 36 |
## Cross-Compiling portability hack: |
| 37 |
## under qemu/binfmt, argv[0] (which is used to report errors) will contain |
| 38 |
## the full path of the binary, if the binary is on the $PATH. |
| 39 |
## So we try to detect what is the actual returned value of the program |
| 40 |
## in case of an error. |
| 41 |
my $prog = `$prog_bin ---print-progname`; |
| 42 |
$prog = $prog_bin unless $prog; |
| 43 |
|
| 44 |
# Turn off localization of executable's output. |
| 45 |
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; |
| 46 |
|
| 47 |
my $in=<<'EOF'; |
| 48 |
A A |
| 49 |
A B |
| 50 |
B A |
| 51 |
B B |
| 52 |
EOF |
| 53 |
|
| 54 |
my $out=<<'EOF'; |
| 55 |
A B |
| 56 |
B A |
| 57 |
EOF |
| 58 |
|
| 59 |
my @Tests = |
| 60 |
( |
| 61 |
['r1', '-W -S0 groupby 1 rand 2', {IN_PIPE=>$in}, {OUT=>$out}], |
| 62 |
); |
| 63 |
|
| 64 |
my $save_temps = $ENV{SAVE_TEMPS}; |
| 65 |
my $verbose = $ENV{VERBOSE}; |
| 66 |
|
| 67 |
my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); |
| 68 |
exit $fail; |