Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
15099082db | ||
|
8d53676743 | ||
|
8913cbc195 | ||
|
17b4629ba5 | ||
|
85bfafffc8 | ||
|
153b04b462 | ||
|
1cf65a723d | ||
|
c2f4d92704 | ||
|
31da4fae92 | ||
|
e892c565cb | ||
|
5aace72fc6 | ||
|
a749c8dae3 | ||
|
da9a0c9948 | ||
|
91a4467f3e | ||
|
0110a72965 | ||
|
d9902c0b11 | ||
|
a900722fb7 | ||
|
4d3a9eddb5 | ||
|
3062e58a75 | ||
|
222ba59d69 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.urchin_stdout
|
15
cross-shell-tests
Executable file
15
cross-shell-tests
Executable 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
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "urchin",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"description": "Test framework for shell",
|
||||
"main": "urchin",
|
||||
"directories": {
|
||||
|
34
readme.md
34
readme.md
@@ -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.
|
||||
|
2
tests/- directories starting with a hypen.../Should work
Executable file
2
tests/- directories starting with a hypen.../Should work
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
exit 0
|
1
tests/Counts should be kept of successes and failures./.test-one/fail
Executable file
1
tests/Counts should be kept of successes and failures./.test-one/fail
Executable file
@@ -0,0 +1 @@
|
||||
false
|
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
../../urchin .test-one | grep '1 test failed'
|
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
../../urchin .test-one | grep '1 test passed'
|
@@ -1,3 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
grep blah fixtures/bladyblah > /dev/null
|
||||
grep blah .fixtures/bladyblah > /dev/null
|
||||
|
@@ -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
38
urchin
@@ -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
|
||||
|
Reference in New Issue
Block a user