Rob Landley | dd28202 | 2008-02-16 20:00:11 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | [ -f testing.sh ] && . testing.sh |
| 4 | |
| 5 | # Create test file |
Rob Landley | 0a2d88a | 2008-05-04 16:00:52 -0500 | [diff] [blame] | 6 | dd if=/dev/urandom of=random bs=64 count=1 2> /dev/null |
Rob Landley | dd28202 | 2008-02-16 20:00:11 -0600 | [diff] [blame] | 7 | |
| 8 | #testing "name" "command" "result" "infile" "stdin" |
| 9 | |
| 10 | testing "cp not enough arguments [fail]" "cp one 2>/dev/null || echo yes" \ |
| 11 | "yes\n" "" "" |
| 12 | testing "cp -missing source [fail]" "cp missing two 2>/dev/null || echo yes" \ |
| 13 | "yes\n" "" "" |
| 14 | testing "cp file->file" "cp random two && cmp random two && echo yes" \ |
| 15 | "yes\n" "" "" |
| 16 | rm two |
| 17 | |
| 18 | mkdir two |
| 19 | testing "cp file->dir" "cp random two && cmp random two/random && echo yes" \ |
| 20 | "yes\n" "" "" |
| 21 | rm two/random |
| 22 | testing "cp file->dir/file" \ |
| 23 | "cp random two/random && cmp random two/random && echo yes" \ |
| 24 | "yes\n" "" "" |
| 25 | testing "cp -r dir->missing" \ |
| 26 | "cp -r two three && cmp random three/random && echo yes" \ |
Rob Landley | 7aa651a | 2012-11-13 17:14:08 -0600 | [diff] [blame] | 27 | "yes\n" "" "" |
Rob Landley | dd28202 | 2008-02-16 20:00:11 -0600 | [diff] [blame] | 28 | touch walrus |
| 29 | testing "cp -r dir->file [fail]" \ |
| 30 | "cp -r two walrus 2>/dev/null || echo yes" "yes\n" "" "" |
| 31 | touch two/three |
| 32 | testing "cp -r dir hits file." \ |
| 33 | "cp -r three two 2>/dev/null || echo yes" "yes\n" "" "" |
| 34 | rm -rf two three walrus |
| 35 | |
| 36 | touch two |
| 37 | chmod 000 two |
| 38 | testing "cp file->inaccessable [fail]" \ |
| 39 | "cp random two 2>/dev/null || echo yes" "yes\n" "" "" |
| 40 | rm -f two |
| 41 | |
| 42 | touch two |
| 43 | chmod 000 two |
| 44 | testing "cp -f file->inaccessable" \ |
| 45 | "cp -f random two && cmp random two && echo yes" "yes\n" "" "" |
| 46 | mkdir sub |
| 47 | chmod 000 sub |
| 48 | testing "cp file->inaccessable_dir [fail]" \ |
| 49 | "cp random sub 2>/dev/null || echo yes" "yes\n" "" "" |
| 50 | rm two |
| 51 | rmdir sub |
| 52 | |
Rob Landley | fbe5dda | 2014-07-14 05:38:27 -0500 | [diff] [blame] | 53 | # This test fails because our -rf deletes existing target files without |
| 54 | # regard to what we'd be copying over it. Posix says to only do that if |
| 55 | # we'd be copying a file over the file, but does not say _why_. |
| 56 | |
| 57 | #mkdir dir |
| 58 | #touch file |
| 59 | #testing "cp -rf dir file [fail]" "cp -rf dir file 2>/dev/null || echo yes" \ |
| 60 | # "yes\n" "" "" |
| 61 | #rm -rf dir file |
Rob Landley | dd28202 | 2008-02-16 20:00:11 -0600 | [diff] [blame] | 62 | |
| 63 | touch one two |
| 64 | testing "cp file1 file2 missing [fail]" \ |
| 65 | "cp one two missing 2>/dev/null || echo yes" "yes\n" "" "" |
| 66 | mkdir dir |
| 67 | testing "cp dir file missing [fail]" \ |
| 68 | "cp dir two missing 2>/dev/null || echo yes" "yes\n" "" "" |
| 69 | testing "cp -rf dir file missing [fail]" \ |
| 70 | "cp dir two missing 2>/dev/null || echo yes" "yes\n" "" "" |
| 71 | testing "cp file1 file2 file [fail]" \ |
| 72 | "cp random one two 2>/dev/null || echo yes" "yes\n" "" "" |
| 73 | testing "cp file1 file2 dir" \ |
| 74 | "cp random one dir && cmp random dir/random && cmp one dir/one && echo yes" \ |
| 75 | "yes\n" "" "" |
| 76 | rm one two random |
| 77 | rm -rf dir |
| 78 | |
Rob Landley | 5ba6663 | 2008-03-25 17:09:40 -0500 | [diff] [blame] | 79 | mkdir -p one/two/three/four |
| 80 | touch one/two/three/five |
| 81 | touch one/{six,seven,eight} |
| 82 | testing "cp -r /abspath dest" \ |
| 83 | "cp -r \"$(readlink -f one)\" dir && diff -r one dir && echo yes" \ |
| 84 | "yes\n" "" "" |
Rob Landley | 50c8c02 | 2008-03-26 00:54:56 -0500 | [diff] [blame] | 85 | testing "cp -r dir again" "cp -r one/. dir && diff -r one dir && echo yes" \ |
| 86 | "yes\n" "" "" |
Rob Landley | 5ba6663 | 2008-03-25 17:09:40 -0500 | [diff] [blame] | 87 | mkdir dir2 |
| 88 | testing "cp -r dir1/* dir2" \ |
| 89 | "cp -r one/* dir2 && diff -r one dir2 && echo yes" "yes\n" "" "" |
Rob Landley | 50c8c02 | 2008-03-26 00:54:56 -0500 | [diff] [blame] | 90 | rm -rf one dir dir2 |
Rob Landley | 6e6871c | 2008-02-20 01:47:56 -0600 | [diff] [blame] | 91 | |
Rob Landley | 5ba6663 | 2008-03-25 17:09:40 -0500 | [diff] [blame] | 92 | # cp -r ../source destdir |
| 93 | # cp -r one/two/three missing |
| 94 | # cp -r one/two/three two |
| 95 | # mkdir one; touch one/two; ln -s two one/three |
Rob Landley | dd28202 | 2008-02-16 20:00:11 -0600 | [diff] [blame] | 96 | # cp file1 file2 dir |
| 97 | # cp file1 missing file2 -> dir |
Rob Landley | 5ba6663 | 2008-03-25 17:09:40 -0500 | [diff] [blame] | 98 | |
| 99 | # Make sure it's truncating existing file |
| 100 | # copy with -d at top level, with -d in directory, without -d at top level, |
| 101 | # without -d in directory |