Joel Andres Granados <[EMAIL PROTECTED]> wrote:
> I followed all of Jims suuggestions and added an additional detail :)  To 
> avoid having the message be a bit long I put a "\n" at the beginning of the 
> "are you sure..." string.  Thats about it.
> I was a pain getting the strings to compare correctly in the tests :)

Thanks for persevering.
Writing good tests isn't easy.

A few additional changes are required, but I'll take care
of the rest.  For example, when running tests as non-root,
they fail due to this:

  * expecting success: $compare outI errI
  --- outI        2008-06-20 09:55:21.000000000 +0000
  +++ errI        2008-06-20 09:55:21.000000000 +0000
  @@ -1,4 +1,3 @@
  -WARNING: You are not superuser.  Watch out for permissions.
   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?

The first change set below fixes that and also removes some
unnecessary duplication in generating the expected output files.

The 2nd uses the same sed command as used in another test
(candidate now to be factored out into test-lib.sh), for consistency.
[note that there are literal ^M (CR) bytes in the patch]

The 3rd converts 14 tests to a 2x-loop over just 7 tests.

The 4th adjusts the now-failing t3000-constraints.sh test
to accommodate the changed diagnostic.

I expect to push your change set and the four below later today.

Jim

>From 0faa0c9bd2b170a9ca87a981d32282d1f16c3341 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Fri, 20 Jun 2008 12:01:42 +0200
Subject: [PATCH] tests: avoid failure when run as non-root

* tests/t7000-scripting.sh: and avoid some duplication
---
 tests/t7000-scripting.sh |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

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 \
--
1.5.6.7.g67e08b


>From 00628b980a88b7b7086804d67fd9d8a434112629 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Fri, 20 Jun 2008 12:09:40 +0200
Subject: [PATCH] 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".
---
 tests/t7000-scripting.sh |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

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
--
1.5.6.7.g67e08b


>From bd74aaf75b6fd2544f9ded6943601092c6cff592 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Fri, 20 Jun 2008 14:04:30 +0200
Subject: [PATCH] tests: factor out duplication

* tests/t7000-scripting.sh: Use a loop rather than
two copies of each of 7 tests.
---
 tests/t7000-scripting.sh |  108 ++++++++++++++++------------------------------
 1 files changed, 38 insertions(+), 70 deletions(-)

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
--
1.5.6.7.g67e08b


>From e4474291931390c5a205efbde5e787f57e36fa95 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Fri, 20 Jun 2008 14:12:25 +0200
Subject: [PATCH] tests: avoid test failure due to added newline in diagnostic

* tests/t3000-constraints.sh: Adapt to changed output syntax.
---
 tests/t3000-constraints.sh |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

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 &&
--
1.5.6.7.g67e08b

_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel

Reply via email to