Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Migrated the assert logic to a bake(1) task file.

  • Loading branch information...
commit ee34c1a2a9535b36f7a9613d9e6a670ab16a8c92 1 parent 27b6733
@freeformsystems authored
View
6 bin/bake
@@ -80,6 +80,12 @@ function boilerplate {
boilerplate;
######################################################################
+require 'help';
+
+# configure help
+help.man.page "default" "bake.1";
+help.parse "$@";
+
# TODO: add --version handling
function program.usage {
View
4 lib/modules/method
@@ -91,11 +91,11 @@ function method.diff.end {
declared+=( "$m" );
fi
done
- _result="${declared[@]}";
+ _result="${declared[@]:-}";
#echo "got method end diff declared: ${declared[@]}";
__method_diff_list="";
else
- _result="";
+ _result="";
fi
}
View
112 lib/modules/tasks/assert
@@ -0,0 +1,112 @@
+: <<'ronn:markdown'
+assert(1) -- unit test runner for strike(1)
+=============================================
+
+## SYNOPSIS
+
+`assert` test [<unit>...]<br>
+
+## DESCRIPTION
+
+**assert** runs strike(1) unit tests.
+
+## BUGS
+
+**assert** is written in bash and depends upon `bash` >= 4.
+
+## COPYRIGHT
+
+**assert** is copyright (c) 2012 muji <http://xpm.io>
+
+## SEE ALSO
+
+strike(1)
+ronn:markdown
+
+function tasks.assert {
+ #echo "assert_test"
+
+ if [ $# -eq 0 ]; then
+ quit 1 "no tests specified";
+ fi
+
+ local opts=( "$@" );
+ local searchpaths=(
+ "$exedir/test"
+ "$exedir/../test"
+ );
+ local unit path file;
+ for path in ${searchpaths[@]}
+ do
+ for unit in ${opts[@]}
+ do
+ file="${path}/${unit}.test";
+ if [ -f "$file" ]; then
+ __assert_run_test "$file";
+ fi
+ done
+ done
+}
+
+declare -gx __assert_expects;
+
+function assert.expects {
+ #echo "expects called with : $1";
+ __assert_expects="$1";
+}
+
+function assert.ok {
+ #echo "assert.complete called with : $1";
+ local expected="$__assert_expects";
+ local received="${1:-}";
+
+ # local frame=0
+ # while caller $frame; do
+ # ((frame++));
+ # done
+
+ local stack=( $( caller 0 ) );
+ local lineno="${stack[0]}";
+ local method="${stack[1]}";
+ local file="${stack[2]}";
+
+ # echo "got lineno : $lineno";
+ # echo "got method : $method";
+ # echo "got file : $file";
+
+ local frame="${file}:${lineno}";
+
+ if [ "$expected" == "$received" ]; then
+ console.ok "%s" "$method";
+ else
+ error "%s $frame" "$method";
+ fi
+}
+
+function __assert_run_test {
+ local file="$1";
+ require "$file" || quit 1 "could not require test file %s" "$file";
+
+ info "assert %s < %s" "`basename $file`" "$file";
+
+ # get the methods declared by the module
+ require.methods "$file";
+ local methods=( "$_result" );
+ local m;
+ for m in ${methods[@]}
+ do
+ # check that the method starts with a test prefix
+ if [[ "$m" =~ ^test. ]]; then
+
+ # clean up
+ __assert_expects="";
+
+ info "assert %s" "$m";
+
+ set +o errexit;
+ # execute the test method
+ "$m";
+ set -o errexit;
+ fi
+ done
+}
View
2  lib/modules/tasks/doc
@@ -58,6 +58,8 @@ The following commands are then available to bake(1):
bake(1), strike(1), require(7)
ronn:markdown
+require 'executable';
+
function tasks.initialize {
executable validate 'ronn' 'git';
}
View
2  lib/modules/tasks/list
@@ -1,3 +1,5 @@
+require 'executable';
+
# lists task methods
function tasks.list {
executable validate 'egrep';
View
2  tasks
@@ -1,4 +1,4 @@
-require 'executable';
+require 'tasks/assert';
require 'tasks/clean';
require 'tasks/list';
require 'tasks/doc';
Please sign in to comment.
Something went wrong with that request. Please try again.