1#!/usr/bin/perl 2# Make sure that rm -r '' fails. 3 4# Copyright (C) 1998-2023 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 <https://www.gnu.org/licenses/>. 18 19# On SunOS 4.1.3, running rm -r '' in a nonempty directory may 20# actually remove files with names of entries in the current directory 21# but relative to '/' rather than relative to the current directory. 22 23use strict; 24 25(my $program_name = $0) =~ s|.*/||; 26 27# Turn off localization of executable's output. 28@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; 29 30my $prog = 'rm'; 31 32# FIXME: copied from misc/ls-misc; factor into Coreutils.pm? 33sub mk_file(@) 34{ 35 foreach my $f (@_) 36 { 37 open (F, '>', $f) && close F 38 or die "creating $f: $!\n"; 39 } 40} 41 42my @Tests = 43 ( 44 # test-name options input expected-output 45 # 46 ['empty-name-1', "''", {EXIT => 1}, 47 {ERR => "$prog: cannot remove '': No such file or directory\n"}], 48 49 ['empty-name-2', "a '' b", {EXIT => 1}, 50 {ERR => "$prog: cannot remove '': No such file or directory\n"}, 51 {PRE => sub { mk_file qw(a b) }}, 52 {POST => sub {-f 'a' || -f 'b' and die "a or b remain\n" }}, 53 ], 54 ); 55 56my $save_temps = $ENV{SAVE_TEMPS}; 57my $verbose = $ENV{VERBOSE}; 58 59my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); 60exit $fail; 61