Incorrect accquiring bugdir command line argument
[be.git] / test_usage.sh
1 #!/bin/bash
2 #
3 # Run through some simple usage cases.  This both tests that important
4 # features work, and gives an example of suggested usage to get people
5 # started.
6 #
7 # usage: test_usage.sh VCS
8 # where VCS is one of:
9 #   bzr, git, hg, arch, none
10 #
11 # Note that this script uses the *installed* version of be, not the
12 # one in your working tree.
13
14 set -e # exit immediately on failed command
15 set -o pipefail # pipes fail if any stage fails
16 set -v # verbose, echo commands to stdout
17
18 exec 6>&2 # save stderr to file descriptor 6
19 exec 2>&1 # fd 2 now writes to stdout
20
21 if [ $# -gt 1 ]
22 then
23     echo "usage: test_usage.sh [VCS]"
24     echo ""
25     echo "where VCS is one of"
26     for VCS in arch bzr darcs git hg none
27     do
28         echo "  $VCS"
29     done
30     exit 1
31 elif [ $# -eq 0 ]
32 then
33     for VCS in arch bzr darcs git hg none
34     do
35         echo -e "\n\nTesting $VCS\n\n"
36         $0 "$VCS" || exit 1
37     done
38     exit 0
39 fi
40
41 VCS="$1"
42
43 TESTDIR=`mktemp -d /tmp/BEtest.XXXXXXXXXX`
44 cd $TESTDIR
45
46 # Initialize the VCS repository
47 if [ "$VCS" == "arch" ]
48 then
49     ID=`tla my-id`
50     ARCH_PARAM_DIR="$HOME/.arch-params"
51     ARCH_ARCHIVE_ROOT=`mktemp -d /tmp/BEtest.XXXXXXXXXX`
52     UNIQUE=`echo "$ARCH_ARCHIVE_ROOT" | sed 's/\/tmp\/BEtest.//;s/[0-9]//g'` 
53     ARCH_ARCHIVE="j@x.com--BE-test-usage-$UNIQUE"
54     ARCH_PROJECT="BE-test-usage--twig--99.5"
55     ARCH_ARCHIVE_DIR="$ARCH_ARCHIVE_ROOT/$ARCH_PROJECT"
56     echo "tla make-archive $ARCH_ARCHIVE $ARCH_ARCHIVE_DIR"
57     tla make-archive $ARCH_ARCHIVE $ARCH_ARCHIVE_DIR
58     echo "tla archive-setup -A $ARCH_ARCHIVE $ARCH_PROJECT"
59     tla archive-setup -A $ARCH_ARCHIVE $ARCH_PROJECT
60     echo "tla init-tree -A $ARCH_ARCHIVE $ARCH_PROJECT"
61     tla init-tree -A $ARCH_ARCHIVE $ARCH_PROJECT
62     echo "Adjusing the naming conventions to allow .files"
63     sed -i 's/^source .*/source ^[._=a-zA-X0-9].*$/' '{arch}/=tagging-method'
64     echo "tla import -A $ARCH_ARCHIVE --summary 'Began versioning'"
65     tla import -A $ARCH_ARCHIVE --summary 'Began versioning'
66 elif [ "$VCS" == "bzr" ]
67 then
68     ID=`bzr whoami`
69     bzr init
70 elif [ "$VCS" == "darcs" ]
71 then
72     if [ -z "$DARCS_EMAIL" ]; then
73         export DARCS_EMAIL="J. Doe <jdoe@example.com>"
74     fi
75     ID="$DARCS_EMAIL"
76     darcs init
77 elif [ "$VCS" == "git" ]
78 then
79     NAME=`git config user.name`
80     EMAIL=`git config user.email`
81     ID="$NAME <$EMAIL>"
82     git init
83 elif [ "$VCS" == "hg" ]
84 then
85     ID=`hg showconfig ui.username`
86     hg init
87 elif [ "$VCS" == "none" ]
88 then
89     ID=`id -nu`
90 else
91     echo "Unrecognized VCS '$VCS'"
92     exit 1
93 fi
94
95 if [ -z "$ID" ]
96 then # set a default ID for VCSs that aren't tracking one yet.
97     ID="John Doe <jdoe@example.com>"
98 fi
99 echo "I am '$ID'"
100
101 be init  # initialize the Bugs Everywhere repository
102 OUT=`be new 'having too much fun'` # create a new bug
103 echo "$OUT"
104 BUG=`echo "$OUT" | sed -n 's/Created bug with ID //p'`
105 echo "Working with bug: $BUG"
106 be comment $BUG "This is an argument"
107 #be set user_id "$ID"    # get tired of guessing user id for none VCS
108 be set                  # show settings
109 be comment $BUG/ "No it isn't" # comment on the first comment
110 be show $BUG            # show details on a given bug
111 be status closed $BUG   # set bug status to 'closed'
112 be comment $BUG "It's closed, but I can still comment."
113 if [ "$VCS" != 'none' ]; then
114     be commit 'Initial commit'
115 fi
116 be status open $BUG     # set bug status to 'open'
117 be comment $BUG "Reopend, comment again"
118 be status fixed $BUG    # set bug status to 'fixed'
119 be list                 # list all open bugs
120 be list --status fixed  # list all fixed bugs
121 be assign - $BUG        # assign the bug to yourself
122 be list -m --status fixed # see fixed bugs assigned to you
123 be assign 'Joe' $BUG    # assign the bug to Joe
124 be list -a Joe --status fixed # list the fixed bugs assigned to Joe
125 be assign none $BUG     # un-assign the bug
126 if [ "$VCS" != 'none' ]; then
127   be diff               # see what has changed
128 fi
129 OUT=`be new 'also having too much fun'`
130 BUGB=`echo "$OUT" | sed -n 's/Created bug with ID //p'`
131 be comment $BUGB "Blissfully unaware of a similar bug"
132 be merge $BUG $BUGB     # join BUGB to BUG
133 be --no-pager show $BUG            # show bug details & comments
134 # you can also export/import XML bugs/comments
135 OUT=`be new 'yet more fun'`
136 BUGC=`echo "$OUT" | sed -n 's/Created bug with ID //p'`
137 be comment $BUGC "The ants go marching..."
138 be show --xml $BUGC/ | be import-xml --add-only --root $BUG -
139 be remove $BUG # decide that you don't like that bug after all
140 be commit "You can even commit using BE"
141 be commit --allow-empty "And you can add empty commits if you like"
142 be commit "But this will fail" || echo "Failed"
143
144 cd /
145 rm -rf $TESTDIR
146
147 if [ "$VCS" == "arch" ]
148 then
149     # Cleanup everything outside of TESTDIR
150     rm -rf "$ARCH_ARCHIVE_ROOT"
151     rm -rf "$ARCH_PARAM_DIR/=locations/$ARCH_ARCHIVE"
152 fi
153
154 exec 2>&6 6>&- # restore stderr and close fd 6