Add tests (#3)

This commit is contained in:
Denis Isidoro 2019-09-20 18:44:51 -03:00 committed by GitHub
parent 2fdb55f261
commit 2bc52976c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 95 additions and 12 deletions

26
.circleci/config.yml Normal file
View File

@ -0,0 +1,26 @@
# Clojure CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-clojure/ for more details
#
version: 2
job_defaults: &defaults
docker:
- image: frolvlad/alpine-bash
working_directory: ~/repo
environment:
ENVIRONMENT: "test"
TERM: "dumb"
jobs:
tests:
<<: *defaults
steps:
- checkout
- run: ./test/find_cheats
workflows:
version: 2
run-tests:
jobs:
- tests

View File

@ -1,8 +1,8 @@
BIN ?= navi
PREFIX ?= /usr/local
install:
scripts/symlink
scripts/install
uninstall:
rm -f $(PREFIX)/bin/$(BIN)
scripts/uninstall
release:
scripts/release

View File

@ -1,4 +1,4 @@
# navi
# navi [![CircleCI](https://circleci.com/gh/denisidoro/navi.svg?style=svg)](https://circleci.com/gh/denisidoro/navi)
An interactive cheatsheet tool for the command-line so that you'll never say the following again:
@ -53,7 +53,12 @@ Or you can launch and browser and search for instructions on Google, but that ta
In this case, you need to pass the directory which contains `.cheat` files as in:
```sh
navi --dir /folder/with/cheats
navi --dir "/folder/with/cheats"
```
Alternatively, you can set an environment variable in your `.bashrc`-like file:
```sh
export NAVI_DIR="/folder/with/cheats"
```
## .cheat syntax

2
navi
View File

@ -22,6 +22,6 @@ source "${SCRIPT_DIR}/src/main.sh"
##? --print Prevent script execution [default: false]
##? --no-interpolation Prevent argument interpolation [default: false]
VERSION="0.5.0"
VERSION="0.6.0"
docs::eval "$@"
main "$@"

26
scripts/release Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$SCRIPT_DIR"
tag="v$*"
tar="https://github.com/denisidoro/navi/archive/v${tag}.tar.gz"
formula="/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/navi.rb"
echo "Attempting to release version ${tag}..."
echo "git tag"
git tag -a "$tag" -m "$tag"
echo "git push"
git push --follow-tags
echo "rm formula"
rm "$formula" || true
echo "brew create"
brew create "$tar"
echo "output"
grep "url" "$formula" -A1

5
scripts/uninstall Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
BIN="/usr/local/bin/navi"
rm -rf "$BIN" || true

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
cheat::find() {
find "${cheat_dir:-"${SCRIPT_DIR}/cheats"}" -iname '*.cheat'
find "${NAVI_DIR:-"${SCRIPT_DIR}/cheats"}" -iname '*.cheat'
}
cheat::read_many() {

View File

@ -14,7 +14,7 @@ docs::eval() {
for arg in $@; do
case $wait_for in
dir) cheat_dir="$arg"; wait_for="";;
dir) NAVI_DIR="$arg"; wait_for="";;
esac
case $arg in
@ -25,6 +25,4 @@ docs::eval() {
-d|--dir) wait_for="dir";;
esac
done
echo "cheat_dir: ${cheat_dir:-}"
}

13
test/core.sh Normal file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
source <(
grep -v 'main ' "${SCRIPT_DIR}/navi" | sed -E "s|export.*|export SCRIPT_DIR=\"${SCRIPT_DIR}\"|")
test::success() {
echo "Test passed!"
}
test::fail() {
echo "Test failed..."
exit 42
}

10
test/find_cheats Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
source "${SCRIPT_DIR}/test/core.sh"
cheat::find \
| grep -q "docker.cheat" \
&& test::success \
|| test::fail