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