~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/misc/invalid-opt.pl

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# exercise the 'invalid option' handling code in each program
 
3
 
 
4
# Copyright (C) 2008-2012 Free 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 3 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, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
require 5.003;
 
20
use strict;
 
21
 
 
22
# Turn off localization of executable's output.
 
23
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
 
24
 
 
25
my %exit_status =
 
26
  (
 
27
    ls => 2,
 
28
    dir => 2,
 
29
    vdir => 2,
 
30
    test => 2,
 
31
    chroot => 125,
 
32
    echo => 0,
 
33
    env => 125,
 
34
    expr => 0,
 
35
    nice => 125,
 
36
    nohup => 125,
 
37
    sort => 2,
 
38
    stdbuf => 125,
 
39
    test => 0,
 
40
    timeout => 125,
 
41
    true => 0,
 
42
    tty => 2,
 
43
    printf => 0,
 
44
    printenv => 2,
 
45
  );
 
46
 
 
47
my %expected_out =
 
48
  (
 
49
    echo => "-/\n",
 
50
    expr => "-/\n",
 
51
    printf => "-/",
 
52
  );
 
53
 
 
54
my %expected_err =
 
55
  (
 
56
    false => '',
 
57
    stty => '',
 
58
  );
 
59
 
 
60
my $fail = 0;
 
61
my @built_programs = split ' ', $ENV{built_programs};
 
62
foreach my $prog (@built_programs)
 
63
  {
 
64
    $prog eq '['
 
65
      and next;
 
66
 
 
67
    my $try = "Try '$prog --help' for more information.\n";
 
68
    my $x = $exit_status{$prog};
 
69
    defined $x
 
70
      or $x = 1;
 
71
 
 
72
    my $out = $expected_out{$prog};
 
73
    defined $out
 
74
      or $out = '';
 
75
 
 
76
    my $err = $expected_err{$prog};
 
77
    defined $err
 
78
      or $err = $x == 0 ? '' : "$prog: invalid option -- /\n$try";
 
79
 
 
80
    # Accommodate different syntax in glibc's getopt
 
81
    # diagnostics by filtering out single quotes.
 
82
    # Also accommodate BSD getopt.
 
83
    my $err_subst = "s,'/',/,; s,unknown,invalid,";
 
84
 
 
85
    # Depending on how this script is run, stty emits different
 
86
    # diagnostics.  Don't bother checking them.
 
87
    $prog eq 'stty'
 
88
      and $err_subst = 's/(.|\n)*//ms';
 
89
 
 
90
    my @Tests = (["$prog-invalid-opt", '-/', {OUT=>$out},
 
91
                  {ERR_SUBST => $err_subst},
 
92
                  {EXIT=>$x}, {ERR=>$err}]);
 
93
 
 
94
    my $save_temps = $ENV{DEBUG};
 
95
    my $verbose = $ENV{VERBOSE};
 
96
 
 
97
    my $f = run_tests ($prog, \$prog, \@Tests, $save_temps, $verbose);
 
98
    $f
 
99
      and $fail = 1;
 
100
  }
 
101
 
 
102
exit $fail;