1#! /bin/sh
2
3#   This file is part of lunit 0.5.
4#
5#   For Details about lunit look at: http://www.mroth.net/lunit/
6#
7#   Author: Michael Roth <mroth@nessie.de>
8#
9#   Copyright (c) 2004-2009 Michael Roth <mroth@nessie.de>
10#
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:
18#
19#   The above copyright notice and this permission notice shall be
20#   included in all copies or substantial portions of the Software.
21#
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.
29
30
31if test $# = 0 ; then
32  echo "$0: Usage Error. Try $0 --help" >&2
33  exit 1
34fi
35
36if [ `uname` = "Darwin" ]; then
37  scriptname="$(readlink -n "$0")"
38else
39  scriptname="$(readlink -n -f "$0")"
40fi
41interpreter="lua52"
42options=""
43
44while true ; do
45  case "$1" in
46    -h|--help)
47      cat <<EOT
48lunit 0.5
49Copyright (c) 2004-2009 Michael Roth <mroth@nessie.de>
50This program comes WITHOUT WARRANTY OF ANY KIND.
51
52Usage: lunit [OPTIONS] [--] scripts
53
54Options:
55
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.
65
66Please report bugs to <mroth@nessie.de>.
67EOT
68      exit ;;
69
70    --version)
71      echo "lunit 0.5 Copyright 2004-2009 Michael Roth <mroth@nessie.de>"
72      exit ;;
73
74    -i|--interpreter)
75      interpreter="$2"
76      shift 2 ;;
77
78    -p|--path)
79      LUA_PATH="$2"
80      export LUA_PATH
81      shift 2 ;;
82
83    --cpath)
84      LUA_CPATH="$2"
85      export LUA_CPATH
86      shift 2 ;;
87
88    --loadonly)
89      options="$options $1"
90      shift 1 ;;
91
92    --dontforce)
93      scriptname=""
94      shift 1 ;;
95
96    -r|--runner|-t|--test)
97      options="$options $1 $2"
98      shift 2 ;;
99
100    --)
101      break ;;
102
103    -*)
104      echo "$0: Invalid option: $1" >&2
105      exit 1 ;;
106
107    *)
108      break ;;
109  esac
110done
111
112
113exec "$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 )
119    end
120    force( scriptname..".lua" )
121    force( scriptname.."-console.lua" )
122  end
123  require "lunit"
124  local stats = lunit.main(argv)
125  if stats.errors > 0 or stats.failed > 0 then
126    os.exit(1)
127  end
128EOT
129