1#!/usr/bin/env bash
2## Test for issue1465 - ortryrunning should try RHS if AND ONLY IF the
3## LHS wasn't found or wasn't executable.
4##
5## Copyright (C) 2009  Trent W. Buck
6##
7## Permission is hereby granted, free of charge, to any person
8## obtaining a copy of this software and associated documentation
9## files (the "Software"), to deal in the Software without
10## restriction, including without limitation the rights to use, copy,
11## modify, merge, publish, distribute, sublicense, and/or sell copies
12## of the Software, and to permit persons to whom the Software is
13## furnished to do so, subject to the following conditions:
14##
15## The above copyright notice and this permission notice shall be
16## included in all copies or substantial portions of the Software.
17##
18## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25## SOFTWARE.
26
27. lib                  # Load some portability helpers.
28darcs init      --repo R        # Create our test repo.
29
30FAKE_EDITOR_HOME=`pwd`
31cat <<FAKE > editor-good.hs
32import System.Environment
33import System.IO
34main = getArgs >>= \[name] -> writeFile name "fake"
35FAKE
36ghc -o editor-good --make editor-good.hs
37
38cat <<FAKE > editor-bad.hs
39import System.Exit
40main = exitWith (ExitFailure 127)
41FAKE
42ghc -o editor-bad --make editor-bad.hs
43
44cat <<FAKE > editor-gave-up.hs
45import System.Exit
46main = exitWith (ExitFailure 1)
47FAKE
48ghc -o editor-gave-up --make editor-gave-up.hs
49
50cat <<VI > vi.hs
51import System.Environment
52import System.IO
53main = getArgs >>= \[name] -> writeFile name "vi"
54VI
55ghc -o vi --make vi.hs
56
57cd R
58mkdir d
59unset TERM
60
61DARCSDIR=$(dirname $(which darcs))
62# the /dev/null stdin redirection is to make vi or the fallback editor just fail
63DARCS_EDITOR=$FAKE_EDITOR_HOME/editor-good \
64darcs record    -lam 'Initial commit.' --edit </dev/null &> log-1
65darcs changes   > changes-1
66darcs unrecord  -a
67grep fake changes-1
68
69# Bad editor: fall through to the next choice
70DARCS_EDITOR=$FAKE_EDITOR_HOME/editor-bad \
71PATH=.:$DARCSDIR \
72darcs record    -lam 'Initial commit.' --edit </dev/null &> log-2
73darcs changes   > changes-2
74darcs unrecord  -a
75grep "Initial" changes-2
76egrep -i 'vi|emacs|nano|edit' log-2
77
78# Normal failure (eg. user hit ^-C)
79# If Darcs did the right thing, the output won't make any mention of
80# the fallback editors.
81DARCS_EDITOR=$FAKE_EDITOR_HOME/editor-gave-up \
82darcs record    -lam 'Initial commit.' --edit </dev/null &> log-3
83darcs changes   > changes-3
84darcs unrecord  -a
85grep "Initial" changes-3
86not egrep -i 'not found|vi|emacs|nano|edit' log-3
87