Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chipaca committed Nov 28, 2016
1 parent 80dd2c1 commit 4882f21
Show file tree
Hide file tree
Showing 26 changed files with 188 additions and 21 deletions.
6 changes: 5 additions & 1 deletion data/completion/snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- sh -*-
_complete() {
local cur prev words cword
_init_completion || return
Expand All @@ -23,7 +24,10 @@ _complete() {

case $command in
install|info|sign-build)
_filedir "*.snap"
_filedir "snap"
;;
ack)
_filedir
;;
try)
_filedir -d
Expand Down
7 changes: 7 additions & 0 deletions tests/main/completion/abort.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source lib.exp0

# abort completes with change ids
rechat "snap abort \t\t" "1 *2"

cancel
brexit
8 changes: 8 additions & 0 deletions tests/main/completion/ack.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source lib.exp0

# ack completes with directories and files
chat "snap ack ./\t\t" "ack.exp" true
chat "" " testdir/"

cancel
brexit
8 changes: 8 additions & 0 deletions tests/main/completion/buy.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source lib.exp0

# buy completes remote snaps only
chat "snap buy \t\t" "snap buy ??$"
chat "test-\t\t" "test-assumes*test-snapd-tools"

cancel
brexit
7 changes: 7 additions & 0 deletions tests/main/completion/change.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source lib.exp0

# change completes with change ids
rechat "snap change \t\t" "1 *2"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/delete-key.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap delete-key \t" "snap delete-key default"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/disable.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap disable \t\t" "core*test-snapd-tools"

cancel
brexit
7 changes: 7 additions & 0 deletions tests/main/completion/download.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source lib.exp0

# download with 3+ chars completes store stuff
chat "snap download test-\t\t" "test-assumes"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/enable.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap enable \t\t" "core*test-snapd-tools"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/export-key.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap export-key \t" "snap export-key default"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/get.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap get \t\t" "core*test-snapd-tools"

cancel
brexit
10 changes: 10 additions & 0 deletions tests/main/completion/info.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source lib.exp0

# info completes directories and snap files, and locally installed snaps
chat "snap inf\t\t\t" "bar.snap*core*testdir/"

# with 3+ chars, also remote snaps
chat "test-\t\t" "test-assumes"

cancel
brexit
18 changes: 14 additions & 4 deletions tests/main/completion/install.exp
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
source lib.exp
source lib.exp0

# install completes directories and snaps
chat "snap ins\t\t\t" "basic_1.0_all.snap*testdir/"
next
chat "snap ins\t\t\t" "bar.snap*testdir/"

# install with 3+ chars also completes store stuff
chat "tes\t\t\t" "test-snapd-tools*testdir/"
chat "tes\t\t\t" "test-assumes" true
# TODO: don't list things already installed:
chat "" "test-snapd-tools" true
chat "" "testdir/"
cancel

# no extra space added after a directory
chat "snap ins\t./tes\t" " ./testdir/$"
cancel

# extra space added after a file
chat "snap ins\t./bar\t" " ./bar.snap $"

cancel
brexit
15 changes: 15 additions & 0 deletions tests/main/completion/key.exp0
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
source lib.exp0

# create a key doesn't complete
chat "snap create-key \t\t" "snap create-key ??$"
chat "\r" "Passphrase:"
chat "\r" "Confirm passphrase:"
send "\r"

# this can take a while
set timeout 60

next
cancel
brexit

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set send_slow {1 0.1}
set timeout 5

proc delay {} {
sleep 0.1
sleep 0.5
}

proc chat {outstr instr {keep false}} {
Expand Down Expand Up @@ -41,20 +41,20 @@ proc next {} {
delay
expect {
timeout {puts "timeout"; exit 1}
"bash-*\[$#] "
"bash-*\[$#] $"
}
}

proc cancel {} {
send ""
send " \r"
next
}

proc brexit {} {
send "exit\r"
expect {
timeout {puts "timeout"; exit 1}
eof exit 0
eof {exit 0}
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/main/completion/list.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source lib.exp0

# list completes locally installed snaps
chat "snap list \t\t" "core*test-snapd-tools"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/refresh.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap refresh \t\t" "core*test-snapd-tools"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/remove.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap remove \t\t" "core*test-snapd-tools"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/revert.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap revert \t\t" "core*test-snapd-tools"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/set.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap set \t\t" "core*test-snapd-tools"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/sign-build.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap sign-build -k\t" "kdefault"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/sign.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap sign -k\t" "kdefault"

cancel
brexit
19 changes: 11 additions & 8 deletions tests/main/completion/task.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
summary: Check different completions
systems: [-ubuntu-core-16-64, -ubuntu-core-16-arm-64, -ubuntu-core-16-arm-32]

prepare: |
touch basic_1.0_all.snap
mkdir -p testdir
touch testdir/foo.snap
touch bar.snap
snap install core
snap install test-snapd-tools
expect -d -f key.exp0
restore: |
rm basic_1.0_all.snap
rm testdir/foo.snap bar.snap
rmdir testdir
execute: |
echo "Toplevel completion"
expect -d -f toplevel.exp
echo "Install completion"
expect -d -f install.exp
for i in *.exp; do
echo $i
expect -d -f $i
done
10 changes: 6 additions & 4 deletions tests/main/completion/toplevel.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source lib.exp
source lib.exp0

# --help completes
chat "snap --h\t" "snap --help $" true
Expand All @@ -13,9 +13,11 @@ chat "\t\t" "snap --version $"
cancel

# commands complete
rechat "snap in\t\t" "info *install *interfaces"
next
chat "s\t" "snap install "
rechat "snap in\t\t" "\[\n ]info\[\r ]" true
rechat "" "\[\n ]install\[\r ]" true
rechat "" "\[\n ]interfaces\[\r ]"

chat "s\t" "snap install $"

cancel
brexit
6 changes: 6 additions & 0 deletions tests/main/completion/try.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source lib.exp0

chat "snap try \t" "testdir/"

cancel
brexit
7 changes: 7 additions & 0 deletions tests/main/completion/watch.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source lib.exp0

# watch completes with change ids
rechat "snap watch \t\t" "1 *2"

cancel
brexit

0 comments on commit 4882f21

Please sign in to comment.