daemon: debug segv correct use of dereferencing NULL.
[libguestfs.git] / edit / test-virt-edit.sh
1 #!/bin/bash -
2
3 export LANG=C
4 set -e
5
6 # Make a copy of the Fedora image so we can write to it then
7 # discard it.
8 cp ../tests/guests/fedora.img test.img
9
10 # Edit interactively.  We have to simulate this by setting $EDITOR.
11 # The command will be: echo newline >> /tmp/file
12 export EDITOR='echo newline >>'
13 ./virt-edit -a test.img /etc/test3
14 if [ "$(../cat/virt-cat -a test.img /etc/test3)" != "a
15 b
16 c
17 d
18 e
19 f
20 newline" ]; then
21     echo "$0: error: mismatch in interactive editing of file /etc/test3"
22     exit 1
23 fi
24 unset EDITOR
25
26 # Edit non-interactively, only if we have 'perl' binary.
27 if perl --version >/dev/null 2>&1; then
28     ./virt-edit -a test.img /etc/test3 -e 's/^[a-f]/$lineno/'
29     if [ "$(../cat/virt-cat -a test.img /etc/test3)" != "1
30 2
31 3
32 4
33 5
34 6
35 newline" ]; then
36         echo "$0: error: mismatch in non-interactive editing of file /etc/test3"
37         exit 1
38     fi
39 fi
40
41 # Discard test image.
42 rm test.img