Skip to content

Commit d06eaa4

Browse files
committed
initial commit
0 parents  commit d06eaa4

File tree

14 files changed

+518
-0
lines changed

14 files changed

+518
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (C) 2015 Jeff Lindsay
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
NAME=basht
2+
VERSION=0.1.0
3+
4+
build:
5+
go-bindata include
6+
mkdir -p build/Linux && GOOS=linux go build -ldflags "-X main.Version $(VERSION)" -o build/Linux/$(NAME)
7+
mkdir -p build/Darwin && GOOS=darwin go build -ldflags "-X main.Version $(VERSION)" -o build/Darwin/$(NAME)
8+
9+
deps:
10+
go get -u github.com/jteeuwen/go-bindata/...
11+
go get -u github.com/progrium/gh-release/...
12+
go get || true
13+
14+
test: build
15+
build/$(shell uname -s)/basht tests/meta.bash
16+
17+
.PHONY: build

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# basht
2+
3+
Basht is a minimalist Bash testing utility. You can write tests in pure Bash, just pass it one or more files that define tests. Tests are functions that start with `T_`:
4+
5+
```
6+
T_additionUsingBC() {
7+
result="$(echo 2+2 | bc)"
8+
[[ "$result" -eq 4 ]]
9+
}
10+
11+
T_additionUsingDC() {
12+
result="$(echo 2 2+p | dc)"
13+
[[ "$result" -eq 4 ]]
14+
}
15+
```
16+
17+
Tests that return non-zero fail. Only the return value will fail a test, as `set -e` is not used. You can fail a test at any time by explicitly calling `return` with non-zero.
18+
19+
## Getting basht
20+
21+
Download and uncompress the latest binary tarball from [releases](https://github.com/progrium/basht/releases).
22+
23+
Alternatively, if you happen to also be using Go, you can install with `go get`:
24+
25+
$ go get github.com/progrium/basht
26+
27+
## Running tests
28+
29+
Any filenames passed to basht are loaded and any tests found will be run. Take advantage of globbing for multiple files or directories of tests.
30+
31+
```
32+
$ basht tests/example.bash
33+
=== RUN T_additionUsingBC
34+
--- PASS T_additionUsingBC (0s)
35+
=== RUN T_additionUsingDC
36+
--- PASS T_additionUsingDC (0s)
37+
38+
Ran 2 tests.
39+
40+
PASS
41+
```
42+
43+
If tests pass, basht will exit zero. If any tests failed, basht exists non-zero with the number of failed tests.
44+
45+
```
46+
$ basht tests/fails.bash
47+
=== RUN T_failEquals
48+
--- FAIL T_failEquals (0s)
49+
=== RUN T_failMessage
50+
--- FAIL T_failMessage (0s)
51+
tests/fails.bash:19: This is a fail message.
52+
53+
=== RUN T_failReturn
54+
--- FAIL T_failReturn (0s)
55+
=== RUN T_failSuccess
56+
--- FAIL T_failSuccess (0s)
57+
58+
Ran 4 tests. 4 failed.
59+
60+
FAIL
61+
```
62+
63+
## Macros
64+
65+
Basht provides no special assertions or helpers. However, there is one macro basht provides:
66+
67+
### $T_fail
68+
69+
Calling `$T_fail <message>` marks a test as failed and includes a failure message. There is an example above of how this is shown in the output. It includes the filename and line number with the message.
70+
71+
Keep in mind it does not return, so if used before the end of a test, you must return after.
72+
73+
```
74+
T_failMessage() {
75+
false || $T_fail "This is a fail message."
76+
}
77+
78+
T_failMultiple() {
79+
if ! something; then
80+
$T_fail "Something failed."
81+
return
82+
fi
83+
if ! another; then
84+
$T_fail "Another failed."
85+
return
86+
fi
87+
}
88+
```
89+
90+
## License
91+
92+
BSD

basht.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/progrium/go-basher"
8+
)
9+
10+
var Version string
11+
12+
func main() {
13+
if len(os.Args) == 2 && os.Args[1] == "--version" {
14+
fmt.Println(Version)
15+
os.Exit(0)
16+
}
17+
os.Setenv("VERSION", Version)
18+
basher.Application(nil, []string{
19+
"include/basht.bash",
20+
}, Asset, true)
21+
}

bindata.go

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"compress/gzip"
6+
"fmt"
7+
"io"
8+
"strings"
9+
"os"
10+
"time"
11+
"io/ioutil"
12+
"path"
13+
"path/filepath"
14+
)
15+
16+
func bindata_read(data []byte, name string) ([]byte, error) {
17+
gz, err := gzip.NewReader(bytes.NewBuffer(data))
18+
if err != nil {
19+
return nil, fmt.Errorf("Read %q: %v", name, err)
20+
}
21+
22+
var buf bytes.Buffer
23+
_, err = io.Copy(&buf, gz)
24+
gz.Close()
25+
26+
if err != nil {
27+
return nil, fmt.Errorf("Read %q: %v", name, err)
28+
}
29+
30+
return buf.Bytes(), nil
31+
}
32+
33+
type asset struct {
34+
bytes []byte
35+
info os.FileInfo
36+
}
37+
38+
type bindata_file_info struct {
39+
name string
40+
size int64
41+
mode os.FileMode
42+
modTime time.Time
43+
}
44+
45+
func (fi bindata_file_info) Name() string {
46+
return fi.name
47+
}
48+
func (fi bindata_file_info) Size() int64 {
49+
return fi.size
50+
}
51+
func (fi bindata_file_info) Mode() os.FileMode {
52+
return fi.mode
53+
}
54+
func (fi bindata_file_info) ModTime() time.Time {
55+
return fi.modTime
56+
}
57+
func (fi bindata_file_info) IsDir() bool {
58+
return false
59+
}
60+
func (fi bindata_file_info) Sys() interface{} {
61+
return nil
62+
}
63+
64+
var _include_basht_bash = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x74\x53\xd1\x6f\x9b\x3e\x10\x7e\xc6\x7f\xc5\xfd\x90\x55\x88\x2a\x7e\x4a\xb6\xb7\x54\x68\xe9\xba\x54\xab\xd4\x25\x53\x68\x9f\xa2\x08\x21\x62\x1a\x34\x0a\x91\x6d\xb6\x49\x19\xff\xfb\xee\x6c\x87\x42\xb6\xe5\x01\xc7\xe7\xef\xbe\xef\xee\x3b\x9b\xa5\x69\xde\xd4\x3a\x2b\x6b\x15\x4e\xe0\xc4\xbc\xaa\xc9\xb3\x0a\xc4\x0d\x14\x8d\x04\x01\x65\x0d\x3e\x3f\x2d\xe6\xef\x3a\xff\x06\xf6\x0d\x6c\xb7\xb8\x17\x3e\xc4\x31\xae\x33\x1f\x76\x3b\xb8\xba\x02\x29\x74\x2b\x6b\x98\x12\xa4\xc6\x5c\xb7\x9f\xb1\x8e\xa1\x40\x91\x95\xd5\x97\x2c\x97\xcd\x50\xa1\x2a\x6b\x11\x13\xc5\x0d\xa8\x43\x59\x68\xe6\xa5\xa9\x16\x4a\xa7\x4a\x67\xba\x55\xf1\xac\x0f\xbc\x0a\xa5\xb2\x17\x02\x53\xce\x1c\xf8\xc2\x47\xde\x27\x43\x1b\x07\xe2\x3b\x92\x0d\x34\x80\x7f\xbc\x4d\x3e\xa7\xc9\xfa\x79\x73\xb7\x9c\xf3\xc7\x87\xd5\x72\xb5\x0e\x18\x7b\xc5\x16\x87\xfa\xb2\xad\x81\x92\xc4\x1e\x50\x51\x6a\xfc\x36\x47\xd8\xb7\x32\xd3\x65\x53\x33\x6f\x2f\xf2\x2a\x93\x02\xa2\x0c\x8e\xb2\xc9\xb1\x06\xb1\x67\x1e\x66\xc5\x53\xe6\xd9\x44\xf3\x0f\x5d\x2a\x70\x43\x46\xf1\x05\xf5\xcf\x3c\x4f\x35\xad\xcc\x05\x1a\x44\x27\x3e\x06\x08\xa5\x0d\x24\xec\x79\xef\xe1\x17\xbc\x48\x71\x84\xa0\x0f\x15\xf0\x94\x06\x18\xce\x7e\x7c\x83\xe0\x74\x94\x65\xad\x81\xbf\xef\x82\x89\xe3\xf5\xca\x02\xfe\x83\xb7\x89\xa1\x82\xf6\x69\x3e\x7d\x85\xdb\xc5\x8e\x06\xa5\x0f\xa2\x26\xbc\xd7\xd6\x4a\x68\x18\x39\x0b\x63\x5b\x0d\x4c\xe4\x87\x06\xfc\x18\x87\xba\x79\x5e\x01\x92\x9a\xa8\xf1\x05\x6d\x4f\x96\x77\xeb\xd5\xa7\xc4\x06\xb9\x36\xcb\x78\x58\xfc\x34\xda\xcf\x23\xfe\xa1\x73\x14\xcd\xf1\x92\xe1\xec\x71\xcc\xc3\x90\x13\x20\xe2\x46\x69\x32\x31\xc7\x7d\x2f\xd7\x71\x48\xfd\xd9\x28\x19\x4f\x78\x5c\xaf\x67\x0e\x89\x6e\x98\xeb\x38\xd2\x36\x57\x73\x8a\xf7\x72\xe0\x82\xeb\x2f\x8a\x22\xf8\x7a\x9b\x24\xd8\x20\x84\xfc\x74\xae\xa3\x53\x13\x5b\x98\xa8\x94\xb5\xe3\x3c\x5f\x12\xb4\x7f\x7b\xcd\x01\xd5\xfd\xed\xc3\xe3\xbf\xa8\x2e\x6b\x73\x66\xfb\x17\x75\x39\x36\xc0\xdf\x25\x72\x00\x70\x35\x95\xec\x6d\x31\x5f\x7a\x6b\xcc\x7d\x2d\xee\xac\x6a\x8b\xb6\xaf\x74\x3a\x12\xb5\x82\x9b\x0c\xaf\x22\xbd\x00\x92\x54\xff\xfb\xac\x17\xb2\xe7\xe4\x12\x06\x9d\x21\x7f\xcd\x01\x27\xe2\x1e\xd1\x9f\x1c\x64\x8f\x09\xfe\x2c\xf5\x19\xcc\xa8\xf0\x8e\xfd\x0e\x00\x00\xff\xff\xb6\xec\xc7\x36\x75\x04\x00\x00")
65+
66+
func include_basht_bash_bytes() ([]byte, error) {
67+
return bindata_read(
68+
_include_basht_bash,
69+
"include/basht.bash",
70+
)
71+
}
72+
73+
func include_basht_bash() (*asset, error) {
74+
bytes, err := include_basht_bash_bytes()
75+
if err != nil {
76+
return nil, err
77+
}
78+
79+
info := bindata_file_info{name: "include/basht.bash", size: 1141, mode: os.FileMode(420), modTime: time.Unix(1426344369, 0)}
80+
a := &asset{bytes: bytes, info: info}
81+
return a, nil
82+
}
83+
84+
// Asset loads and returns the asset for the given name.
85+
// It returns an error if the asset could not be found or
86+
// could not be loaded.
87+
func Asset(name string) ([]byte, error) {
88+
cannonicalName := strings.Replace(name, "\\", "/", -1)
89+
if f, ok := _bindata[cannonicalName]; ok {
90+
a, err := f()
91+
if err != nil {
92+
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
93+
}
94+
return a.bytes, nil
95+
}
96+
return nil, fmt.Errorf("Asset %s not found", name)
97+
}
98+
99+
// MustAsset is like Asset but panics when Asset would return an error.
100+
// It simplifies safe initialization of global variables.
101+
func MustAsset(name string) []byte {
102+
a, err := Asset(name)
103+
if (err != nil) {
104+
panic("asset: Asset(" + name + "): " + err.Error())
105+
}
106+
107+
return a
108+
}
109+
110+
// AssetInfo loads and returns the asset info for the given name.
111+
// It returns an error if the asset could not be found or
112+
// could not be loaded.
113+
func AssetInfo(name string) (os.FileInfo, error) {
114+
cannonicalName := strings.Replace(name, "\\", "/", -1)
115+
if f, ok := _bindata[cannonicalName]; ok {
116+
a, err := f()
117+
if err != nil {
118+
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
119+
}
120+
return a.info, nil
121+
}
122+
return nil, fmt.Errorf("AssetInfo %s not found", name)
123+
}
124+
125+
// AssetNames returns the names of the assets.
126+
func AssetNames() []string {
127+
names := make([]string, 0, len(_bindata))
128+
for name := range _bindata {
129+
names = append(names, name)
130+
}
131+
return names
132+
}
133+
134+
// _bindata is a table, holding each asset generator, mapped to its name.
135+
var _bindata = map[string]func() (*asset, error){
136+
"include/basht.bash": include_basht_bash,
137+
}
138+
139+
// AssetDir returns the file names below a certain
140+
// directory embedded in the file by go-bindata.
141+
// For example if you run go-bindata on data/... and data contains the
142+
// following hierarchy:
143+
// data/
144+
// foo.txt
145+
// img/
146+
// a.png
147+
// b.png
148+
// then AssetDir("data") would return []string{"foo.txt", "img"}
149+
// AssetDir("data/img") would return []string{"a.png", "b.png"}
150+
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
151+
// AssetDir("") will return []string{"data"}.
152+
func AssetDir(name string) ([]string, error) {
153+
node := _bintree
154+
if len(name) != 0 {
155+
cannonicalName := strings.Replace(name, "\\", "/", -1)
156+
pathList := strings.Split(cannonicalName, "/")
157+
for _, p := range pathList {
158+
node = node.Children[p]
159+
if node == nil {
160+
return nil, fmt.Errorf("Asset %s not found", name)
161+
}
162+
}
163+
}
164+
if node.Func != nil {
165+
return nil, fmt.Errorf("Asset %s not found", name)
166+
}
167+
rv := make([]string, 0, len(node.Children))
168+
for name := range node.Children {
169+
rv = append(rv, name)
170+
}
171+
return rv, nil
172+
}
173+
174+
type _bintree_t struct {
175+
Func func() (*asset, error)
176+
Children map[string]*_bintree_t
177+
}
178+
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
179+
"include": &_bintree_t{nil, map[string]*_bintree_t{
180+
"basht.bash": &_bintree_t{include_basht_bash, map[string]*_bintree_t{
181+
}},
182+
}},
183+
}}
184+
185+
// Restore an asset under the given directory
186+
func RestoreAsset(dir, name string) error {
187+
data, err := Asset(name)
188+
if err != nil {
189+
return err
190+
}
191+
info, err := AssetInfo(name)
192+
if err != nil {
193+
return err
194+
}
195+
err = os.MkdirAll(_filePath(dir, path.Dir(name)), os.FileMode(0755))
196+
if err != nil {
197+
return err
198+
}
199+
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
200+
if err != nil {
201+
return err
202+
}
203+
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
204+
if err != nil {
205+
return err
206+
}
207+
return nil
208+
}
209+
210+
// Restore assets under the given directory recursively
211+
func RestoreAssets(dir, name string) error {
212+
children, err := AssetDir(name)
213+
if err != nil { // File
214+
return RestoreAsset(dir, name)
215+
} else { // Dir
216+
for _, child := range children {
217+
err = RestoreAssets(dir, path.Join(name, child))
218+
if err != nil {
219+
return err
220+
}
221+
}
222+
}
223+
return nil
224+
}
225+
226+
func _filePath(dir, name string) string {
227+
cannonicalName := strings.Replace(name, "\\", "/", -1)
228+
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
229+
}
230+

circle.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
dependencies:
2+
pre:
3+
- make deps
4+
override:
5+
- make build
6+
post:
7+
- tar -czf $CIRCLE_ARTIFACTS/basht-linux.tgz -C build/Linux basht
8+
- tar -czf $CIRCLE_ARTIFACTS/basht-darwin.tgz -C build/Darwin basht
9+
10+
test:
11+
override:
12+
- make test
13+
14+
deployment:
15+
release:
16+
branch: release
17+
commands:
18+
- make release

0 commit comments

Comments
 (0)