Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / uniq / Test.pm
1 # Test "uniq".
2
3 # Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006 Free
4 # Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
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
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 package Test;
22 require 5.002;
23 use strict;
24
25 $Test::input_via_stdin = 1;
26
27 my @tv = (
28 # test flags  input              expected output    expected return code
29 #
30 ['1',  '',    '',                '',                0],
31 ['2',  '',    "a\na\n",          "a\n",             0],
32 ['3',  '',    "a\na",            "a\n",             0],
33 ['4',  '',    "a\nb",            "a\nb\n",          0],
34 ['5',  '',    "a\na\nb",         "a\nb\n",          0],
35 ['6',  '',    "b\na\na\n",       "b\na\n",          0],
36 ['7',  '',    "a\nb\nc\n",       "a\nb\nc\n",       0],
37 # Make sure that eight bit characters work
38 ['8',  '',    "ö\nv\n",          "ö\nv\n",          0],
39 # Test output of -u option; only unique lines
40 ['9',  '-u',  "a\na\n",          "",                0],
41 ['10', '-u',  "a\nb\n",          "a\nb\n",          0],
42 ['11', '-u',  "a\nb\na\n",       "a\nb\na\n",       0],
43 ['12', '-u',  "a\na\n",          "",                0],
44 ['13', '-u',  "a\na\n",          "",                0],
45 #['5',  '-u',  "a\na\n",          "",                0],
46 # Test output of -d option; only repeated lines
47 ['20', '-d',  "a\na\n",          "a\n",             0],
48 ['21', '-d',  "a\nb\n",          "",                0],
49 ['22', '-d',  "a\nb\na\n",       "",                0],
50 ['23', '-d',  "a\na\nb\n",       "a\n",             0],
51 # Check the key options
52 # If we skip over fields or characters, is the output deterministic?
53 ['obs30', '-1',  "a a\nb a\n",      "a a\n",           0],
54 ['31', '-f 1',"a a\nb a\n",      "a a\n",           0],
55 ['32', '-f 1',"a a\nb b\n",      "a a\nb b\n",      0],
56 ['33', '-f 1',"a a a\nb a c\n",  "a a a\nb a c\n",  0],
57 ['34', '-f 1',"b a\na a\n",      "b a\n",           0],
58 ['35', '-f 2',"a a c\nb a c\n",  "a a c\n",         0],
59 # Skip over characters.
60 ['obs-plus40', '+1',  "aaa\naaa\n",      "aaa\n",           0],
61 ['obs-plus41', '+1',  "baa\naaa\n",      "baa\n",           0],
62 ['42', '-s 1',"aaa\naaa\n",      "aaa\n",           0],
63 ['43', '-s 2',"baa\naaa\n",      "baa\n",           0],
64 ['obs-plus44', '+1 --',  "aaa\naaa\n",   "aaa\n",           0],
65 ['obs-plus45', '+1 --',  "baa\naaa\n",   "baa\n",           0],
66 # Skip over fields and characters
67 ['50', '-f 1 -s 1',"a aaa\nb ab\n",      "a aaa\nb ab\n",       0],
68 ['51', '-f 1 -s 1',"a aaa\nb aaa\n",     "a aaa\n",             0],
69 ['52', '-s 1 -f 1',"a aaa\nb ab\n",      "a aaa\nb ab\n",       0],
70 ['53', '-s 1 -f 1',"a aaa\nb aaa\n",     "a aaa\n",             0],
71 # Fixed in 2.0.15
72 ['54', '-s 4',     "abc\nabcd\n",        "abc\n",               0],
73 # Supported in 2.0.15
74 ['55', '-s 0',     "abc\nabcd\n",        "abc\nabcd\n",         0],
75 ['56', '-s 0',     "abc\n",              "abc\n",               0],
76 ['57', '-w 0',     "abc\nabcd\n",        "abc\n",               0],
77 # Only account for a number of characters
78 ['60', '-w 1',"a a\nb a\n",      "a a\nb a\n",         0],
79 ['61', '-w 3',"a a\nb a\n",      "a a\nb a\n",         0],
80 ['62', '-w 1 -f 1',"a a a\nb a c\n",  "a a a\n",       0],
81 ['63', '-f 1 -w 1',"a a a\nb a c\n",  "a a a\n",       0],
82 # The blank after field one is checked too
83 ['64', '-f 1 -w 4',"a a a\nb a c\n",  "a a a\nb a c\n",         0],
84 ['65', '-f 1 -w 3',"a a a\nb a c\n",  "a a a\n",                0],
85 # Make sure we don't break if the file contains \0
86 ['90', '',       "a\0a\na\n",  "a\0a\na\n",                     0],
87 # Check fields seperated by tabs and by spaces
88 ['91', '',       "a\ta\na a\n",  "a\ta\na a\n",                 0],
89 ['92', '-f 1',   "a\ta\na a\n",  "a\ta\na a\n",                 0],
90 ['93', '-f 2',   "a\ta a\na a a\n",  "a\ta a\n",                0],
91 ['94', '-f 1',   "a\ta\na\ta\n",  "a\ta\n",                     0],
92 # Check the count option; add tests for other options too
93 ['101', '-c',    "a\nb\n",          "      1 a\n      1 b\n", 0],
94 ['102', '-c',    "a\na\n",          "      2 a\n",             0],
95 # Check the local -D (--all-repeated) option
96 ['110', '-D',    "a\na\n",          "a\na\n",                   0],
97 ['111', '-D -w1',"a a\na b\n",      "a a\na b\n",               0],
98 ['112', '-D -c', "a a\na b\n",      "",                         1],
99 ['113', '--all-repeated=separate',"a\na\n",          "a\na\n",           0],
100 ['114', '--all-repeated=separate',"a\na\nb\nc\nc\n", "a\na\n\nc\nc\n",   0],
101 ['115', '--all-repeated=separate',"a\na\nb\nb\nc\n", "a\na\n\nb\nb\n",   0],
102 ['116', '--all-repeated=prepend', "a\na\n",          "\na\na\n",         0],
103 ['117', '--all-repeated=prepend', "a\na\nb\nc\nc\n", "\na\na\n\nc\nc\n", 0],
104 ['118', '--all-repeated=prepend', "a\nb\n",          "",                 0],
105 ['119', '--all-repeated=badoption', "a\n",           "",                 1],
106 # Check that -d and -u suppress all output, as POSIX requires.
107 ['120', '-d -u', "a\na\n\b",        "",                         0],
108 ['121', '-d -u -w340282366920938463463374607431768211456',
109                  "a\na\n\b",        "",                         0],
110 );
111
112 sub test_vector
113 {
114   my $t;
115   foreach $t (@tv)
116     {
117       my ($test_name, $flags, $in, $exp, $ret) = @$t;
118       $Test::input_via{$test_name} = {REDIR => 0, PIPE => 0};
119
120       $test_name =~ /^obs-plus/
121         and $Test::env{$test_name} = ['_POSIX2_VERSION=199209'];
122
123       $ret
124         and $Test::input_via{$test_name} = {REDIR => 0};
125     }
126
127   return @tv;
128 }
129
130 1;