Compare commits
	
		
			41 Commits
		
	
	
		
			tap
			...
			more-shell
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 7126872a8b | ||
|  | 96ab43c233 | ||
|  | 2be0151213 | ||
|  | 655daf4b74 | ||
|  | 31023bce21 | ||
|  | d96f3707e9 | ||
|  | 3f05794d7e | ||
|  | d7c8549206 | ||
|  | bc74b20c5c | ||
|  | 8bdd00c3e9 | ||
|  | 42dd0947e8 | ||
|  | da6d89aa56 | ||
|  | 3ea035d188 | ||
|  | 8e669c40a6 | ||
|  | 66c010b694 | ||
|  | 7339e84d7c | ||
|  | e364d40f3a | ||
|  | 13e748d684 | ||
|  | bb42d27917 | ||
|  | c1ec06c6fe | ||
|  | 5382946639 | ||
|  | 144013c71c | ||
|  | 009fd7ea05 | ||
|  | c3901fe175 | ||
|  | 538c8437a7 | ||
|  | cd124e09ee | ||
|  | d963f10be1 | ||
|  | 0ca55d155b | ||
|  | 8d55550248 | ||
|  | 0f86778d79 | ||
|  | 92cb735bb7 | ||
|  | c817355e94 | ||
|  | d4bedbbfcf | ||
|  | f6b57772f2 | ||
|  | 72fa30e787 | ||
|  | eda4a6e42c | ||
|  | df80586d79 | ||
|  | d525c1793b | ||
|  | 56a4e5d8af | ||
|  | d81b7efdc3 | ||
|  | 7f5455739d | 
							
								
								
									
										9
									
								
								AUTHORS
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								AUTHORS
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| Authors | ||||
| ------- | ||||
| David Jones | ||||
| Michael Klement | ||||
| Thomas Levine | ||||
|  | ||||
| Maintainer | ||||
| ------- | ||||
| Thomas Levine <_@thomaslevine.com> | ||||
							
								
								
									
										20
									
								
								HISTORY
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								HISTORY
									
									
									
									
									
								
							| @@ -1,5 +1,23 @@ | ||||
| HISTORY | ||||
| ------- | ||||
| ======= | ||||
|  | ||||
| Version 0.0.6 | ||||
| --------------------- | ||||
|  | ||||
| * Produce TAP output with the -t flag. | ||||
| * Add a + sign in front of directories in the normal output so that they | ||||
|   line up with non-directories. | ||||
| * Display skipped tests in the normal output and in the TAP output. | ||||
| * Correct some things in the documentation. | ||||
| * Rearrange things in the documentation to be more clear. | ||||
| * Pass the -e flag to exit urchin if any single test fails. | ||||
| * Remove the undocumented, experimental -x flag now that shall exists. | ||||
| * Display version number with the -v flag. | ||||
| * Document why Urchin is called "Urchin" | ||||
|  | ||||
| These changes are made somewhat separately in the branches "exit-on-fail", | ||||
| "remove-urchin-x", "tap", and "update-readme". They are rebased into one | ||||
| branch, "tlevine-2016-02", for merging into "master". | ||||
|  | ||||
| Version 0.0.5 | ||||
| --------------------- | ||||
|   | ||||
| @@ -2,11 +2,11 @@ | ||||
| # Run urchin in a bunch of different shells, | ||||
| # including a shell that isn't quite POSIX-compatible (zsh) | ||||
|  | ||||
| for shell in dash bash ksh zsh; do | ||||
| for shell in dash bash mksh ksh zsh; do | ||||
|   if which $shell > /dev/null 2> /dev/null; then | ||||
|     echo | ||||
|     echo Running urchin tests in $shell | ||||
|     $shell urchin -s $shell tests | tail -n 3 | ||||
|     $shell urchin -s $shell tests | tail -n 4 | ||||
|   else | ||||
|     echo | ||||
|     echo Skipping $shell because it is not in the PATH | ||||
|   | ||||
							
								
								
									
										73
									
								
								readme.md
									
									
									
									
									
								
							
							
						
						
									
										73
									
								
								readme.md
									
									
									
									
									
								
							| @@ -4,9 +4,13 @@ | ||||
|     / /_/ / /  / /__/ / / / / / / / | ||||
|     \__,_/_/   \___/_/ /_/_/_/ /_/  | ||||
|  | ||||
| Urchin is a test framework for shell. It is implemented in | ||||
| portable /bin/sh and should work on GNU/Linux, Mac OS X, and | ||||
| other Unix platforms. | ||||
| Urchin is a file-based test harness, normally used for testing shell programs. | ||||
| It is written in portable shell and should thus work on GNU/Linux, BSD | ||||
| (including Mac OS X), and other Unix-like platforms. | ||||
|  | ||||
| Urchin is called "Urchin" because | ||||
| [sea urchins](https://en.wikipedia.org/wiki/Sea_urchin) | ||||
| have shells called "tests". | ||||
|  | ||||
| ## Try it out | ||||
| Urchin's tests are written in Urchin, so you can run them to see what Urchin | ||||
| @@ -27,14 +31,15 @@ run this: | ||||
|     cd urchin | ||||
|     ./cross-shell-tests | ||||
|  | ||||
| ## Globally | ||||
| Download Urchin like so (as root) (or use npm, below): | ||||
| ## Install | ||||
| Urchin is contained in a single file, so you can install it by copying it to a | ||||
| directory in your `PATH`. For example, you can run the following as root. | ||||
|  | ||||
|     cd /usr/local/bin | ||||
|     wget https://raw.github.com/tlevine/urchin/master/urchin | ||||
|     chmod +x urchin | ||||
|  | ||||
| Can be installed with npm too: | ||||
| Urchin can be installed with npm too. | ||||
|  | ||||
|     npm install -g urchin | ||||
|  | ||||
| @@ -86,15 +91,14 @@ Files are only run if they are executable, and files beginning with `.` are | ||||
| ignored. Thus, fixtures and libraries can be included sloppily within the test | ||||
| directory tree. The test passes if the file exits 0; otherwise, it fails. | ||||
|  | ||||
| In case you care about the order in which your tests execute, consider that | ||||
| Tests files and subdirectories are run in ASCIIbetical order within each | ||||
| directory; that is, | ||||
| urchin looks for files within a directory in the following manner. | ||||
|  | ||||
|     for file in *; do | ||||
|       do_something_with_test_file $file | ||||
|     done | ||||
|  | ||||
| Tests within a directory are executed in whatever order `*` returns. | ||||
|  | ||||
| ### Writing cross-shell compatibility tests for testing shell code | ||||
|  | ||||
| While you could write your test scripts to explicitly invoke the functionality | ||||
| @@ -106,24 +110,20 @@ The specific approach depends on your test scenario: | ||||
| * (b) Your scripts _source_ scripts containing portable shell code. | ||||
|  | ||||
| #### (a) Cross-shell tests with test scripts that _invoke_ shell scripts | ||||
| Urchin sets the `TEST_SHELL` environment variable so that you may change the | ||||
| shell with which your tests call other shell programs. To run your test | ||||
| scripts in multiple shells you must call `$TEST_SHELL` in your tests and then | ||||
| run urchin with the appropriate option. | ||||
|  | ||||
| First, consider using [shall](https://github.com/mklement0/shall). | ||||
|  | ||||
|     #!/usr/bin/env shall | ||||
|     echo This is a test file. | ||||
|  | ||||
| Alternatively, you can use urchin's built-in recognition of the | ||||
| `TEST_SHELL` environment variable. | ||||
| In your test scripts, invoke the shell scripts to test via the shell | ||||
| specified in environment variable `TEST_SHELL` rather than directly; | ||||
| e.g.: `$TEST_SHELL ../foo bar` (rather than just `../foo bar`).   | ||||
| Note that if you alsow want your test scripts to work when run directly, | ||||
| outside of Urchin, be sure to target scripts that happen to be in the  | ||||
| current directory with prefix `./`; e.g., `$TEST_SHELL ./baz` | ||||
| (rather than `$TEST_SHELL baz`). | ||||
|  | ||||
| Then, on invocation of Urchin, prepend a definition of environment variable | ||||
| `TEST_SHELL` specifying the shell to test with, e.g.: `TEST_SHELL=zsh urchin ./tests`.   | ||||
| On invocation of Urchin, prepend a definition of environment variable | ||||
| `TEST_SHELL` specifying the shell to test with, e.g., | ||||
|  | ||||
|     TEST_SHELL=zsh urchin ./tests | ||||
|  | ||||
| To test with multiple shells in sequence, use something like: | ||||
|  | ||||
|     for shell in sh bash ksh zsh; do | ||||
| @@ -131,14 +131,20 @@ To test with multiple shells in sequence, use something like: | ||||
|     done | ||||
|  | ||||
| If `TEST_SHELL` has no value, Urchin defines it as `/bin/sh`, so the test | ||||
| scripts can rely on `$TEST_SHELL` always containing a value. | ||||
| scripts can rely on `$TEST_SHELL` always containing a value when Urchin runs | ||||
| them. | ||||
|  | ||||
| That said, we still recommand that you account for the possibility that | ||||
| `$TEST_SHELL` does not contain a value so that you may run your test scripts | ||||
| without Urchin. Supporting this case is very simple; when you invoke scripts | ||||
| that happen to be in the current directory, be sure to use the prefix `./`, | ||||
| e.g., `$TEST_SHELL ./baz` rather than `$TEST_SHELL baz`. | ||||
|  | ||||
| #### (b) Cross-shell tests with test scripts that _source_ shell scripts | ||||
|  | ||||
| If you _source_ shell code in your test scripts, it is the test scripts | ||||
| themselves that must be run with the shell specified. | ||||
|  | ||||
| To that end, Urchin supports the `-s <shell>` option, which instructs | ||||
| Urchin supports the `-s <shell>` option, which instructs | ||||
| Urchin to invoke the test scripts with the specified shell; e.g., `-s bash`.   | ||||
| (In addition, Urchin sets environment variable `TEST_SHELL` to the specified | ||||
| shell.) | ||||
| @@ -154,21 +160,12 @@ To test with multiple shells in sequence, use something like: | ||||
|       urchin -s $shell ./tests | ||||
|     done | ||||
|  | ||||
| <!-- | ||||
| #### (c) Cross shell tests with `urchin -x` (experimental) | ||||
| If you run urchin with the `-x` flag, it will be as if you ran | ||||
| `$TEST_SHELL`. Unless `$TEST_SHELL` isn't set, in which case it'll | ||||
| be as if you ran `/bin/sh`. Putting this in she shebang line might | ||||
| eventually work out to be a cleaner way of doing cross-shell testing. | ||||
| Also consider using [shall](https://github.com/mklement0/shall). | ||||
| It does something similar, but the interface may be more intuitive. | ||||
|  | ||||
|     #!/usr/bin/env urchin -x | ||||
|     test a = a | ||||
|     #!/usr/bin/env shall | ||||
|     echo This is a test file. | ||||
|  | ||||
| It might make sense if you do this. | ||||
|  | ||||
|     export TEST_SHELL=zsh && urchin -x | ||||
|     export TEST_SHELL=bash && urchin -x | ||||
| --> | ||||
| ## Alternatives to Urchin | ||||
| Alternatives to Urchin are discussed in | ||||
| [this blog post](https://blog.scraperwiki.com/2012/12/how-to-test-shell-scripts/). | ||||
|   | ||||
							
								
								
									
										0
									
								
								tests/.die-on-fail/1 should run.
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										0
									
								
								tests/.die-on-fail/1 should run.
									
									
									
									
									
										Executable file
									
								
							
							
								
								
									
										1
									
								
								tests/.die-on-fail/2 should run.
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										1
									
								
								tests/.die-on-fail/2 should run.
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1 @@ | ||||
| false | ||||
							
								
								
									
										1
									
								
								tests/.die-on-fail/3 should not run.
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										1
									
								
								tests/.die-on-fail/3 should not run.
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1 @@ | ||||
| false | ||||
							
								
								
									
										1
									
								
								tests/.die-on-fail/4 should not run.
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										1
									
								
								tests/.die-on-fail/4 should not run.
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1 @@ | ||||
| false | ||||
							
								
								
									
										11
									
								
								tests/Exit on fail if -e is passed.
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										11
									
								
								tests/Exit on fail if -e is passed.
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| tmp=$(mktemp) | ||||
| ../urchin -e -f ./.die-on-fail > $tmp | ||||
| result=$? | ||||
|  | ||||
| grep '1 should run.' $tmp | ||||
| grep '2 should run.' $tmp | ||||
| grep -v '3 should not run.' $tmp | ||||
| grep -v '4 should not run.' $tmp | ||||
|  | ||||
| rm $tmp | ||||
| exit $result | ||||
							
								
								
									
										2
									
								
								tests/Print version on -v.
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										2
									
								
								tests/Print version on -v.
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| #!/bin/sh | ||||
| ../urchin -v | grep '[0-9.]\{3,\}' | ||||
							
								
								
									
										26
									
								
								urchin
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								urchin
									
									
									
									
									
								
							| @@ -4,6 +4,9 @@ | ||||
| # which breaks fullpath(). | ||||
| unset CDPATH | ||||
|  | ||||
| # Urchin version number | ||||
| VERSION=0.0.6 | ||||
|  | ||||
| fullpath() { | ||||
|   ( | ||||
|     cd -- "$1" | ||||
| @@ -54,6 +57,13 @@ recurse() { | ||||
|  | ||||
|         # $2 instead of $indent_level so it doesn't clash | ||||
|         recurse "${test}" $(( $2 + 1 )) "$shell_for_sh_tests" | ||||
|         exit_code=$? | ||||
|  | ||||
|         if $exit_on_fail && test $exit_code -ne 0; then | ||||
|           [ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file" | ||||
|           [ -f teardown_dir ] && [ -x teardown_dir ] && ./teardown_dir >> "$stdout_file" | ||||
|           return 1 | ||||
|         fi | ||||
|  | ||||
|         [ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file" | ||||
|       done | ||||
| @@ -68,7 +78,6 @@ recurse() { | ||||
|   else | ||||
|     if [ -x "$potential_test" ] | ||||
|       then | ||||
|  | ||||
|       [ -f setup ] && [ -x setup ] && ./setup >> "$stdout_file" | ||||
|  | ||||
|       # Run the test | ||||
| @@ -80,7 +89,6 @@ recurse() { | ||||
|       fi | ||||
|       exit_code="$?" | ||||
|  | ||||
|  | ||||
|       [ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file" | ||||
|       if [ $exit_code -eq 0 ]; then | ||||
|         result=success | ||||
| @@ -132,6 +140,10 @@ recurse() { | ||||
|         ;; | ||||
|       esac | ||||
|     fi | ||||
|  | ||||
|     if $exit_on_fail && test 0 -ne $exit_code; then | ||||
|       return 1 | ||||
|     fi | ||||
|   fi | ||||
|   [ $indent_level -eq 0 ] && rm "$stdout_file" | ||||
| } | ||||
| @@ -151,10 +163,14 @@ $USAGE | ||||
|  | ||||
| -s <shell>  Invoke test scripts that either have no shebang line at all or | ||||
|             have shebang line "#!/bin/sh" with the specified shell. | ||||
| -e          Stop running if any single test fails. This is helpful if you want | ||||
|             to use Urchin to run things other than tests, such as a set of | ||||
|             configuration scripts. | ||||
| -f          Force running even if the test directory's name does not | ||||
|             contain the word "test". | ||||
| -t          Format output in Test Anything Protocol (TAP) | ||||
| -h          This help. | ||||
| -h, --help  This help. | ||||
| -v          Display the version number. | ||||
|  | ||||
| Go to https://github.com/tlevine/urchin for documentation on writing tests. | ||||
|  | ||||
| @@ -231,10 +247,12 @@ urchin_molly_guard() { | ||||
|  | ||||
| shell_for_sh_tests= | ||||
| force=false | ||||
| exit_on_fail=false | ||||
| tap_format=false | ||||
| while [ $# -gt 0 ] | ||||
| do | ||||
|     case "$1" in | ||||
|         -e) exit_on_fail=true;; | ||||
|         -f) force=true;; | ||||
|         -s) | ||||
|           shift | ||||
| @@ -244,6 +262,8 @@ do | ||||
|         -t) tap_format=true;; | ||||
|         -h|--help) urchin_help | ||||
|           exit 0;; | ||||
|         -v) echo "$VERSION" | ||||
|             exit;; | ||||
|         -*) urchin_help >&2 | ||||
|             exit 1;; | ||||
|         *)  break;; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user