From 22cee80bc2f631703bf417a54ef4e0f0837e921a Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Fri, 11 Sep 2009 09:27:57 +0100 Subject: guestfish: Enable grouping in string lists This change adds the ability to group entries in a string list with single quotes. So the string: "'foo bar'" becomes 1 token rather than 2. Consequently single quotes must now be escaped: "\'" resolves to a literal single quote. Incidentally, this change also alters another, probably unintentional behaviour of the previous implementation, in that tokens are separated by any amount of whitespace rather than a single whitespace character. I.e.: "a b" resolves to: 'a' 'b' rather than: 'a' '' 'b' That last syntax can be used if an empty argument is still desired. Whitespace is now also defined to include tabs. parse_string_list can also now fail if it contains an unmatched open quote. --- regressions/Makefile.am | 3 ++- regressions/test-stringlist.sh | 60 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100755 regressions/test-stringlist.sh (limited to 'regressions') diff --git a/regressions/Makefile.am b/regressions/Makefile.am index 3279f95c..9112b94d 100644 --- a/regressions/Makefile.am +++ b/regressions/Makefile.am @@ -32,7 +32,8 @@ TESTS = \ test-qemudie-synch.sh \ test-read_file.sh \ test-remote.sh \ - test-reopen.sh + test-reopen.sh \ + test-stringlist.sh SKIPPED_TESTS = \ test-bootbootboot.sh diff --git a/regressions/test-stringlist.sh b/regressions/test-stringlist.sh new file mode 100755 index 00000000..0b0c476e --- /dev/null +++ b/regressions/test-stringlist.sh @@ -0,0 +1,60 @@ +#!/bin/sh - +# libguestfs +# Copyright (C) 2009 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# Test remote control of guestfish. + +set -e + +rm -f test.img + +eval `../fish/guestfish --listen` + +error=0 + +function check_echo { + test=$1 + expected=$2 + + local echo + + echo=$(../fish/guestfish --remote echo_daemon "$test") + if [ "$echo" != "$expected" ]; then + echo "Expected \"$expected\", got \"$echo\"" + error=1 + fi +} + +../fish/guestfish --remote alloc test.img 10M +../fish/guestfish --remote run + +check_echo "' '" " " +check_echo "\'" "'" +check_echo "'\''" "'" +check_echo "'\' '" "' " +check_echo "'\'foo\''" "'foo'" +check_echo "foo' 'bar" "foo bar" +check_echo "foo' 'bar" "foo bar" +check_echo "'foo' 'bar'" "foo bar" +check_echo "'foo' " "foo" +check_echo " 'foo'" "foo" + +../fish/guestfish --remote exit + +rm -f test.img + +exit $error -- cgit