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

« back to all changes in this revision

Viewing changes to tests/Coreutils.pm

  • 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
1
package Coreutils;
2
2
# This is a testing framework.
3
3
 
4
 
# Copyright (C) 1998, 2000-2002, 2004-2011 Free Software Foundation, Inc.
 
4
# Copyright (C) 1998-2012 Free Software Foundation, Inc.
5
5
 
6
6
# This program is free software: you can redistribute it and/or modify
7
7
# it under the terms of the GNU General Public License as published by
33
33
my %Types = map {$_ => 1} @Types;
34
34
my %Zero_one_type = map {$_ => 1}
35
35
   qw (OUT ERR EXIT PRE POST OUT_SUBST ERR_SUBST ENV);
36
 
my $srcdir = $ENV{srcdir};
 
36
my $srcdir = "$ENV{srcdir}";
37
37
my $Global_count = 1;
38
38
 
39
39
# When running in a DJGPP environment, make $ENV{SHELL} point to bash.
46
46
# ================
47
47
# 'contents'               contents only (file name is derived from test name)
48
48
# {filename => 'contents'} filename and contents
49
 
# {filename => undef}      filename only -- $(srcdir)/filename must exist
 
49
# {filename => undef}      filename only -- $(srcdir)/tests/filename must exist
50
50
#
51
 
# FIXME: If there is more than one input file, then you can't specify `REDIR'.
 
51
# FIXME: If there is more than one input file, then you can't specify 'REDIR'.
52
52
# PIPE is still ok.
53
53
#
54
54
# I/O spec: a hash ref with the following properties
60
60
# {OUT => {'filename'=>undef}} compare contents of existing filename to
61
61
#           stdout from cmd
62
62
# {OUT => {'filename'=>[$CTOR, $DTOR]}} $CTOR and $DTOR are references to
63
 
#           functions, each which is passed the single argument `filename'.
64
 
#           $CTOR must create `filename'.
65
 
#           DTOR may be omitted in which case `sub{unlink @_[0]}' is used.
 
63
#           functions, each which is passed the single argument 'filename'.
 
64
#           $CTOR must create 'filename'.
 
65
#           DTOR may be omitted in which case 'sub{unlink @_[0]}' is used.
66
66
#           FIXME: implement this
67
67
# {ERR => ...}
68
68
#           Same as for OUT, but compare with stderr, not stdout.
78
78
#   diagnostics: Operation not permitted, Not owner, and Permission denied.
79
79
# {EXIT => N} expect exit status of cmd to be N
80
80
# {ENV => 'VAR=val ...'}
81
 
#   Prepend 'VAR=val ...' to the command that we execute via `system'.
 
81
#   Prepend 'VAR=val ...' to the command that we execute via 'system'.
82
82
# {ENV_DEL => 'VAR'}
83
83
#   Remove VAR from the environment just before running the corresponding
84
84
#   command, and restore any value just afterwards.
114
114
      ++$Global_count;
115
115
    }
116
116
 
117
 
  warn "creating file `$file' with contents `$data'\n" if $debug;
 
117
  warn "creating file '$file' with contents '$data'\n" if $debug;
118
118
 
119
119
  # The test spec gave a string.
120
120
  # Write it to a temp file and return tempfile name.
130
130
{
131
131
  my ($program_name, $test_name, $in_or_out, $actual, $expected) = @_;
132
132
 
133
 
  my $differ = compare ($expected, $actual);
 
133
  my $differ = compare ($actual, $expected);
134
134
  if ($differ)
135
135
    {
136
136
      my $info = (defined $in_or_out ? "std$in_or_out " : '');
137
137
      warn "$program_name: test $test_name: ${info}mismatch, comparing "
138
 
        . "$actual (actual) and $expected (expected)\n";
 
138
        . "$expected (expected) and $actual (actual)\n";
139
139
      # Ignore any failure, discard stderr.
140
 
      system "diff -c $actual $expected 2>/dev/null";
 
140
      system "diff -c $expected $actual 2>/dev/null";
141
141
    }
142
142
 
143
143
  return $differ;
183
183
  else
184
184
    {
185
185
      # FIXME: put $srcdir in here somewhere
186
 
      warn "$program_name: $test_name: specified file `$file' does"
 
186
      warn "$program_name: $test_name: specified file '$file' does"
187
187
        . " not exist\n"
188
 
          if ! -f "$srcdir/$file";
 
188
          if ! -f "$srcdir/tests/$file";
189
189
    }
190
190
 
191
191
  return $file;
213
213
}
214
214
 
215
215
# FIXME: cleanup on interrupt
216
 
# FIXME: extract `do_1_test' function
 
216
# FIXME: extract 'do_1_test' function
217
217
 
218
218
# FIXME: having to include $program_name here is an expedient kludge.
219
 
# Library code doesn't `die'.
 
219
# Library code doesn't 'die'.
220
220
sub run_tests ($$$$$)
221
221
{
222
222
  my ($program_name, $prog, $t_spec, $save_temps, $verbose) = @_;
314
314
            . " expected 1\n"
315
315
              if $n != 1;
316
316
          my ($type, $val) = each %$io_spec;
317
 
          die "$program_name: $test_name: invalid key `$type' in test spec\n"
 
317
          die "$program_name: $test_name: invalid key '$type' in test spec\n"
318
318
            if ! $Types{$type};
319
319
 
320
320
          # Make sure there's no more than one of OUT, ERR, EXIT, etc.
350
350
                        or die "$program_name: $test_name: CMP spec has $n "
351
351
                          . "elements -- expected 1\n";
352
352
 
353
 
                      # Replace any `@AUX@' in the key of %$e.
 
353
                      # Replace any '@AUX@' in the key of %$e.
354
354
                      my ($ff, $val) = each %$e;
355
355
                      my $new_ff = _at_replace $expect, $ff;
356
356
                      if ($new_ff ne $ff)
474
474
            and $pushed_env{$env_sym} = $val;
475
475
        }
476
476
 
477
 
      warn "Running command: `$cmd_str'\n" if $debug;
 
477
      warn "Running command: '$cmd_str'\n" if $debug;
478
478
      my $rc = 0xffff & system $cmd_str;
479
479
 
480
480
      # Restore any environment setting we changed via a deletion.
486
486
      if ($rc == 0xff00)
487
487
        {
488
488
          warn "$program_name: test $test_name failed: command failed:\n"
489
 
            . "  `$cmd_str': $!\n";
 
489
            . "  '$cmd_str': $!\n";
490
490
          $fail = 1;
491
491
          goto cleanup;
492
492
        }