source: trunk/moap/test/test_bash_completion.sh @ 211

Revision 211, 2.1 KB checked in by thomas, 6 years ago (diff)

fix test

  • Property svn:executable set to *
Line 
1#!/bin/bash
2
3# test completion
4# call with the completion file as the first argument
5
6. $1
7
8
9# helper functions
10assert_equals()
11{
12    if [[ "$1" != "$2" ]];
13    then
14        echo "Result '$1' != expected '$2'"
15        exit 1
16    fi
17}
18
19# run the given function as a test and output
20test()
21{
22    echo -n "  $1 ... "
23    $1
24    if [[ $! -eq 0 ]]; then
25        echo "[OK]"
26    else
27        echo "[FAILED]"
28    fi 
29}
30
31# tests
32test_moap()
33{
34    unset COMPREPLY
35    _moap_complete_moap "moap "
36    assert_equals "${COMPREPLY[*]}" "bug changelog code doap ignore"
37
38    # completing a partial command will still return all possible commands
39    # bash will filter
40    unset COMPREPLY
41    _moap_complete_moap "moap do"
42    assert_equals "${COMPREPLY[*]}" "bug changelog code doap ignore"
43
44    # complete options
45    unset COMPREPLY
46    _moap_complete_moap moap -
47    assert_equals "${COMPREPLY[*]}" "--help --version -h -v"
48
49    # complete options
50    unset COMPREPLY
51    _moap_complete_moap moap --
52    assert_equals "${COMPREPLY[*]}" "--help --version"
53
54    # complete partial long options
55    unset COMPREPLY
56    _moap_complete_moap moap --ver
57    assert_equals "${COMPREPLY[*]}" "--version"
58
59    # complete commands with an argumentless option already specified
60    unset COMPREPLY
61    _moap_complete_moap moap --version
62    assert_equals "${COMPREPLY[*]}" "bug changelog code doap ignore"
63}
64
65test_moap_doap()
66{
67    unset COMPREPLY
68    _moap_complete_moap moap doa
69    assert_equals "${COMPREPLY[*]}" "doap"
70
71    unset COMPREPLY
72    _moap_complete_moap moap doap
73    assert_equals "${COMPREPLY[*]}" "bug freshmeat ical mail rss show"
74
75    unset COMPREPLY
76    _moap_complete_moap moap doap --ve
77    assert_equals "${COMPREPLY[*]}" "--version"
78
79    # complete commands with an argumented option without the argument
80    unset COMPREPLY
81    _moap_complete_moap moap doap --version
82    assert_equals "${COMPREPLY[*]}" ""
83
84    # complete commands with an argumented option already specified
85    unset COMPREPLY
86    _moap_complete_moap moap doap --version 0.9.1
87    assert_equals "${COMPREPLY[*]}" "bug freshmeat ical mail rss show"
88}
89
90test "test_moap"
91test "test_moap_doap"
Note: See TracBrowser for help on using the repository browser.