From 4d96d0a6c6721f440ee7e6a28d9743d781b83455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Mon, 1 Apr 2013 16:19:21 +0200 Subject: [PATCH] add tests for completions --- test/completions.bats | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/completions.bats diff --git a/test/completions.bats b/test/completions.bats new file mode 100644 index 00000000..8bfb88d5 --- /dev/null +++ b/test/completions.bats @@ -0,0 +1,48 @@ +#!/usr/bin/env bats + +load test_helper + +create_command() { + bin="${RBENV_TEST_DIR}/bin" + mkdir -p "$bin" + echo "$2" > "${bin}/$1" + chmod +x "${bin}/$1" +} + +@test "command with no completion support" { + create_command "rbenv-hello" "#!$BASH + echo hello" + run rbenv-completions hello + assert_success "" +} + +@test "command with completion support" { + create_command "rbenv-hello" "#!$BASH +# provide rbenv completions +if [[ \$1 = --complete ]]; then + echo hello +else + exit 1 +fi" + run rbenv-completions hello + assert_success "hello" +} + +@test "forwards extra arguments" { + create_command "rbenv-hello" "#!$BASH +# provide rbenv completions +if [[ \$1 = --complete ]]; then + shift 1 + while [[ \$# -gt 0 ]]; do + echo \$1 + shift 1 + done +else + exit 1 +fi" + run rbenv-completions hello happy world + assert_success + assert_line 0 "happy" + assert_line 1 "world" + refute_line 2 +}