Skip to content

Commit

Permalink
fix tests for zsh
Browse files Browse the repository at this point in the history
  • Loading branch information
kindermax committed Jul 11, 2022
1 parent b4e0cd6 commit f61311c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
with:
version: latest
- name: Test bats
run: lets test-bats
run: timeout 120 lets test-bats

lint:
runs-on: ubuntu-latest
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ services:
environment:
NO_COLOR: 1
BATS_UTILS_PATH: /bats
command: |
bash -c '
command:
- bash
- -c
- |
go build -o /usr/bin/lets *.go
ARGS="--tap --verbose-run --trace"
if [[ -n "${LETSOPT_TEST}" ]]; then
bats ${ARGS} tests/"${LETSOPT_TEST}"
bats tests/"${LETSOPT_TEST}" ${LETSOPT_OPTS}
else
bats ${ARGS} tests
bats tests ${LETSOPT_OPTS}
fi
'
10 changes: 9 additions & 1 deletion lets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,25 @@ commands:
description: Run bats tests
depends: [build-lets-image]
options: |
Usage: lets test-bats [<test>]
Usage: lets test-bats [<test>] [--opts=<opts>]
Example:
lets test-bats config_version.bats
cmd: |
docker-compose run --rm test-bats
test-completions:
ref: test-bats
args: zsh_completion.bats_
description: |
Run completions tests
This tests are separate because it hangs on Github Actions
test:
description: Run unit and bats tests
depends:
- test-unit
- test-bats
- test-completions

coverage:
description: Run tests for lets
Expand Down
4 changes: 0 additions & 4 deletions tests/test_helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ cleanup() {
rm -rf .lets
}

cleanup_completion() {
rm -rf _lets
}

# Usage:

# my_array=(2,4,1)
Expand Down
64 changes: 0 additions & 64 deletions tests/test_helpers_completion.bash

This file was deleted.

13 changes: 2 additions & 11 deletions tests/zsh_completion.bats → tests/zsh_completion.bats_
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
load test_helpers
load "${BATS_UTILS_PATH}/bats-support/load.bash"
load "${BATS_UTILS_PATH}/bats-assert/load.bash"

setup() {
load "${BATS_UTILS_PATH}/bats-support/load.bash"
load "${BATS_UTILS_PATH}/bats-assert/load.bash"
cd ./tests/zsh_completion
cleanup
cleanup_completion
}

create_completion() {
lets completion --shell=zsh > _lets
}

@test "zsh_completion: should complete run command" {
create_completion
run ./completion_helper.sh "lets r"

assert_success
assert_output "run"
}

@test "zsh_completion: should complete run command options" {
create_completion
run ./completion_helper.sh "lets run --"

assert_success
Expand All @@ -32,15 +25,13 @@ EOF
}

@test "zsh_completion: should complete run command options: --debug" {
create_completion
run ./completion_helper.sh "lets run --d"

assert_success
assert_output "--debug"
}

@test "zsh_completion: should complete run command options: --env" {
create_completion
run ./completion_helper.sh "lets run --e"

assert_success
Expand Down
53 changes: 1 addition & 52 deletions tests/zsh_completion/completion_helper.sh
Original file line number Diff line number Diff line change
@@ -1,59 +1,8 @@
#! /bin/zsh

autoload -Uz compinit && compinit

# source _lets

#---------------------
compdef _lets lets

LETS_EXECUTABLE=lets

function _lets {
echo "Completing !!!!"
local state

_arguments -C -s \
"1: :->cmds" \
'*::arg:->args'

case $state in
cmds)
_lets_commands
;;
args)
_lets_command_options "${words[1]}"
;;
esac
}

# Check if in folder with correct lets.yaml file
_check_lets_config() {
${LETS_EXECUTABLE} 1>/dev/null 2>/dev/null
echo $?
}

_lets_commands () {
local cmds
eval "$(echo "$(lets completion -s zsh)" | sed 's/#compdef/compdef/')"

if [ $(_check_lets_config) -eq 0 ]; then
IFS=$'\n' cmds=($(${LETS_EXECUTABLE} completion --commands --verbose))
else
cmds=()
fi
_describe -t commands 'Available commands' cmds
}

_lets_command_options () {
local cmd=$1

if [ $(_check_lets_config) -eq 0 ]; then
IFS=$'\n'
_arguments -s $(${LETS_EXECUTABLE} completion --options=${cmd} --verbose)
fi
}
#---------------------
# Define our test function.
comptest () {
# Gather all matching completions in this array.
# -U discards duplicates.
Expand Down

0 comments on commit f61311c

Please sign in to comment.