Compare commits
	
		
			4 Commits
		
	
	
		
			single-fil
			...
			parallel
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					dc0a030f71 | ||
| 
						 | 
					41a63f003c | ||
| 
						 | 
					aa05b95715 | ||
| 
						 | 
					c611667152 | 
							
								
								
									
										31
									
								
								HISTORY
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								HISTORY
									
									
									
									
									
								
							@@ -4,40 +4,9 @@ HISTORY
 | 
			
		||||
Version 0.0.7
 | 
			
		||||
---------------------
 | 
			
		||||
 | 
			
		||||
### Molly-guard
 | 
			
		||||
The Molly-guard is now more accepting. For example, you no longer need to
 | 
			
		||||
pass -f in this case: https://github.com/creationix/nvm/issues/357
 | 
			
		||||
 | 
			
		||||
### Skipping tests
 | 
			
		||||
Previously, tests were run if they were executable and were otherwise marked
 | 
			
		||||
as skipped. Now, an executable script can indicate that it is skipped by
 | 
			
		||||
exiting with code 3.  For example, if a test requires some dependancy, it
 | 
			
		||||
might look for the dependency and then skip if it does not see the dependency.
 | 
			
		||||
It might look like this.
 | 
			
		||||
 | 
			
		||||
    #!/bin/sh
 | 
			
		||||
    if which inkscape; then
 | 
			
		||||
      exit 3 # status code 3 for skip
 | 
			
		||||
    fi
 | 
			
		||||
    inkscape blah blah ...
 | 
			
		||||
 | 
			
		||||
I chose status code 3 sort of arbitrarily at first, but it turns out that it
 | 
			
		||||
would the appropriate status code if these tests were Nagios plugins, as the
 | 
			
		||||
concept of skipping a test is similar to the Nagios concept of unknown service
 | 
			
		||||
status (https://nagios-plugins.org/doc/guidelines.html#AEN78).
 | 
			
		||||
 | 
			
		||||
### Run on a file
 | 
			
		||||
It is now possible to run urchin on a single file.
 | 
			
		||||
This occurred to me when I wanted to run
 | 
			
		||||
 | 
			
		||||
    urchin test/fast/Unit\ tests/nvm_ls_current
 | 
			
		||||
 | 
			
		||||
on the nvm tests. I wound up running this instead.
 | 
			
		||||
 | 
			
		||||
    urchin test/fast/Unit\ tests/ | grep nvm_ls_current
 | 
			
		||||
 | 
			
		||||
The Molly guard is assessed, and the corresponding setup, setup_dir,
 | 
			
		||||
teardown, and teardown_dir files are run in the appropriate order.
 | 
			
		||||
 | 
			
		||||
Version 0.0.6
 | 
			
		||||
---------------------
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								TODO
									
									
									
									
									
								
							@@ -1,6 +1,18 @@
 | 
			
		||||
Things I want
 | 
			
		||||
=============
 | 
			
		||||
 | 
			
		||||
Skip tests
 | 
			
		||||
-------------
 | 
			
		||||
I want tests to be able to decide to skip themselves. For example, if a test
 | 
			
		||||
requires some dependancy, it might look for the dependency and then skip if it
 | 
			
		||||
does not see the dependency. It might look like this.
 | 
			
		||||
 | 
			
		||||
    #!/bin/sh
 | 
			
		||||
    if which parallel > /dev/null; then
 | 
			
		||||
      exit 3 # status code 3 for skip
 | 
			
		||||
    fi
 | 
			
		||||
    parallel blah blah ...
 | 
			
		||||
 | 
			
		||||
Test speed
 | 
			
		||||
-------------
 | 
			
		||||
Make tests run faster.
 | 
			
		||||
@@ -123,6 +135,22 @@ cleanly create and teardown temporary files.
 | 
			
		||||
On the other hand, this could just be sourced explicitly in the test file,
 | 
			
		||||
without the special setup and teardown feature.
 | 
			
		||||
 | 
			
		||||
Run on a file
 | 
			
		||||
----------------
 | 
			
		||||
Presently you can run urchin only on a directory.
 | 
			
		||||
It would be neat if you could run it on a file as well.
 | 
			
		||||
 | 
			
		||||
This occurred to me when I wanted to run
 | 
			
		||||
 | 
			
		||||
    urchin test/fast/Unit\ tests/nvm_ls_current
 | 
			
		||||
 | 
			
		||||
on the nvm tests. I wound up running this instead.
 | 
			
		||||
 | 
			
		||||
    urchin test/fast/Unit\ tests/ | grep nvm_ls_current
 | 
			
		||||
 | 
			
		||||
The Molly guard would be assessed, and the corresponding setup, setup_dir,
 | 
			
		||||
teardown, and teardown_dir files would be run in the appropriate order.
 | 
			
		||||
 | 
			
		||||
Running automated tasks
 | 
			
		||||
-------------------------
 | 
			
		||||
Urchin might be appropriate for if you have lots of tasks that you want to run
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
tmp=$(mktemp)
 | 
			
		||||
../urchin -e -f ./.die-on-fail > $tmp
 | 
			
		||||
../urchin -e -b -f ./.die-on-fail > $tmp
 | 
			
		||||
result=$?
 | 
			
		||||
 | 
			
		||||
grep '1 should run.' $tmp
 | 
			
		||||
 
 | 
			
		||||
@@ -1 +0,0 @@
 | 
			
		||||
echo setup
 | 
			
		||||
@@ -1 +0,0 @@
 | 
			
		||||
echo setup_dir
 | 
			
		||||
@@ -1 +0,0 @@
 | 
			
		||||
echo teardown
 | 
			
		||||
@@ -1 +0,0 @@
 | 
			
		||||
echo teardown_dir
 | 
			
		||||
@@ -1,2 +0,0 @@
 | 
			
		||||
echo thetest
 | 
			
		||||
exit 1
 | 
			
		||||
@@ -1,3 +0,0 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
../../urchin .test
 | 
			
		||||
# This will exit 0 if it worked.
 | 
			
		||||
@@ -1,2 +0,0 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
! ../../urchin not-a-file
 | 
			
		||||
@@ -1,4 +0,0 @@
 | 
			
		||||
tmp=$(mktemp)
 | 
			
		||||
echo "Using temp file $tmp"
 | 
			
		||||
../../urchin .wrappers > $tmp
 | 
			
		||||
diff $tmp .wrapper-expectation
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
tmp=$(mktemp)
 | 
			
		||||
 | 
			
		||||
../../urchin -t .testsuite/ | sed 1d > $tmp
 | 
			
		||||
../../urchin -b -t .testsuite/ | sed 1d > $tmp
 | 
			
		||||
diff $tmp .expected-output
 | 
			
		||||
 
 | 
			
		||||
@@ -1 +0,0 @@
 | 
			
		||||
exit 1
 | 
			
		||||
@@ -1 +0,0 @@
 | 
			
		||||
exit 3
 | 
			
		||||
@@ -1 +0,0 @@
 | 
			
		||||
exit 0
 | 
			
		||||
@@ -1 +0,0 @@
 | 
			
		||||
test $(../../urchin -t .test/ | grep -c SKIP) -eq 1
 | 
			
		||||
							
								
								
									
										67
									
								
								urchin
									
									
									
									
									
								
							
							
						
						
									
										67
									
								
								urchin
									
									
									
									
									
								
							@@ -16,6 +16,13 @@ unset CDPATH
 | 
			
		||||
# Urchin version number
 | 
			
		||||
VERSION=0.0.6
 | 
			
		||||
 | 
			
		||||
fullpath() {
 | 
			
		||||
  (
 | 
			
		||||
    cd -- "$1"
 | 
			
		||||
    pwd
 | 
			
		||||
  )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
indent() {
 | 
			
		||||
  level="$1"
 | 
			
		||||
  if test "$level" -gt 0; then
 | 
			
		||||
@@ -60,17 +67,23 @@ recurse() {
 | 
			
		||||
        [ -f setup ] && [ -x setup ] && ./setup >> "$stdout_file"
 | 
			
		||||
 | 
			
		||||
        # $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
 | 
			
		||||
        (
 | 
			
		||||
          recurse "${test}" $(( $2 + 1 )) "$shell_for_sh_tests"
 | 
			
		||||
          exit_code=$?
 | 
			
		||||
          [ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file"
 | 
			
		||||
          [ -f teardown_dir ] && [ -x teardown_dir ] && ./teardown_dir >> "$stdout_file"
 | 
			
		||||
          return 1
 | 
			
		||||
        fi
 | 
			
		||||
          exit $exit_code
 | 
			
		||||
        ) &
 | 
			
		||||
 | 
			
		||||
        [ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file"
 | 
			
		||||
        if $single_process; then
 | 
			
		||||
          wait $!
 | 
			
		||||
          exit_code=$?
 | 
			
		||||
          if $exit_on_fail && test $exit_code -ne 0; then
 | 
			
		||||
            [ -f teardown_dir ] && [ -x teardown_dir ] && ./teardown_dir >> "$stdout_file"
 | 
			
		||||
            return 1
 | 
			
		||||
          fi
 | 
			
		||||
        fi
 | 
			
		||||
      done
 | 
			
		||||
      wait
 | 
			
		||||
      [ -f teardown_dir ] && [ -x teardown_dir ] && ./teardown_dir >> "$stdout_file"
 | 
			
		||||
    )
 | 
			
		||||
    if $tap_format; then
 | 
			
		||||
@@ -91,13 +104,12 @@ recurse() {
 | 
			
		||||
      else
 | 
			
		||||
        TEST_SHELL="$TEST_SHELL" ./"$potential_test" > "$stdout_file" 2>&1
 | 
			
		||||
      fi
 | 
			
		||||
 | 
			
		||||
      exit_code="$?"
 | 
			
		||||
 | 
			
		||||
      [ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file"
 | 
			
		||||
      if [ $exit_code -eq 0 ]; then
 | 
			
		||||
        result=success
 | 
			
		||||
      elif [ $exit_code -eq 3 ]; then
 | 
			
		||||
        result=skip
 | 
			
		||||
      else
 | 
			
		||||
        result=fail
 | 
			
		||||
      fi
 | 
			
		||||
@@ -177,6 +189,8 @@ $USAGE
 | 
			
		||||
 | 
			
		||||
-s <shell>  Invoke test scripts that either have no shebang line at all or
 | 
			
		||||
            have shebang line "#!/bin/sh" with the specified shell.
 | 
			
		||||
-b, --series   Run all tests in series in a single process. The default
 | 
			
		||||
               is to run tests from the same directory in parallel.
 | 
			
		||||
-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.
 | 
			
		||||
@@ -262,6 +276,7 @@ urchin_molly_guard() {
 | 
			
		||||
  exit 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
single_process=false
 | 
			
		||||
shell_for_sh_tests=
 | 
			
		||||
force=false
 | 
			
		||||
exit_on_fail=false
 | 
			
		||||
@@ -269,6 +284,7 @@ tap_format=false
 | 
			
		||||
while [ $# -gt 0 ]
 | 
			
		||||
do
 | 
			
		||||
    case "$1" in
 | 
			
		||||
        -b|--series) single_process=true;;
 | 
			
		||||
        -e) exit_on_fail=true;;
 | 
			
		||||
        -f) force=true;;
 | 
			
		||||
        -s)
 | 
			
		||||
@@ -277,7 +293,7 @@ do
 | 
			
		||||
          which "$shell_for_sh_tests" > /dev/null || {
 | 
			
		||||
            echo "Cannot find specified shell: '$shell_for_sh_tests'" >&2
 | 
			
		||||
            urchin_help >&2
 | 
			
		||||
            exit 11
 | 
			
		||||
            exit 3
 | 
			
		||||
          } ;;
 | 
			
		||||
        -t) tap_format=true;;
 | 
			
		||||
        -h|--help) urchin_help
 | 
			
		||||
@@ -291,17 +307,26 @@ do
 | 
			
		||||
    shift
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# Verify argument for main stuff
 | 
			
		||||
if [ "$#" != '1' ] || [ ! -d "$1" ]
 | 
			
		||||
  then
 | 
			
		||||
  [ -n "$1" ] && [ ! -d "$1" ] && echo "Not a directory: '$1'" >&2
 | 
			
		||||
  echo "$USAGE" >&2
 | 
			
		||||
  exit 3
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if $exit_on_fail && ! $single_process; then
 | 
			
		||||
  echo 'You must specify -b/--series in order to use -e.' >&2
 | 
			
		||||
  exit 3
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Constants
 | 
			
		||||
logfile=$(fullpath "$1")/.urchin.log
 | 
			
		||||
stdout_file=$(fullpath "$1")/.urchin_stdout
 | 
			
		||||
 | 
			
		||||
# Run or present the Molly guard.
 | 
			
		||||
thetest=$(readlink -f "$1")
 | 
			
		||||
if echo "$thetest" | grep -Fi 'test' > /dev/null || $force; then
 | 
			
		||||
  if test -d "$1"; then
 | 
			
		||||
    d="$thetest"
 | 
			
		||||
  else
 | 
			
		||||
    d=$(echo "$thetest" | sed 's/\/[^\/]\{1,\}$//')
 | 
			
		||||
    cd "$d"
 | 
			
		||||
  fi
 | 
			
		||||
  logfile="$d/.urchin.log"
 | 
			
		||||
  stdout_file="$d/.urchin_stdout"
 | 
			
		||||
if fullpath "$1" | grep -Fi 'test' > /dev/null || $force
 | 
			
		||||
  then
 | 
			
		||||
  urchin_go "$1" "$shell_for_sh_tests"
 | 
			
		||||
else
 | 
			
		||||
  urchin_molly_guard
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user