20 Commits

Author SHA1 Message Date
David Jones
15099082db 0.0.2 2013-07-26 12:53:25 +01:00
David Jones
8d53676743 Ensure we can cd into directories starting with a hyphen. Fixes #3. 2013-07-26 12:51:01 +01:00
David Jones
8913cbc195 Removing space at the end of a line. 2013-07-02 09:46:21 +01:00
David Jones
17b4629ba5 when testing, just cd into urchin 2013-07-02 09:43:59 +01:00
David Jones
85bfafffc8 /bin/sh not login shell 2013-07-02 09:43:16 +01:00
David Jones
153b04b462 Merge branch 'master' of github.com:scraperwiki/urchin 2013-07-02 09:25:49 +01:00
David Jones
1cf65a723d Merge pull request #2 from tlevine/cross-shell-test-runner
Cross shell test runner
2013-07-01 08:17:52 -07:00
David Jones
c2f4d92704 Hide fixtures directory. 2013-06-28 10:58:25 +01:00
David Jones
31da4fae92 Print date and duration. 2013-06-28 10:48:43 +01:00
David Jones
e892c565cb Removed spurious output from grep. 2013-06-28 10:47:51 +01:00
Thomas Levine
5aace72fc6 remove conflicting ksh calls 2013-06-27 11:45:45 -07:00
Thomas Levine
a749c8dae3 fix urchin call in XSD test 2013-06-27 11:45:05 -07:00
Thomas Levine
da9a0c9948 documentation 2013-06-27 11:44:19 -07:00
Thomas Levine
91a4467f3e cross-shell test runner in runtests 2013-06-27 11:33:16 -07:00
David Jones
0110a72965 remove pointless use of echo 2013-06-27 18:27:40 +01:00
David Jones
d9902c0b11 ASCII art from figlet 2013-06-26 08:22:54 +01:00
David Jones
a900722fb7 Fix bug when test is called "-n" 2013-06-26 08:15:07 +01:00
David Jones
4d3a9eddb5 npm instructions. 2013-06-21 17:14:44 +01:00
David Jones
3062e58a75 Use singular / plural form correctly. 2013-06-20 18:56:29 +01:00
David Jones
222ba59d69 Test for singular. 2013-06-20 18:43:11 +01:00
13 changed files with 77 additions and 24 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.urchin_stdout

15
cross-shell-tests Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
# 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
if which $shell > /dev/null 2> /dev/null; then
echo
echo Running urchin tests in $shell
$shell urchin tests | tail -n 2
else
echo
echo Skipping $shell because it is not in the PATH
fi
done
echo

View File

@@ -1,6 +1,6 @@
{
"name": "urchin",
"version": "0.0.1",
"version": "0.0.2",
"description": "Test framework for shell",
"main": "urchin",
"directories": {

View File

@@ -1,7 +1,8 @@
, , ,_ _, , , ___, , ,
| | |_) / |_|, ' | |\ |
'\__| '| \ '\_ '| | _|_, |'\|
` ' ` ` ' ` ' ' `
__ _
__ ____________/ /_ (_)___
/ / / / ___/ ___/ __ \/ / __ \
/ /_/ / / / /__/ / / / / / / /
\__,_/_/ \___/_/ /_/_/_/ /_/
Urchin is a test framework for shell. It is implemented in
portable /bin/sh and should work on GNU/Linux, Mac OS X, and
@@ -15,14 +16,27 @@ is like. Clone the repository
Run the tests
cd urchin/tests
../urchin .
cd urchin
./urchin tests
The above command will run the tests in your systems default
shell, /bin/sh (on recent Ubuntu this is dash, but it could be
ksh or bash on other systems); to test cross-shell compatibility,
run this:
cd urchin
./cross-shell-tests
## Globally
Download Urchin like so (as root)
Download Urchin like so (as root) (or use npm, below):
wget -O /usr/local/bin https://raw.github.com/scraperwiki/urchin/master/urchin
chmod +x /usr/local/bin/urchin
cd /usr/local/bin
wget https://raw.github.com/scraperwiki/urchin/master/urchin
chmod +x urchin
Can be installed with npm too:
npm install -g urchin
Now you can run it.
@@ -61,7 +75,7 @@ and directories have special meanings.
Directories are processed in a depth-first order. When a particular directory
is processed, `setup_dir` is run before everything else in the directory, including
subdirectories. `teardown_dir` is run after everything else in the directory.
subdirectories. `teardown_dir` is run after everything else in the directory.
A directory's `setup` file, if it exists, is run right before each test file
within the particular directory, and the `teardown` file is run right after.

View File

@@ -0,0 +1,2 @@
#!/bin/sh
exit 0

View File

@@ -0,0 +1 @@
false

View File

@@ -0,0 +1,2 @@
#!/bin/sh
../../urchin .test-one | grep '1 test failed'

View File

@@ -0,0 +1,2 @@
#!/bin/sh
../../urchin .test-one | grep '1 test passed'

View File

@@ -1,3 +1,3 @@
#!/bin/sh
grep blah fixtures/bladyblah > /dev/null
grep blah .fixtures/bladyblah > /dev/null

View File

@@ -1,3 +1,3 @@
#!/bin/sh
../../../urchin .fixture | grep 'http://www.w3.org/2001/XMLSchema'
../../urchin .fixture | grep 'http://www.w3.org/2001/XMLSchema'

38
urchin
View File

@@ -2,7 +2,7 @@
fullpath() {
(
cd "$1"
cd -- "$1"
pwd
)
}
@@ -28,7 +28,7 @@ recurse() {
(
indent $indent_level
echo " ${potential_test}"
cd "$potential_test"
cd -- "$potential_test"
[ -f setup_dir ] && [ -x setup_dir ] && ./setup_dir >> "$stdout_file"
for test in *
do
@@ -58,13 +58,13 @@ recurse() {
then
# On success, print a '✓'
printf '\033[32m✓ \033[0m'
echo "${potential_test}"
echo "${potential_test} passed" >> "$logfile"
printf '%s\n' "${potential_test}"
printf '%s\n' "${potential_test} passed" >> "$logfile"
else
# On fail, print a red '✗'
printf '\033[31m✗ \033[0m'
echo "${potential_test}"
echo "${potential_test} failed" >> "$logfile"
printf '%s\n' "${potential_test}"
printf '%s\n' "${potential_test} failed" >> "$logfile"
cat "$stdout_file"
fi
rm "$stdout_file"
@@ -86,15 +86,31 @@ urchin_help() {
echo
}
plural () {
# Make $1 a plural according to the number $2.
# If $3 is supplied, use that instead of "${1}s".
# Result is written to stdout.
if [ "$2" = 1 ]
then
printf '%s\n' "$1"
else
printf '%s\n' "${3-${1}s}"
fi
}
urchin_go() {
echo Running tests
echo Running tests at $(date +%Y-%m-%dT%H:%M:%S)
start=$(date +%s)
echo > "$logfile"
recurse "$1" 0
echo Done
echo $(grep -e 'passed$' "$logfile"|wc -l) tests passed.
echo $(grep -e 'failed$' "$logfile"|wc -l) tests failed.
finish=$(date +%s)
elapsed=$(($finish - $start))
echo Done, took $elapsed $(plural second $elapsed)
set -- $(grep -e 'passed$' "$logfile"|wc -l) $(grep -e 'failed$' "$logfile"|wc -l)
printf '%s\n' "$1 $(plural test "$1") passed."
printf '%s\n' "$2 $(plural test "$2") failed."
}
urchin_molly_guard() {
@@ -135,7 +151,7 @@ if [ "$#" != '1' ] && [ ! -d "$1" ]
fi
# Run or present the Molly guard.
if echo "$(basename "$(fullpath "$1")")" | grep test || $FORCE
if basename "$(fullpath "$1")" | grep test > /dev/null || $FORCE
then
urchin_go "$1"
else