diff options
author | Eric Blake <ebb9@byu.net> | 2009-11-04 11:13:39 -0700 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2009-11-05 07:10:40 -0700 |
commit | 31a9937081dc41a5f8d28d71709204e413e09972 (patch) | |
tree | c8d994de7a8a903ec10a0b427059e6c4acebe615 /tests/misc/mktemp | |
parent | d431c61873753673ad9fcbac90db6db04185e307 (diff) | |
download | coreutils-31a9937081dc41a5f8d28d71709204e413e09972.tar.xz |
mktemp: add suffix handling
Now that mkstemps is supported, we might as well use it.
* src/mktemp.c (TMPDIR_OPTION): New enum value.
(longopts): Add new option.
(usage): Document it.
(count_trailing_X_s): Rename...
(count_consecutive_X_s): ...to this, and add parameter.
(mkstemp_len, mkdtemp_len): Add parameter.
(main): Implement new option.
(AUTHORS): Add myself.
* AUTHORS (mktemp): Likewise.
* tests/misc/mktemp: Test new option.
* doc/coreutils.texi (mktemp invocation): Document it.
* NEWS: Likewise.
Fixes http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=548316.
Diffstat (limited to 'tests/misc/mktemp')
-rwxr-xr-x | tests/misc/mktemp | 72 |
1 files changed, 68 insertions, 4 deletions
diff --git a/tests/misc/mktemp b/tests/misc/mktemp index e620311e9..7735f33d1 100755 --- a/tests/misc/mktemp +++ b/tests/misc/mktemp @@ -60,8 +60,8 @@ my @Tests = . "Try `$prog --help' for more information.\n"}, {EXIT => 1} ], ['too-many-q', '-q a b', {EXIT => 1} ], - ['too-few-x', 'foo.XX', - {ERR=>"$prog: too few X's in template `foo.XX'\n"}, {EXIT => 1} ], + ['too-few-x', 'foo.XX', {EXIT => 1}, + {ERR=>"$prog: too few X's in template `foo.XX'\n"}], ['too-few-xq', '-q foo.XX', {EXIT => 1} ], ['1f', 'bar.XXXX', {OUT => "bar.ZZZZ\n"}, @@ -110,8 +110,72 @@ my @Tests = . "with --tmpdir, it may not be absolute\n"}, {EXIT => 1} ], # Suffix after X. - ['invalid-t3', 'aXXXXb', - {ERR=>"$prog: too few X's in template `aXXXXb'\n"}, {EXIT => 1} ], + ['suffix1f', 'aXXXXb', {OUT=>"aZZZZb\n"}, + {OUT_SUBST=>'s,a....b,aZZZZb,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + ['suffix1d', '-d aXXXXb', {OUT=>"aZZZZb\n"}, + {OUT_SUBST=>'s,a....b,aZZZZb,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'D'; }}], + ['suffix1u', '-u aXXXXb', {OUT=>"aZZZZb\n"}, + {OUT_SUBST=>'s,a....b,aZZZZb,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + -e $f and die "dry-run created file"; }}], + + ['suffix2f', 'aXXXXaaXXXXa', {OUT=>"aXXXXaaZZZZa\n"}, + {OUT_SUBST=>'s,a....a$,aZZZZa,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + ['suffix2d', '-d --suffix= aXXXXaaXXXX', {OUT=>"aXXXXaaZZZZ\n"}, + {OUT_SUBST=>'s,a....$,aZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'D'; }}], + + ['suffix3f', '--suffix=b aXXXX', {OUT=>"aZZZZb\n"}, + {OUT_SUBST=>'s,a....b,aZZZZb,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + + ['suffix4f', '--suffix=X aXXXX', {OUT=>"aZZZZX\n"}, + {OUT_SUBST=>'s,^a....,aZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + + ['suffix5f', '--suffix /b aXXXX', {EXIT=>1}, + {ERR=>"$prog: invalid suffix `/b', contains directory separator\n"}], + + ['suffix6f', 'aXXXX/b', {EXIT=>1}, + {ERR=>"$prog: invalid suffix `/b', contains directory separator\n"}], + ['suffix6f-q', '-q aXXXX/b', {EXIT=>1}], + + ['suffix7f', '--suffix= aXXXXb', {EXIT=>1}, + {ERR=>"$prog: with --suffix, template `aXXXXb' must end in X\n"}], + ['suffix7f-q', '-q --suffix= aXXXXb', {EXIT=>1}], + ['suffix7d', '-d --suffix=aXXXXb ""', {EXIT=>1}, + {ERR=>"$prog: with --suffix, template `' must end in X\n"}], + + ['suffix8f', 'aXXXX --suffix=b', {OUT=>"aZZZZb\n"}, + {OUT_SUBST=>'s,^a....,aZZZZ,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + + ['suffix9f', 'aXXXX --suffix=b', {EXIT=>1}, + {ENV=>"POSIXLY_CORRECT=1"}, + {ERR=>"$prog: too many templates\n" + . "Try `$prog --help' for more information.\n"}], + + ['suffix10f', 'aXXb', {EXIT => 1}, + {ERR=>"$prog: too few X's in template `aXXb'\n"}], + ['suffix10d', '-d --suffix=X aXX', {EXIT => 1}, + {ERR=>"$prog: too few X's in template `aXXX'\n"}], + + ['suffix11f', '--suffix=.txt', {OUT=>"./tmp.ZZZZZZZZZZ.txt\n"}, + {ENV=>"TMPDIR=."}, + {OUT_SUBST=>'s,\..{10}\.,.ZZZZZZZZZZ.,'}, + {POST => sub { my ($f) = @_; defined $f or return; chomp $f; + check_tmp $f, 'F'; }}], + # Test template with subdirectory ['tmp-w-slash', '--tmpdir=. a/bXXXX', |