1#!/bin/bash
2
3# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
4# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
5
6[ -f testing.sh ] && . testing.sh
7
8#testing "name" "command" "result" "infile" "stdin"
9
10echo "abcdefghijklmnopqrstuvwxyz" > file.txt
11testing "Remove text-file" "rm file.txt && [ ! -e file.txt ] && echo 'yes'" "yes\n" "" ""
12rm -f file*
13
14mkdir dir
15testing "Remove empty directory" "rm -r dir && [ ! -d dir ] && echo 'yes'" "yes\n" "" ""
16rm -rf dir
17
18echo "abcdefghijklmnopqrstuvwxyz" > file.txt && chmod 000 file.txt
19testing "Remove text file(mode 000)" "rm -f file.txt && [ ! -e file.txt ] && echo 'yes'" \
20  "yes\n" "" ""
21rm -f file*
22
23touch file1.txt file2.txt
24mkdir dir1 dir2
25testing "rm -r (multiple files and dirs)" \
26  "rm -r file1.txt file2.txt dir1 dir2 2>/dev/null &&
27   [ ! -e file1.txt -a ! -e file2.txt -a ! -d dir1 -a ! -d dir2 ] && echo 'yes'" \
28  "yes\n" "" ""
29rm -rf file* dir*
30
31touch file1.txt file2.txt
32mkdir dir1 dir2
33testing "rm -rf (present + missing files and dirs)" \
34  "rm -rf file1.txt file2.txt file3.txt dir1 dir2 dir3 2>/dev/null &&
35  [ ! -e file1.txt -a ! -e file2.txt -a ! -d dir1 -a ! -d dir2 ] && echo 'yes'" \
36  "yes\n" "" ""
37rm -rf file* dir*
38
39# testing with nested dirs.
40mkdir -p dir1/dir2/dir3 dir1/dir2/dir4
41touch dir1/file1.txt dir1/dir2/file2.txt dir1/dir2/dir3/file3.txt
42testing "rm -r nested_dir" "rm -r dir1/dir2/ 2>/dev/null &&
43  [ -d dir1 -a -f dir1/file1.txt -a ! -d dir1/dir2 ] && echo 'yes'" \
44  "yes\n" "" ""
45rm -rf dir*
46
47