Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / tsort / basic-1
1 #!/bin/sh
2 # -*- perl -*-
3 # Test "tsort".
4
5 # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006 Free Software
6 # Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
22
23 : ${PERL=perl}
24 : ${srcdir=.}
25
26 $PERL -e 1 > /dev/null 2>&1 || {
27   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
28     "so can't run this test"
29   exit 77
30 }
31
32 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
33 #/
34 require 5.003;
35 use strict;
36
37 (my $program_name = $0) =~ s|.*/||;
38
39 # Turn off localisation of executable's ouput.
40 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
41
42 my @Tests =
43   (
44    ['cycle-1', {IN => {f => "t b\nt s\ns t\n"}}, {OUT => "s\nt\nb\n"},
45     {EXIT => 1},
46     {ERR => "tsort: f: input contains a loop:\ntsort: s\ntsort: t\n"} ],
47    ['cycle-2', {IN => {f => "t x\nt s\ns t\n"}}, {OUT => "s\nt\nx\n"},
48     {EXIT => 1},
49     {ERR => "tsort: f: input contains a loop:\ntsort: s\ntsort: t\n"} ],
50
51    ['posix-1', {IN => "a b c c d e\ng g\nf g e f\nh h\n"},
52     {OUT => "a\nc\nd\nh\nb\ne\nf\ng\n"}],
53    ['posix-2', {IN => "b a\nd c\nz h x h r h\n"},
54     {OUT => "b\nd\nr\nx\nz\na\nc\nh\n"}],
55
56    ['linear-1', {IN => "a b b c c d d e e f f g\n"},
57     {OUT => "a\nb\nc\nd\ne\nf\ng\n"}],
58
59    ['tree-1', {IN => "a b b c c d d e e f f g\nc x x y y z\n"},
60     {OUT => "a\nb\nc\nx\nd\ny\ne\nz\nf\ng\n"}],
61    ['tree-2', {IN => "a b b c c d d e e f f g\nc x x y y z\nf r r s s t\n"},
62     {OUT => "a\nb\nc\nx\nd\ny\ne\nz\nf\nr\ng\ns\nt\n"}],
63
64    # Before coreutils-5.0.1, given an odd number of input tokens,
65    # tsort would accept that and treat the input as if an additional
66    # copy of the final token were appended.
67    ['odd', {IN => "a\n"},
68     {EXIT => 1},
69     {ERR => "tsort: odd.1: input contains an odd number of tokens\n"}],
70
71    ['only-one', {IN => {f => ""}}, {IN => {g => ""}},
72     {EXIT => 1},
73     {ERR => "tsort: extra operand `g'\n"
74      . "Try `tsort --help' for more information.\n"}],
75   );
76
77 my $save_temps = $ENV{DEBUG};
78 my $verbose = $ENV{VERBOSE};
79
80 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
81 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
82 exit $fail;
83 EOF