[PATCH 2/2] tests: Ensure test files are newline-terminated

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently we only append a newline to 'actual' if 'expected'
(as loaded from file) already ends in a newline, but that
results in inconsistent behavior.

For example, some of the test files used by virhostcputest are
newline-terminated and some aren't. If we were to remove
existing newlines from those files or add them where they
aren't present, the test would still pass, and even using
VIR_TEST_REGENERATE_OUTPUT=1 wouldn't change them back.

Make things consistent by ensuring that 'actual' is always
newline-terminated. The only exception is when 'actual' is
completely empty: in that case, we want the file to be actually
empty, not contain a single empty line. query-jobs-empty.result
in qemumonitorjsondata/ is an example of this being used.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 ...69d019_36ea_4111_8f0a_8c9a70e21366-create.json |  2 +-
 ...69d019_36ea_4111_8f0a_8c9a70e21366-define.json |  2 +-
 ...441d39_495e_4243_ad9f_beb3f14c23d9-create.json |  2 +-
 ...441d39_495e_4243_ad9f_beb3f14c23d9-define.json |  2 +-
 ...dc4916_1ca8_49ac_b176_871d16c13076-create.json |  2 +-
 ...dc4916_1ca8_49ac_b176_871d16c13076-define.json |  2 +-
 .../disk-cdrom-network.args.disk1.pipe.778        |  2 +-
 .../disk-cdrom-network.args.disk2.pipe.780        |  2 +-
 .../disk-network-http.args.disk2.pipe.778         |  2 +-
 .../disk-network-http.args.disk3.pipe.780         |  2 +-
 ...source-curl-nbdkit-backing.args.disk0.pipe.778 |  2 +-
 .../disk-network-source-curl.args.disk0.pipe.778  |  2 +-
 .../disk-network-source-curl.args.disk1.pipe.780  |  2 +-
 .../disk-network-source-curl.args.disk1.pipe.782  |  2 +-
 .../disk-network-source-curl.args.disk2.pipe.784  |  2 +-
 .../disk-network-ssh-password.args.disk0.pipe.778 |  2 +-
 tests/testutils.c                                 | 15 ++++++---------
 .../linux-ppc64-deconf-cpus.signature             |  2 +-
 .../linux-ppc64-subcores1.signature               |  2 +-
 .../linux-ppc64-subcores2.signature               |  2 +-
 .../linux-ppc64-subcores3.signature               |  2 +-
 .../linux-s390x-with-frequency.signature          |  2 +-
 22 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-create.json b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-create.json
index bfc6dcace3..80f3b6cb2e 100644
--- a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-create.json
+++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-create.json
@@ -1 +1 @@
-{"mdev_type":"i915-GVTg_V5_8","start":"manual"}
\ No newline at end of file
+{"mdev_type":"i915-GVTg_V5_8","start":"manual"}
diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-define.json b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-define.json
index bfc6dcace3..80f3b6cb2e 100644
--- a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-define.json
+++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-define.json
@@ -1 +1 @@
-{"mdev_type":"i915-GVTg_V5_8","start":"manual"}
\ No newline at end of file
+{"mdev_type":"i915-GVTg_V5_8","start":"manual"}
diff --git a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-create.json b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-create.json
index e5b22b2c44..4fba307865 100644
--- a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-create.json
+++ b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-create.json
@@ -1 +1 @@
-{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribute-1":"attribute-value-1"},{"example-attribute-2":"attribute-value-2"}]}
\ No newline at end of file
+{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribute-1":"attribute-value-1"},{"example-attribute-2":"attribute-value-2"}]}
diff --git a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-define.json b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-define.json
index e5b22b2c44..4fba307865 100644
--- a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-define.json
+++ b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-define.json
@@ -1 +1 @@
-{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribute-1":"attribute-value-1"},{"example-attribute-2":"attribute-value-2"}]}
\ No newline at end of file
+{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribute-1":"attribute-value-1"},{"example-attribute-2":"attribute-value-2"}]}
diff --git a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-create.json b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-create.json
index 2e03d0bd8e..22d4a2e586 100644
--- a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-create.json
+++ b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-create.json
@@ -1 +1 @@
-{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribute":"attribute-value"}]}
\ No newline at end of file
+{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribute":"attribute-value"}]}
diff --git a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-define.json b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-define.json
index 2e03d0bd8e..22d4a2e586 100644
--- a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-define.json
+++ b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-define.json
@@ -1 +1 @@
-{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribute":"attribute-value"}]}
\ No newline at end of file
+{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribute":"attribute-value"}]}
diff --git a/tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe.778 b/tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe.778
index ccdd4033fc..dd67dde67b 100644
--- a/tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe.778
+++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe.778
@@ -1 +1 @@
-iscsi-mycluster_myname-secret
\ No newline at end of file
+iscsi-mycluster_myname-secret
diff --git a/tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe.780 b/tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe.780
index ccdd4033fc..dd67dde67b 100644
--- a/tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe.780
+++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe.780
@@ -1 +1 @@
-iscsi-mycluster_myname-secret
\ No newline at end of file
+iscsi-mycluster_myname-secret
diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk2.pipe.778 b/tests/qemunbdkitdata/disk-network-http.args.disk2.pipe.778
index 2c42c95930..3751afd16b 100644
--- a/tests/qemunbdkitdata/disk-network-http.args.disk2.pipe.778
+++ b/tests/qemunbdkitdata/disk-network-http.args.disk2.pipe.778
@@ -1 +1 @@
-test=testcookievalue; test2="blurb"
\ No newline at end of file
+test=testcookievalue; test2="blurb"
diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk3.pipe.780 b/tests/qemunbdkitdata/disk-network-http.args.disk3.pipe.780
index 2c42c95930..3751afd16b 100644
--- a/tests/qemunbdkitdata/disk-network-http.args.disk3.pipe.780
+++ b/tests/qemunbdkitdata/disk-network-http.args.disk3.pipe.780
@@ -1 +1 @@
-test=testcookievalue; test2="blurb"
\ No newline at end of file
+test=testcookievalue; test2="blurb"
diff --git a/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.args.disk0.pipe.778 b/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.args.disk0.pipe.778
index 20af4ae383..e72f706c3b 100644
--- a/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.args.disk0.pipe.778
+++ b/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.args.disk0.pipe.778
@@ -1 +1 @@
-cookie1=cookievalue1; cookie2=cookievalue2
\ No newline at end of file
+cookie1=cookievalue1; cookie2=cookievalue2
diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk0.pipe.778 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk0.pipe.778
index 20af4ae383..e72f706c3b 100644
--- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk0.pipe.778
+++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk0.pipe.778
@@ -1 +1 @@
-cookie1=cookievalue1; cookie2=cookievalue2
\ No newline at end of file
+cookie1=cookievalue1; cookie2=cookievalue2
diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.780 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.780
index ccdd4033fc..dd67dde67b 100644
--- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.780
+++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.780
@@ -1 +1 @@
-iscsi-mycluster_myname-secret
\ No newline at end of file
+iscsi-mycluster_myname-secret
diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.782 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.782
index 20af4ae383..e72f706c3b 100644
--- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.782
+++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.782
@@ -1 +1 @@
-cookie1=cookievalue1; cookie2=cookievalue2
\ No newline at end of file
+cookie1=cookievalue1; cookie2=cookievalue2
diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.784 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.784
index 5c035e84c5..af98693472 100644
--- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.784
+++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.784
@@ -1 +1 @@
-cookie1=cookievalue1; cookie2=cookievalue2; cookie3=cookievalue3
\ No newline at end of file
+cookie1=cookievalue1; cookie2=cookievalue2; cookie3=cookievalue3
diff --git a/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0.pipe.778 b/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0.pipe.778
index ccdd4033fc..dd67dde67b 100644
--- a/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0.pipe.778
+++ b/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0.pipe.778
@@ -1 +1 @@
-iscsi-mycluster_myname-secret
\ No newline at end of file
+iscsi-mycluster_myname-secret
diff --git a/tests/testutils.c b/tests/testutils.c
index b20e447b99..6ee78cca3c 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -582,6 +582,7 @@ virTestCompareToFileFull(const char *actual,
     g_autofree char *filecontent = NULL;
     g_autofree char *fixedcontent = NULL;
     const char *cmpcontent = actual;
+    size_t cmpcontentLen;
 
     if (!cmpcontent)
         cmpcontent = "";
@@ -594,16 +595,12 @@ virTestCompareToFileFull(const char *actual,
             return -1;
     }
 
-    if (filecontent) {
-        size_t filecontentLen = strlen(filecontent);
-        size_t cmpcontentLen = strlen(cmpcontent);
+    cmpcontentLen = strlen(cmpcontent);
 
-        if (filecontentLen > 0 &&
-            filecontent[filecontentLen - 1] == '\n' &&
-            (cmpcontentLen == 0 || cmpcontent[cmpcontentLen - 1] != '\n')) {
-            fixedcontent = g_strdup_printf("%s\n", cmpcontent);
-            cmpcontent = fixedcontent;
-        }
+    if (cmpcontentLen > 0 &&
+        cmpcontent[cmpcontentLen - 1] != '\n') {
+        fixedcontent = g_strdup_printf("%s\n", cmpcontent);
+        cmpcontent = fixedcontent;
     }
 
     if (STRNEQ_NULLABLE(cmpcontent, filecontent)) {
diff --git a/tests/virhostcpudata/linux-ppc64-deconf-cpus.signature b/tests/virhostcpudata/linux-ppc64-deconf-cpus.signature
index 7adf19db2f..f7c21761e0 100644
--- a/tests/virhostcpudata/linux-ppc64-deconf-cpus.signature
+++ b/tests/virhostcpudata/linux-ppc64-deconf-cpus.signature
@@ -1 +1 @@
-POWER8E (raw), altivec supported, rev 2.1 (pvr 004b 0201)
\ No newline at end of file
+POWER8E (raw), altivec supported, rev 2.1 (pvr 004b 0201)
diff --git a/tests/virhostcpudata/linux-ppc64-subcores1.signature b/tests/virhostcpudata/linux-ppc64-subcores1.signature
index 7adf19db2f..f7c21761e0 100644
--- a/tests/virhostcpudata/linux-ppc64-subcores1.signature
+++ b/tests/virhostcpudata/linux-ppc64-subcores1.signature
@@ -1 +1 @@
-POWER8E (raw), altivec supported, rev 2.1 (pvr 004b 0201)
\ No newline at end of file
+POWER8E (raw), altivec supported, rev 2.1 (pvr 004b 0201)
diff --git a/tests/virhostcpudata/linux-ppc64-subcores2.signature b/tests/virhostcpudata/linux-ppc64-subcores2.signature
index 7adf19db2f..f7c21761e0 100644
--- a/tests/virhostcpudata/linux-ppc64-subcores2.signature
+++ b/tests/virhostcpudata/linux-ppc64-subcores2.signature
@@ -1 +1 @@
-POWER8E (raw), altivec supported, rev 2.1 (pvr 004b 0201)
\ No newline at end of file
+POWER8E (raw), altivec supported, rev 2.1 (pvr 004b 0201)
diff --git a/tests/virhostcpudata/linux-ppc64-subcores3.signature b/tests/virhostcpudata/linux-ppc64-subcores3.signature
index 7adf19db2f..f7c21761e0 100644
--- a/tests/virhostcpudata/linux-ppc64-subcores3.signature
+++ b/tests/virhostcpudata/linux-ppc64-subcores3.signature
@@ -1 +1 @@
-POWER8E (raw), altivec supported, rev 2.1 (pvr 004b 0201)
\ No newline at end of file
+POWER8E (raw), altivec supported, rev 2.1 (pvr 004b 0201)
diff --git a/tests/virhostcpudata/linux-s390x-with-frequency.signature b/tests/virhostcpudata/linux-s390x-with-frequency.signature
index 70bb28a154..6c8ec5a05e 100644
--- a/tests/virhostcpudata/linux-s390x-with-frequency.signature
+++ b/tests/virhostcpudata/linux-s390x-with-frequency.signature
@@ -1 +1 @@
-IBM/S390, version = 00,  identification = 145F07,  machine = 2964, facilities: 0 1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 35 36 37 40 41 42 43 44 45 46 47 48 49 50 51 52 53 55 57 64 65 66 67 68 69 70 71 72 73 75 76 77 78 80 128 129 131 132 142 143
\ No newline at end of file
+IBM/S390, version = 00,  identification = 145F07,  machine = 2964, facilities: 0 1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 35 36 37 40 41 42 43 44 45 46 47 48 49 50 51 52 53 55 57 64 65 66 67 68 69 70 71 72 73 75 76 77 78 80 128 129 131 132 142 143
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux