[PATCH] tests: factor out duplication

Jim Meyering meyering at redhat.com
Fri Jun 20 12:04:30 UTC 2008


* 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=3D=
1

-# Test for mkpart in scripting mode
-test_expect_success \
-    'Create the test file' \
-    'dd if=3D/dev/zero of=3Dtestfile bs=3D512 count=3D100 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=3D/dev/zero of=3Dtestfile bs=3D512 count=3D100 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,=0D   *=0D,,;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=3D/dev/zero of=3Dtestfile bs=3D512 count=3D100 2> /dev/null'
-
-test_expect_failure \
-    'Test the scripting mode of mkpartfs' \
-    'parted -s testfile "mklabel gpt mkpartfs primary ext3 1s -1s" > out=
S'
-
-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=3D/dev/zero of=3Dtestfile bs=3D512 count=3D100 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,=0D   *=0D,,;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=3D/dev/zero of=3Dtestfile bs=3D512 count=3D100 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=3D/dev/zero of=3Dtestfile bs=3D512 count=3D100 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,=0D   *=0D,,;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




More information about the parted-devel mailing list