Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

WIP: Allow sourcing of helper files from BATS_LIB_PATH #216

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6cd61bf
This commit corrects the problem of incorrect TAP
Jan 21, 2016
adc7ecf
Avoid undocumented usage of the head utility.
May 2, 2016
d0f06d1
Added description & info about this repo in README
btamayo Sep 19, 2017
b72cd35
Updated repo name in README
btamayo Sep 20, 2017
e3b37da
Added Travis CI Badge to master branch README
btamayo Sep 24, 2017
8ca0685
Updating paths #5
btamayo Sep 24, 2017
c85f340
Added IRC channel info
btamayo Sep 24, 2017
3a6efc0
Minor fix in the install command
peteruhnak Sep 25, 2017
aaf62cd
Merge pull request #6 from peteruhnak/patch-1
btamayo Sep 26, 2017
d9ee416
Add .appveyor.yml
mbland Sep 30, 2017
5e752ee
.appveyor.yml: Prefix test command with `time`
mbland Sep 30, 2017
bbac787
.travis.yml: Prefix test command with `time`
mbland Sep 30, 2017
d310b25
.travis.yml: Enable macOS builds
mbland Sep 30, 2017
918714d
test/bats: Add statements to debug Travis macOS
mbland Sep 30, 2017
0f6dde5
exec-test: Work around Bash 3.2.57 ERR trap bug
mbland Feb 15, 2017
55bf719
Merge pull request #10 from bats-core/ci-configs
mbland Sep 30, 2017
a3396cb
exec-test: Refactor bats_frame_* functions
mbland Feb 14, 2017
93d3cec
exec-test: Use printf -v in bats_frame_* functions
mbland Feb 14, 2017
39440c5
exec-test: Replace `dirname` call with `%/*`
mbland Feb 15, 2017
eaa151f
exec-test: Use printf -v in bats_trim_filename
mbland Feb 15, 2017
3bc0379
exec-test: Use printf -v in bats_strip_string
mbland Feb 15, 2017
698fa76
exec-test: Replace `type -t` with `command -F`
mbland Feb 15, 2017
d294689
exec-test: Use `printf -v` in bats_extract_line
mbland Feb 15, 2017
cf9a3b8
exec-test: Invoke bats-preprocess directly
mbland Feb 15, 2017
741c414
preprocess: Use printf -v in encode_name
mbland Feb 15, 2017
e613b31
exec-test: Replace `|| { }` with `if [[ ]]; then`
mbland Feb 15, 2017
fac51df
exec-test: Replace `caller` with `FUNCNAME`, etc.
mbland Feb 15, 2017
3ab495f
preprocess: Add tests for vars, quotes in names
mbland Feb 15, 2017
6beea07
preprocess: Eliminate eval in subshell
mbland Feb 15, 2017
cdc55ad
bats: Refactor resolve_link, abs_dirname
mbland Mar 16, 2017
daf76c2
bats: Convert abs_dirname to use `printf -v`
mbland Mar 16, 2017
d4443ad
bash: Refactor expand_path
mbland Mar 16, 2017
7bcbb2f
bats: Don't pipe to cat for nonpretty output
mbland Mar 16, 2017
f5acd28
bats-exec-suite: Count tests w/ BATS_TEST_PATTERN
mbland Mar 16, 2017
8c4a86d
format-tap: Refactor summary to remove subshells
mbland Mar 16, 2017
ebb192e
Fix test failures due to unquoted variables
mbland Sep 28, 2017
8538868
Merge pull request #8 from bats-core/mbland-optimized
mbland Sep 30, 2017
f953d77
Merge branch 'master' into rojkov-fix-head-util
agent-0028 Oct 2, 2017
b3e6191
Merge pull request #17 from agent-0028/rojkov-fix-head-util
mbland Oct 2, 2017
d1f9165
Reword skipped test fixtures for clarity
agent-0028 Oct 2, 2017
adf559e
Remove unnecessary assignment and blank line
agent-0028 Oct 2, 2017
eed9913
Add double quotes around `$FIXTURE_ROOT`
agent-0028 Oct 3, 2017
6ce148b
Merge pull request #19 from agent-0028/harschware-tap_skip_test_fix
mbland Oct 3, 2017
1ed87ec
test/bats: Add fake tput to fix Alpine tests
mbland Oct 3, 2017
617e086
Allow sourcing of helper files from BATS_LIB_PATH
ntnn Mar 22, 2017
cb43429
Add test harness for various library loading methods
ntnn Mar 22, 2017
e96502c
Source all files of a library if no loading file exists
ntnn Mar 22, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 'v0.4.0.{build}'

build: off

# This presumes that Git bash is installed at `C:\Program Files\Git` and the
# bash we're using is `C:\Program Files\Git\bin\bash.exe`.
#
# If instead it finds the Windows Subsystem for Linux bash at
# `C:\Windows\System32\bash.exe`, it will fail with an error like:
# /mnt/c/.../bats-core/test/test_helper.bash: line 1:
# syntax error near unexpected token `$'{\r''
test_script:
- where bash
- bash --version
- bash -c 'time libexec/bats test'
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
language: c
script: bin/bats --tap test
language: bash
os:
- linux
- osx

script:
- bash -c 'time bin/bats --tap test'

notifications:
email:
on_success: never
5 changes: 5 additions & 0 deletions CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ members of the project's leadership.

## Project Maintainers

### bats-core organization:
* Bianca Tamayo <<[email protected]>>


## Project Original Author(s)
* Sam Stephenson <<[email protected]>>

## Attribution
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
Copyright (c) 2017 Bianca Tamayo and bats-core organization

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:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

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.

Copyright (c) 2014 Sam Stephenson

Permission is hereby granted, free of charge, to any person obtaining
Expand Down
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
## BATS-core: Bash Automated Testing System (2017)

[![Build Status](https://travis-ci.org/bats-core/bats-core.svg?branch=master)](https://travis-ci.org/bats-core/bats-core)

### Background:
### What is this repo?
**Tuesday, September 19, 2017:** This is a mirrored fork of [bats](https://github.com/sstephenson/bats), at [0360811](https://github.com/sstephenson/bats/commit/03608115df2071fff4eaaff1605768c275e5f81f). It was created via `git clone --bare` and `git push --mirror`.

#### Why was it created?
The original bats repository needed new maintainers, and has not been actively maintained since 2013. While there were volunteers for maintainers, attempts to organize issues, and outstanding PRs, the lack of write-access to the repo hindered progress severely.

## What's the plan and why?
The rough plan, originally [outlined here](https://github.com/sstephenson/bats/issues/150#issuecomment-323845404) is to create a new, mirrored mainline (this repo!). An excerpt:

> **1. Roadmap 1.0:**
> There are already existing high-quality PRs, and often-requested features and issues, especially here at [#196](https://github.com/sstephenson/bats/issues/196). Leverage these and **consolidate into a single roadmap**.
>
>**2. Create or choose a fork or *mirror* of this repo to use as the new mainline:**
>Repoint existing PRs (whichever ones are possible) to the new mainline, get that repo to a stable 1.0. IMO we should create an organization and grant 2-3 people admin and write access.
>

Doing it this way accomplishes two things:
1. Removes the dependency on the original maintainer
2. Enables collaboration and contribution flow again
3. Allows the possibility of merging back to original, or merging from original if or when the need arises
4. Prevents lock-out by giving administrative access to more than one person, increases transferability

## Misc
- We are `#bats` on freenode

---
# Bats: Bash Automated Testing System

Bats is a [TAP](http://testanything.org)-compliant testing framework
Expand Down Expand Up @@ -77,7 +108,7 @@ then iterates over the test cases and executes each one in its own
process.

For more details about how Bats evaluates test files, see
[Bats Evaluation Process](https://github.com/sstephenson/bats/wiki/Bats-Evaluation-Process)
[Bats Evaluation Process](https://github.com/bats-core/bats-core/wiki/Bats-Evaluation-Process)
on the wiki.

### `run`: Test other commands
Expand Down Expand Up @@ -210,8 +241,8 @@ Check out a copy of the Bats repository. Then, either add the Bats
command with the location to the prefix in which you want to install
Bats. For example, to install Bats into `/usr/local`,

$ git clone https://github.com/sstephenson/bats.git
$ cd bats
$ git clone https://github.com/bats-core/bats-core.git
$ cd bats-core
$ ./install.sh /usr/local

Note that you may need to run `install.sh` with `sudo` if you do not
Expand All @@ -221,15 +252,15 @@ have permission to write to the installation prefix.
## Support

The Bats source code repository is [hosted on
GitHub](https://github.com/sstephenson/bats). There you can file bugs
GitHub](https://github.com/bats-core/bats-core). There you can file bugs
on the issue tracker or submit tested pull requests for review.

For real-world examples from open-source projects using Bats, see
[Projects Using Bats](https://github.com/sstephenson/bats/wiki/Projects-Using-Bats)
[Projects Using Bats](https://github.com/bats-core/bats-core/wiki/Projects-Using-Bats)
on the wiki.

To learn how to set up your editor for Bats syntax highlighting, see
[Syntax Highlighting](https://github.com/sstephenson/bats/wiki/Syntax-Highlighting)
[Syntax Highlighting](https://github.com/bats-core/bats-core/wiki/Syntax-Highlighting)
on the wiki.


Expand Down Expand Up @@ -289,5 +320,9 @@ on the wiki.

---

© 2014 Sam Stephenson. Bats is released under an MIT-style license;
© 2017 Bianca Tamayo (bats-core organization)

© 2014 Sam Stephenson

Bats is released under an MIT-style license;
see `LICENSE` for details.
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
$(type -p greadlink readlink | head -n1) "$1"
}

abs_dirname() {
Expand Down
65 changes: 44 additions & 21 deletions libexec/bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,62 @@ help() {
echo " -t, --tap Show results in TAP format"
echo " -v, --version Display the version number"
echo
echo " For more information, see https://github.com/sstephenson/bats"
echo " For more information, see https://github.com/bats-core/bats-core"
echo
}

BATS_READLINK=

resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
if [[ -z "$BATS_READLINK" ]]; then
if command -v 'greadlink' >/dev/null; then
BATS_READLINK='greadlink'
elif command -v 'readlink' >/dev/null; then
BATS_READLINK='readlink'
else
BATS_READLINK='true'
fi
fi
"$BATS_READLINK" "$1" || return 0
}

abs_dirname() {
local cwd="$(pwd)"
local cwd="$PWD"
local path="$1"

while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
path="$(resolve_link "$name")"
done

pwd
printf -v "$2" -- '%s' "$PWD"
cd "$cwd"
}

expand_path() {
{ cd "$(dirname "$1")" 2>/dev/null
local dirname="$PWD"
local path="${1%/}"
local dirname="${path%/*}"

if [[ "$dirname" == "$path" ]]; then
dirname="$PWD"
elif cd "$dirname" 2>/dev/null; then
dirname="$PWD"
cd "$OLDPWD"
echo "$dirname/$(basename "$1")"
} || echo "$1"
else
printf '%s' "$path"
return
fi
printf -v "$2" '%s/%s' "$dirname" "${path##*/}"
}

BATS_LIBEXEC="$(abs_dirname "$0")"
export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")"
export BATS_CWD="$(abs_dirname .)"
abs_dirname "$0" 'BATS_LIBEXEC'
abs_dirname "$BATS_LIBEXEC" 'BATS_PREFIX'
abs_dirname '.' 'BATS_CWD'

export BATS_PREFIX
export BATS_CWD
export BATS_TEST_PATTERN='^ *@test +(.+) +\{ *(.*)$'
export PATH="$BATS_LIBEXEC:$PATH"

options=()
Expand Down Expand Up @@ -113,14 +136,16 @@ fi

filenames=()
for filename in "${arguments[@]}"; do
expand_path "$filename" 'filename'

if [ -d "$filename" ]; then
shopt -s nullglob
for suite_filename in "$(expand_path "$filename")"/*.bats; do
for suite_filename in "$filename"/*.bats; do
filenames["${#filenames[@]}"]="$suite_filename"
done
shopt -u nullglob
else
filenames["${#filenames[@]}"]="$(expand_path "$filename")"
filenames["${#filenames[@]}"]="$filename"
fi
done

Expand All @@ -130,13 +155,11 @@ else
command="bats-exec-suite"
fi

if [ -n "$pretty" ]; then
set -o pipefail execfail
if [ -z "$pretty" ]; then
exec "$command" $count_flag "${filenames[@]}"
else
extended_syntax_flag="-x"
formatter="bats-format-tap-stream"
else
extended_syntax_flag=""
formatter="cat"
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter"
fi

set -o pipefail execfail
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter"
6 changes: 5 additions & 1 deletion libexec/bats-exec-suite
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ trap "kill 0; exit 1" int

count=0
for filename in "$@"; do
let count+="$(bats-exec-test -c "$filename")"
while IFS= read -r line; do
if [[ "$line" =~ $BATS_TEST_PATTERN ]]; then
let count+=1
fi
done <"$filename"
done

if [ -n "$count_only_flag" ]; then
Expand Down
Loading