[Parted-commits] GNU Parted Official Repository: Changes to 'master'

Jim Meyering meyering at alioth.debian.org
Fri Jun 20 13:21:24 UTC 2008


 parted/parted.c            |   36 ++++++++++++++++------
 tests/Makefile.am          |    3 +
 tests/t3000-constraints.sh |    6 +--
 tests/t7000-scripting.sh   |   71 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 102 insertions(+), 14 deletions(-)

New commits:
commit e4474291931390c5a205efbde5e787f57e36fa95
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri Jun 20 14:12:25 2008 +0200

    tests: avoid test failure due to added newline in diagnostic
    
    * tests/t3000-constraints.sh: Adapt to changed output syntax.

diff --git a/tests/t3000-constraints.sh b/tests/t3000-constraints.sh
index 183f2db..7dc5341 100755
--- a/tests/t3000-constraints.sh
+++ b/tests/t3000-constraints.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright (C) 2007 Free Software Foundation, Inc.
+# Copyright (C) 2007-2008 Free Software Foundation, 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
@@ -30,8 +30,8 @@ test_expect_success \
      { echo y; echo c; } > in &&
      { emit_superuser_warning
        echo "Warning: You requested a partition from 1000kB to 2000kB."
-       echo "The closest location we can manage is 15.9kB to 15.9kB." \
-	    " Is this still acceptable to you?"
+       echo "The closest location we can manage is 15.9kB to 15.9kB."
+       echo "Is this still acceptable to you?"
        echo "Yes/No? y"
        echo "Error: File system too small for ext2."; } > exp &&
      parted -s $dev mklabel msdos &&

commit bd74aaf75b6fd2544f9ded6943601092c6cff592
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri Jun 20 14:04:30 2008 +0200

    tests: factor out duplication
    
    * tests/t7000-scripting.sh: Use a loop rather than
    two copies of each of 7 tests.

diff --git a/tests/t7000-scripting.sh b/tests/t7000-scripting.sh
index 72f17d6..ba4ddc4 100755
--- a/tests/t7000-scripting.sh
+++ b/tests/t7000-scripting.sh
@@ -30,74 +30,42 @@ EOF
   sed s/Error/Warning/ errS
   printf 'Is this still acceptable to you?\nYes/No?'; } >> errI || fail=1
 
-# Test for mkpart in scripting mode
-test_expect_success \
-    'Create the test file' \
-    'dd if=/dev/zero of=testfile bs=512 count=100 2> /dev/null'
-
-test_expect_failure \
-    'Test the scripting mode of mkpart' \
-    'parted -s testfile "mklabel gpt mkpart primary ext3 1s -1s" > outS'
-
-test_expect_success \
-    'Compare the real error and the expected one' \
-    '$compare outS errS'
-
-# Test for mkpart in interactive mode.
-test_expect_success \
-    'Create the test file' \
-    '
-    rm testfile ;
-    dd if=/dev/zero of=testfile bs=512 count=100 2> /dev/null
-    '
-test_expect_failure \
-    'Test the interactive mode of mkpart' \
-    'echo n | \
-    parted ---pretend-input-tty testfile \
-    "mklabel gpt mkpart primary ext3 1s -1s" > out
-    '
-# We have to format the output before comparing.
-test_expect_success \
-    'normalize the actual output' \
-    'sed "s,
   *
,,;s, $,," out > o2 && mv -f o2 out'
-
-test_expect_success \
-    'Compare the real error and the expected one' \
-    '$compare out errI'
-
-# Test for mkpartfs in scripting mode
-test_expect_success \
-    'Create the test file' \
-    'dd if=/dev/zero of=testfile bs=512 count=100 2> /dev/null'
-
-test_expect_failure \
-    'Test the scripting mode of mkpartfs' \
-    'parted -s testfile "mklabel gpt mkpartfs primary ext3 1s -1s" > outS'
-
-test_expect_success \
-    'Compare the real error and the expected one' \
-    '$compare outS errS'
-
-# Test for mkpartfs in interactive mode.
-test_expect_success \
-    'Create the test file' \
-    '
-    rm testfile ;
-    dd if=/dev/zero of=testfile bs=512 count=100 2> /dev/null
-    '
-test_expect_failure \
-    'Test the interactive mode of mkpartfs' \
-    'echo n | \
-    parted ---pretend-input-tty testfile \
-    "mklabel gpt mkpartfs primary ext3 1s -1s" > out
-    '
-# We have to format the output before comparing.
-test_expect_success \
-    'normalize the actual output' \
-    'sed "s,
   *
,,;s, $,," out > o2 && mv -f o2 out'
-
-test_expect_success \
-    'Compare the real error and the expected one' \
-    '$compare out errI'
-
+for mkpart in mkpart mkpartfs; do
+
+  # Test for mkpart/mkpartfs in scripting mode
+  test_expect_success \
+      'Create the test file' \
+      'dd if=/dev/zero of=testfile bs=512 count=100 2> /dev/null'
+
+  test_expect_failure \
+      "Test the scripting mode of $mkpart" \
+      'parted -s testfile -- mklabel gpt '$mkpart' primary ext3 1s -1s > out'
+
+  test_expect_success \
+      'Compare the real error and the expected one' \
+      '$compare out errS'
+
+  # Test mkpart/mkpartfsin interactive mode.
+  test_expect_success \
+      'Create the test file' \
+      '
+      rm testfile ;
+      dd if=/dev/zero of=testfile bs=512 count=100 2> /dev/null
+      '
+  test_expect_failure \
+      "Test the interactive mode of $mkpart" \
+      'echo n | \
+      parted ---pretend-input-tty testfile \
+      "mklabel gpt '$mkpart' primary ext3 1s -1s" > out
+      '
+  # We have to format the output before comparing.
+  test_expect_success \
+      'normalize the actual output' \
+      'sed "s,
   *
,,;s, $,," out > o2 && mv -f o2 out'
+
+  test_expect_success \
+      'Compare the real error and the expected one' \
+      '$compare out errI'
+
+done
 test_done

commit 00628b980a88b7b7086804d67fd9d8a434112629
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri Jun 20 12:09:40 2008 +0200

    tests: use consistent output normalization code
    
    * tests/t7000-scripting.sh: same as in e.g., t3000-constraints.sh.
    Use the same name for all output files, "out", not "out1".

diff --git a/tests/t7000-scripting.sh b/tests/t7000-scripting.sh
index d3c7342..72f17d6 100755
--- a/tests/t7000-scripting.sh
+++ b/tests/t7000-scripting.sh
@@ -28,7 +28,7 @@ EOF
 
 { emit_superuser_warning
   sed s/Error/Warning/ errS
-  printf 'Is this still acceptable to you?\nYes/No? '; } >> errI || fail=1
+  printf 'Is this still acceptable to you?\nYes/No?'; } >> errI || fail=1
 
 # Test for mkpart in scripting mode
 test_expect_success \
@@ -54,16 +54,16 @@ test_expect_failure \
     'Test the interactive mode of mkpart' \
     'echo n | \
     parted ---pretend-input-tty testfile \
-    "mklabel gpt mkpart primary ext3 1s -1s" > outI
+    "mklabel gpt mkpart primary ext3 1s -1s" > out
     '
 # We have to format the output before comparing.
 test_expect_success \
-    'normilize the output' \
-    'sed -e "s,^.*Warning,Warning," -e "s,^.*Yes/No,Yes/No," -i outI'
+    'normalize the actual output' \
+    'sed "s,
   *
,,;s, $,," out > o2 && mv -f o2 out'
 
 test_expect_success \
     'Compare the real error and the expected one' \
-    '$compare outI errI'
+    '$compare out errI'
 
 # Test for mkpartfs in scripting mode
 test_expect_success \
@@ -89,15 +89,15 @@ test_expect_failure \
     'Test the interactive mode of mkpartfs' \
     'echo n | \
     parted ---pretend-input-tty testfile \
-    "mklabel gpt mkpartfs primary ext3 1s -1s" > outI
+    "mklabel gpt mkpartfs primary ext3 1s -1s" > out
     '
 # We have to format the output before comparing.
 test_expect_success \
-    'normilize the output' \
-    'sed -e "s,^.*Warning,Warning," -e "s,^.*Yes/No,Yes/No," -i outI'
+    'normalize the actual output' \
+    'sed "s,
   *
,,;s, $,," out > o2 && mv -f o2 out'
 
 test_expect_success \
     'Compare the real error and the expected one' \
-    '$compare outI errI'
+    '$compare out errI'
 
 test_done

commit 0faa0c9bd2b170a9ca87a981d32282d1f16c3341
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri Jun 20 12:01:42 2008 +0200

    tests: avoid failure when run as non-root
    
    * tests/t7000-scripting.sh: and avoid some duplication

diff --git a/tests/t7000-scripting.sh b/tests/t7000-scripting.sh
index 5022f91..d3c7342 100755
--- a/tests/t7000-scripting.sh
+++ b/tests/t7000-scripting.sh
@@ -21,17 +21,14 @@ test_description='Make sure the scripting option works (-s) properly.'
 . $srcdir/test-lib.sh
 
 # The failure messages.
-cat << EOF >> errS || fail=1
+cat << EOF > errS || fail=1
 Error: You requested a partition from 512B to 50.7kB.
 The closest location we can manage is 17.4kB to 33.8kB.
 EOF
 
-cat << EOF >> errI || fail=1
-Warning: You requested a partition from 512B to 50.7kB.
-The closest location we can manage is 17.4kB to 33.8kB.
-Is this still acceptable to you?
-EOF
-echo -n "Yes/No? " >> errI
+{ emit_superuser_warning
+  sed s/Error/Warning/ errS
+  printf 'Is this still acceptable to you?\nYes/No? '; } >> errI || fail=1
 
 # Test for mkpart in scripting mode
 test_expect_success \

commit 81ef5bcfb3462e0910e6fdeaa64ab74f93b00061
Author: Joel Andres Granados <jgranado at redhat.com>
Date:   Fri Jun 20 11:49:27 2008 +0200

    Fix the script mode for mkpart and mkpartfs.
    
    To: parted-devel at lists.alioth.debian.org
    Date: Fri, 20 Jun 2008 11:37:41 +0200
    X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on rho.meyering.net
    X-Spam-Level:
    X-Spam-Status: No, score=-13.8 required=3.2 tests=AWL,BAYES_00,
    	RCVD_IN_DNSWL_LOW autolearn=ham version=3.2.5
    
    In scripting mode, parted used to ask the user for confirmation
    when the values to be used where not the ones specified by the user.
    * parted/parted.c (do_mkpart, do_mkpartfs): if opt_script_mode is.
      set fail, if it's not, warn and ask for intervention.
    * tests/Makefile.am : include the new test in the TEST list.
    * tests/t7000-scripting.sh : Distribute new test case.

diff --git a/parted/parted.c b/parted/parted.c
index 9f79ea4..28357f4 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -776,14 +776,24 @@ do_mkpart (PedDevice** dev)
                         start_sol = ped_unit_format (*dev, part->geom.start);
                         end_sol   = ped_unit_format (*dev, part->geom.end);
 
+                        /* In script mode failure to use specified values is fatal.
+                         * However, in interactive mode, it merely elicits a warning
+                         * and a prompt for whether to proceed.  The same appies for
+                         * do_mkpartfs function.
+                         */
                         switch (ped_exception_throw (
-                                PED_EXCEPTION_WARNING,
-                                PED_EXCEPTION_YES_NO,
+                                (opt_script_mode
+                                 ? PED_EXCEPTION_ERROR
+                                 : PED_EXCEPTION_WARNING),
+                                (opt_script_mode
+                                 ? PED_EXCEPTION_CANCEL
+                                 : PED_EXCEPTION_YES_NO),
                                 _("You requested a partition from %s to %s.\n"
                                   "The closest location we can manage is "
-                                  "%s to %s.  "
-                                  "Is this still acceptable to you?"),
-                                start_usr, end_usr, start_sol, end_sol))
+                                  "%s to %s.%s"),
+                                start_usr, end_usr, start_sol, end_sol,
+                                (opt_script_mode ? ""
+                                 : _("\nIs this still acceptable to you?"))))
                         {
                                 case PED_EXCEPTION_YES:
                                         /* all is well in this state */
@@ -937,13 +947,19 @@ do_mkpartfs (PedDevice** dev)
                         end_sol   = ped_unit_format (*dev, part->geom.end);
 
                         switch (ped_exception_throw (
-                                PED_EXCEPTION_WARNING,
-                                PED_EXCEPTION_YES_NO,
+                                (opt_script_mode
+                                 ? PED_EXCEPTION_ERROR
+                                 : PED_EXCEPTION_WARNING),
+                                (opt_script_mode
+                                 ? PED_EXCEPTION_CANCEL
+                                 : PED_EXCEPTION_YES_NO),
                                 _("You requested a partition from %s to %s.\n"
                                   "The closest location we can manage is "
-                                  "%s to %s.  "
-                                  "Is this still acceptable to you?"),
-                                start_usr, end_usr, start_sol, end_sol)) {
+                                  "%s to %s.%s"),
+                                start_usr, end_usr, start_sol, end_sol,
+                                (opt_script_mode ? ""
+                                 : _("\nIs this still acceptable to you?"))))
+                        {
                                 case PED_EXCEPTION_YES:
                                         /* all is well in this state */
                                         break;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ebebf49..fbcad7c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -12,7 +12,8 @@ TESTS = \
   t4100-msdos-partition-limits.sh \
   t4100-dvh-partition-limits.sh \
   t5000-tags.sh \
-  t6000-dm.sh
+  t6000-dm.sh \
+  t7000-scripting.sh
 
 EXTRA_DIST = \
   $(TESTS) test-lib.sh lvm-utils.sh
diff --git a/tests/t7000-scripting.sh b/tests/t7000-scripting.sh
new file mode 100755
index 0000000..5022f91
--- /dev/null
+++ b/tests/t7000-scripting.sh
@@ -0,0 +1,106 @@
+#!/bin/sh
+
+# Copyright (C) 2008 Free Software Foundation, 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 3 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, see <http://www.gnu.org/licenses/>.
+
+test_description='Make sure the scripting option works (-s) properly.'
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+
+# The failure messages.
+cat << EOF >> errS || fail=1
+Error: You requested a partition from 512B to 50.7kB.
+The closest location we can manage is 17.4kB to 33.8kB.
+EOF
+
+cat << EOF >> errI || fail=1
+Warning: You requested a partition from 512B to 50.7kB.
+The closest location we can manage is 17.4kB to 33.8kB.
+Is this still acceptable to you?
+EOF
+echo -n "Yes/No? " >> errI
+
+# Test for mkpart in scripting mode
+test_expect_success \
+    'Create the test file' \
+    'dd if=/dev/zero of=testfile bs=512 count=100 2> /dev/null'
+
+test_expect_failure \
+    'Test the scripting mode of mkpart' \
+    'parted -s testfile "mklabel gpt mkpart primary ext3 1s -1s" > outS'
+
+test_expect_success \
+    'Compare the real error and the expected one' \
+    '$compare outS errS'
+
+# Test for mkpart in interactive mode.
+test_expect_success \
+    'Create the test file' \
+    '
+    rm testfile ;
+    dd if=/dev/zero of=testfile bs=512 count=100 2> /dev/null
+    '
+test_expect_failure \
+    'Test the interactive mode of mkpart' \
+    'echo n | \
+    parted ---pretend-input-tty testfile \
+    "mklabel gpt mkpart primary ext3 1s -1s" > outI
+    '
+# We have to format the output before comparing.
+test_expect_success \
+    'normilize the output' \
+    'sed -e "s,^.*Warning,Warning," -e "s,^.*Yes/No,Yes/No," -i outI'
+
+test_expect_success \
+    'Compare the real error and the expected one' \
+    '$compare outI errI'
+
+# Test for mkpartfs in scripting mode
+test_expect_success \
+    'Create the test file' \
+    'dd if=/dev/zero of=testfile bs=512 count=100 2> /dev/null'
+
+test_expect_failure \
+    'Test the scripting mode of mkpartfs' \
+    'parted -s testfile "mklabel gpt mkpartfs primary ext3 1s -1s" > outS'
+
+test_expect_success \
+    'Compare the real error and the expected one' \
+    '$compare outS errS'
+
+# Test for mkpartfs in interactive mode.
+test_expect_success \
+    'Create the test file' \
+    '
+    rm testfile ;
+    dd if=/dev/zero of=testfile bs=512 count=100 2> /dev/null
+    '
+test_expect_failure \
+    'Test the interactive mode of mkpartfs' \
+    'echo n | \
+    parted ---pretend-input-tty testfile \
+    "mklabel gpt mkpartfs primary ext3 1s -1s" > outI
+    '
+# We have to format the output before comparing.
+test_expect_success \
+    'normilize the output' \
+    'sed -e "s,^.*Warning,Warning," -e "s,^.*Yes/No,Yes/No," -i outI'
+
+test_expect_success \
+    'Compare the real error and the expected one' \
+    '$compare outI errI'
+
+test_done



More information about the Parted-commits mailing list