released version 0.5
[lunit.git] / lunit
blob6bc010abd9c60e45a1c0c46ba1afa66f44251c45
1 #! /bin/sh
3 # This file is part of lunit 0.5.
5 # For Details about lunit look at: http://www.mroth.net/lunit/
7 # Author: Michael Roth <mroth@nessie.de>
9 # Copyright (c) 2004-2009 Michael Roth <mroth@nessie.de>
11 # Permission is hereby granted, free of charge, to any person
12 # obtaining a copy of this software and associated documentation
13 # files (the "Software"), to deal in the Software without restriction,
14 # including without limitation the rights to use, copy, modify, merge,
15 # publish, distribute, sublicense, and/or sell copies of the Software,
16 # and to permit persons to whom the Software is furnished to do so,
17 # subject to the following conditions:
19 # The above copyright notice and this permission notice shall be
20 # included in all copies or substantial portions of the Software.
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 if test $# = 0 ; then
32 echo "$0: Usage Error. Try $0 --help" >&2
33 exit 1
36 if [ `uname` = "Darwin" ]; then
37 scriptname="$(readlink -n "$0")"
38 else
39 scriptname="$(readlink -n -f "$0")"
41 interpreter="lua"
42 options=""
44 while true ; do
45 case "$1" in
46 -h|--help)
47 cat <<EOT
48 lunit 0.5
49 Copyright (c) 2004-2009 Michael Roth <mroth@nessie.de>
50 This program comes WITHOUT WARRANTY OF ANY KIND.
52 Usage: lunit [OPTIONS] [--] scripts
54 Options:
56 -i, --interpreter LUA Complete path of the lua binary to use.
57 -p, --path PATH Sets the LUA_PATH environment for the tests.
58 --cpath CPATH Sets the LUA_CPATH environment for the tests.
59 -r, --runner RUNNER Testrunner to use, defaults to 'lunit-console'.
60 -t, --test PATTERN Which tests to run, may contain * or ? wildcards.
61 --loadonly Only load the tests.
62 --dontforce Do not force to load $scriptname*.lua.
63 -h, --help Print this help screen.
64 --version Print lunit version.
66 Please report bugs to <mroth@nessie.de>.
67 EOT
68 exit ;;
70 --version)
71 echo "lunit 0.5 Copyright 2004-2009 Michael Roth <mroth@nessie.de>"
72 exit ;;
74 -i|--interpreter)
75 interpreter="$2"
76 shift 2 ;;
78 -p|--path)
79 LUA_PATH="$2"
80 export LUA_PATH
81 shift 2 ;;
83 --cpath)
84 LUA_CPATH="$2"
85 export LUA_CPATH
86 shift 2 ;;
88 --loadonly)
89 options="$options $1"
90 shift 1 ;;
92 --dontforce)
93 scriptname=""
94 shift 1 ;;
96 -r|--runner|-t|--test)
97 options="$options $1 $2"
98 shift 2 ;;
101 break ;;
104 echo "$0: Invalid option: $1" >&2
105 exit 1 ;;
108 break ;;
109 esac
110 done
113 exec "$interpreter" - "$scriptname" $options "$@" <<EOT
114 local scriptname = ...
115 local argv = { select(2,...) }
116 if scriptname ~= "" then
117 local function force(name)
118 pcall( function() loadfile(name)() end )
120 force( scriptname..".lua" )
121 force( scriptname.."-console.lua" )
123 require "lunit"
124 local stats = lunit.main(argv)
125 if stats.errors > 0 or stats.failed > 0 then
126 os.exit(1)