Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / misc / stat-printf
1 #!/bin/sh
2 # Test "stat --printf".
3
4 # Copyright (C) 2005, 2006 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 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 : ${PERL=perl}
22 : ${srcdir=.}
23
24 $PERL -e 1 > /dev/null 2>&1 || {
25   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
26     "so can't run this test"
27   exit 77
28 }
29
30 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
31 require 5.003;
32 use strict;
33
34 (my $ME = $0) =~ s|.*/||;
35 my $prog = 'stat';
36
37 # Turn off localisation of executable's ouput.
38 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
39
40 my @Tests =
41     (
42      # test-name, [option, option, ...] {OUT=>"expected-output"}
43      #
44      ['nl', q!--printf='\n' .!,          {OUT=>"\n"}],
45      ['no-nl', "--printf=%n .",          {OUT=>"."}],
46      ['pct-and-esc', q!--printf='\0%n\0' .!,    {OUT=>"\0.\0"}],
47      ['backslash', q!--printf='\\\\' .!, {OUT=>"\\"}],
48      ['nul', q!--printf='\0' .!,         {OUT=>"\0"}],
49      # Don't bother testing \v, since Perl doesn't handle it.
50      ['bel-etc', q!--printf='\a\b\f\n\r\t' .!, {OUT=>"\a\b\f\n\r\t"}],
51      ['octal-1', q!--printf='\012\377' .!,     {OUT=>"\012\377"}],
52      ['octal-2', q!--printf='.\012a\377b' .!,  {OUT=>".\012a\377b"}],
53      ['hex-1',   q!--printf='\x34\xf' .!,      {OUT=>"\x34\xf"}],
54      ['hex-2',   q!--printf='.\x18p\xfq' .!,   {OUT=>".\x18p\x0fq"}],
55      ['hex-3',   q!--printf='\x' .!,           {OUT=>'x'},
56          {ERR=>"$prog: warning: unrecognized escape `\\x'\n"}],
57
58      # With --format, there *is* a trailing newline.
59      ['f-nl', "--format=%n .",          {OUT=>".\n"}],
60      ['f-nl2', "--format=%n . .",       {OUT=>".\n.\n"}],
61
62      ['end-pct', "--printf=% .",       {OUT=>"%"}],
63      ['pct-pct', "--printf=%% .",      {OUT=>"%"}],
64      ['end-bs',  "--printf='\\' .",    {OUT=>'\\'},
65          {ERR=>"$prog: warning: backslash at end of format\n"}],
66
67      ['err-1', "--printf=%9% .",       {EXIT => 1},
68          {ERR=>"$prog: %9%: invalid directive\n"}],
69      ['err-2', "--printf=%9 .",        {EXIT => 1},
70          {ERR=>"$prog: %9: invalid directive\n"}],
71     );
72
73 my $save_temps = $ENV{DEBUG};
74 my $verbose = $ENV{VERBOSE};
75
76 my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose);
77 exit $fail;
78 EOF