| 1 | # sedparse command line tests |
| 2 | |
| 3 | Just run `clitest --prefix 4 tests/test_cmdline.md` to test this file. |
| 4 | |
| 5 | Note that tests for combining `-e` and `-f` in the same command are made in `test_misc.py`. |
| 6 | |
| 7 | ## Help message |
| 8 | |
| 9 | $ python sedparse.py -h | sed 1q |
| 10 | usage: sedparse.py [-h] [-e script] [-f script-file] [--full] [-v] [-V] |
| 11 | $ |
| 12 | |
| 13 | ## Show version |
| 14 | |
| 15 | Redirecting because in Python 2.7 the version number is sent to STDERR. |
| 16 | |
| 17 | $ python sedparse.py --version 2>&1 | tr -s 0-9 9 |
| 18 | sedparse.py 9.9.9 |
| 19 | $ |
| 20 | |
| 21 | ## No sed script informed |
| 22 | |
| 23 | $ python sedparse.py |
| 24 | sedparse: No sed script to be parsed. Use -e and/or -f. |
| 25 | $ python sedparse.py --full --verbose |
| 26 | sedparse: No sed script to be parsed. Use -e and/or -f. |
| 27 | $ |
| 28 | |
| 29 | ## Error message when using an expression |
| 30 | |
| 31 | $ python sedparse.py -e k |
| 32 | sedparse: -e expression #1, char 1: unknown command: `k' |
| 33 | $ |
| 34 | |
| 35 | ## Error message when using a file |
| 36 | |
| 37 | $ echo k > k.sed |
| 38 | $ echo k | python sedparse.py -f k.sed |
| 39 | sedparse: file k.sed line 1: unknown command: `k' |
| 40 | $ rm k.sed |
| 41 | |
| 42 | ## Error message when using STDIN |
| 43 | |
| 44 | $ echo k | python sedparse.py -f - |
| 45 | sedparse: file - line 1: unknown command: `k' |
| 46 | $ |
| 47 | |
| 48 | ## Runtime errors are sent to STDERR and return 1 |
| 49 | |
| 50 | $ python sedparse.py >/dev/null; echo $? |
| 51 | sedparse: No sed script to be parsed. Use -e and/or -f. |
| 52 | 1 |
| 53 | $ |
| 54 | |
| 55 | Parse errors are already well tested in `test_errors.py`. |
| 56 | |
| 57 | ## Normal execution should print to STDOUT and return zero |
| 58 | |
| 59 | $ python sedparse.py -e x 2>/dev/null; echo $? |
| 60 | [ |
| 61 | { |
| 62 | "cmd": "x", |
| 63 | "line": 1 |
| 64 | } |
| 65 | ] |
| 66 | 0 |
| 67 | $ |
| 68 | |
| 69 | ## Empty sed script |
| 70 | |
| 71 | $ python sedparse.py -e '' |
| 72 | [] |
| 73 | $ touch empty.sed |
| 74 | $ python sedparse.py -f empty.sed |
| 75 | [] |
| 76 | $ cat empty.sed | python sedparse.py -f - |
| 77 | [] |
| 78 | $ rm empty.sed |
| 79 | $ |
| 80 | |
| 81 | ## Both -e and --expression should work |
| 82 | |
| 83 | $ python sedparse.py -e x |
| 84 | [ |
| 85 | { |
| 86 | "cmd": "x", |
| 87 | "line": 1 |
| 88 | } |
| 89 | ] |
| 90 | $ python sedparse.py --expression x |
| 91 | [ |
| 92 | { |
| 93 | "cmd": "x", |
| 94 | "line": 1 |
| 95 | } |
| 96 | ] |
| 97 | $ |
| 98 | |
| 99 | ## Both -f and --file should work |
| 100 | |
| 101 | $ echo x > x.sed |
| 102 | $ python sedparse.py -f x.sed |
| 103 | [ |
| 104 | { |
| 105 | "cmd": "x", |
| 106 | "line": 1 |
| 107 | } |
| 108 | ] |
| 109 | $ python sedparse.py --file x.sed |
| 110 | [ |
| 111 | { |
| 112 | "cmd": "x", |
| 113 | "line": 1 |
| 114 | } |
| 115 | ] |
| 116 | $ rm x.sed |
| 117 | $ |