daemon: debug segv correct use of dereferencing NULL.
[libguestfs.git] / fish / test-guestfish-tilde.sh
1 #!/bin/bash -
2 # libguestfs
3 # Copyright (C) 2011 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 # Test guestfish tilde expansion.
20 # RHBZ#617440 guestfish: fails to tilde expand '~' when the $HOME env is unset
21 # RHBZ#511372 guestfish doesn't understand '~' in filenames
22 # and multiple other fixes to tilde handling.
23
24 set -e
25
26 # Don't rely on $HOME being set when this script is called.
27 HOME=$(pwd)
28 export HOME
29
30 if [ `echo 'echo ~' | ../fish/guestfish` != "$HOME" ]; then
31     echo "$0: failed: did not expand ~ correctly"
32     exit 1
33 fi
34
35 if [ `echo 'echo ~/foo' | ../fish/guestfish` != "$HOME/foo" ]; then
36     echo "$0: failed: did not expand ~/foo correctly"
37     exit 1
38 fi
39
40 # We can be reasonably sure that the root user will always exist and
41 # should have a home directory.
42 root="$(echo ~root)"
43
44 if [ `echo 'echo ~root' | ../fish/guestfish` != "$root" ]; then
45     echo "$0: failed: did not expand ~root correctly"
46     exit 1
47 fi
48
49 if [ `echo 'echo ~root/foo' | ../fish/guestfish` != "$root/foo" ]; then
50     echo "$0: failed: did not expand ~root/foo correctly"
51     exit 1
52 fi
53
54 # RHBZ#617440
55 unset HOME
56 home="$(echo ~)"
57
58 if [ `echo 'echo ~' | ../fish/guestfish` != "$home" ]; then
59     echo "$0: failed: did not expand ~ correctly when \$HOME unset"
60     exit 1
61 fi
62
63 if [ `echo 'echo ~/foo' | ../fish/guestfish` != "$home/foo" ]; then
64     echo "$0: failed: did not expand ~/foo correctly when \$HOME unset"
65     exit 1
66 fi
67
68 # Setting $HOME to pwd above causes guestfish to create a history
69 # file.  Remove it.
70 rm -f .guestfish