Reported bug with utf-8 strings
[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 RCS
8 # where RCS 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 ONLY_TEST_COMMIT="true"
22
23 if [ $# -gt 1 ]
24 then
25     echo "usage: test_usage.sh [RCS]"
26     echo ""
27     echo "where RCS is one of"
28     for RCS in arch bzr darcs git hg none
29     do
30         echo "  $RCS"
31     done
32     exit 1
33 elif [ $# -eq 0 ]
34 then
35     for RCS in arch bzr darcs git hg none
36     do
37         echo -e "\n\nTesting $RCS\n\n"
38         $0 "$RCS" || exit 1
39     done
40     exit 0
41 fi
42
43 RCS="$1"
44
45 TESTDIR=`mktemp -d /tmp/BEtest.XXXXXXXXXX`
46 cd $TESTDIR
47
48 if [ "$RCS" == "arch" ]
49 then
50     ID=`tla my-id`
51     ARCH_PARAM_DIR="$HOME/.arch-params"
52     ARCH_ARCHIVE_ROOT=`mktemp -d /tmp/BEtest.XXXXXXXXXX`
53     UNIQUE=`echo "$ARCH_ARCHIVE_ROOT" | sed 's/\/tmp\/BEtest.//;s/[0-9]//g'` 
54     ARCH_ARCHIVE="j@x.com--BE-test-usage-$UNIQUE"
55     ARCH_PROJECT="BE-test-usage--twig--99.5"
56     ARCH_ARCHIVE_DIR="$ARCH_ARCHIVE_ROOT/$ARCH_PROJECT"
57     echo "tla make-archive $ARCH_ARCHIVE $ARCH_ARCHIVE_DIR"
58     tla make-archive $ARCH_ARCHIVE $ARCH_ARCHIVE_DIR
59     echo "tla archive-setup -A $ARCH_ARCHIVE $ARCH_PROJECT"
60     tla archive-setup -A $ARCH_ARCHIVE $ARCH_PROJECT
61     echo "tla init-tree -A $ARCH_ARCHIVE $ARCH_PROJECT"
62     tla init-tree -A $ARCH_ARCHIVE $ARCH_PROJECT
63     echo "Adjusing the naming conventions to allow .files"
64     sed -i 's/^source .*/source ^[._=a-zA-X0-9].*$/' '{arch}/=tagging-method'
65     echo "tla import -A $ARCH_ARCHIVE --summary 'Began versioning'"
66     tla import -A $ARCH_ARCHIVE --summary 'Began versioning'
67 elif [ "$RCS" == "bzr" ]
68 then
69     ID=`bzr whoami`
70     bzr init
71 elif [ "$RCS" == "darcs" ]
72 then
73     if [ -z "$DARCS_EMAIL" ]; then
74         export DARCS_EMAIL="J. Doe <jdoe@example.com>"
75     fi
76     ID="$DARCS_EMAIL"
77     darcs init
78 elif [ "$RCS" == "git" ]
79 then
80     NAME=`git config user.name`
81     EMAIL=`git config user.email`
82     ID="$NAME <$EMAIL>"
83     git init
84 elif [ "$RCS" == "hg" ]
85 then
86     ID=`hg showconfig ui.username`
87     hg init
88 elif [ "$RCS" == "none" ]
89 then
90     ID=`id -nu`
91 else
92     echo "Unrecognized RCS '$RCS'"
93     exit 1
94 fi
95 if [ -z "$ID" ]
96 then # set a default ID
97     ID="John Doe <jdoe@example.com>"
98 fi
99 echo "I am '$ID'"
100
101 be init
102 OUT=`be new 'having too much fun'`
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 RCS
108 be set                  # show settings
109 be comment $BUG:1 "No it isn't" # comment on the first comment
110 be show $BUG            # show details on a given bug
111 be close $BUG           # set bug status to 'closed'
112 be comment $BUG "It's closed, but I can still comment."
113 be open $BUG            # set bug status to 'open'
114 be comment $BUG "Reopend, comment again"
115 be status $BUG fixed    # set bug status to 'fixed'
116 be list                 # list all open bugs
117 be list --status fixed  # list all fixed bugs
118 be assign $BUG          # assign the bug to yourself
119 be list -m -s fixed     # see fixed bugs assigned to you
120 be assign $BUG 'Joe'    # assign the bug to Joe
121 be list -a Joe -s fixed # list the fixed bugs assigned to Joe
122 be assign $BUG none     # assign the bug to noone
123 be diff                 # see what has changed
124 OUT=`be new 'also having too much fun'`
125 BUGB=`echo "$OUT" | sed -n 's/Created bug with ID //p'`
126 be comment $BUGB "Blissfully unaware of a similar bug"
127 be merge $BUG $BUGB     # join BUGB to BUG
128 be show $BUG            # show bug details & comments
129 # you can also export/import XML bugs/comments
130 OUT=`be new 'yet more fun'`
131 BUGC=`echo "$OUT" | sed -n 's/Created bug with ID //p'`
132 be comment $BUGC "The ants go marching..."
133 be show --xml $BUGC | be comment --xml ${BUG}:2 -
134 be remove $BUG # decide that you don't like that bug after all
135 be commit "You can even commit using BE"
136 be commit --allow-empty "And you can add empty commits if you like"
137 be commit "But this will fail" || echo "Failed"
138
139 cd /
140 rm -rf $TESTDIR
141
142 if [ "$RCS" == "arch" ]
143 then
144     # Cleanup everything outside of TESTDIR
145     rm -rf "$ARCH_ARCHIVE_ROOT"
146     rm -rf "$ARCH_PARAM_DIR/=locations/$ARCH_ARCHIVE"
147 fi
148
149 exec 2>&6 6>&- # restore stderr and close fd 6