datasheet-test: Fix printing of string values in error messages.
[pspp-builds.git] / tests / data / datasheet-test.c
index 194f9223a00396801647f3372b4cd43d1ad0dce4..56c8d26e44dbb74c02eb6838ffc0598b12b0717b 100644 (file)
@@ -188,14 +188,6 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
   assert (n_rows < MAX_ROWS);
   assert (n_columns < MAX_COLS);
 
-  /* If it is a duplicate hash, discard the state before checking
-     its consistency, to save time. */
-  if (mc_discard_dup_state (mc, hash_datasheet (ds)))
-    {
-      datasheet_destroy (ds);
-      return;
-    }
-
   /* Check contents of datasheet via datasheet functions. */
   if (!check_caseproto (mc, proto, datasheet_get_proto (ds), "datasheet"))
     {
@@ -266,11 +258,16 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
               ds_put_format (&s, "row %zu:", row);
               for (col = 0; col < n_columns; col++)
                 {
+                  int width = caseproto_get_width (proto, col);
                   union value v;
-                  value_init (&v, 0);
+                  value_init (&v, width);
                   if (!datasheet_get_value (ds, row, col, &v))
                     NOT_REACHED ();
-                  ds_put_format (&s, " %g", v.f);
+                  if (width == 0)
+                    ds_put_format (&s, " %g", v.f);
+                  else
+                    ds_put_format (&s, " '%.*s'",
+                                   width, value_str (&v, width));
                 }
               mc_error (mc, "%s", ds_cstr (&s));
             }
@@ -316,7 +313,10 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
                   "have been (size %zu,%zu)", n_rows, n_columns);
     }
 
-  mc_add_state (mc, ds);
+  if (mc_discard_dup_state (mc, hash_datasheet (ds)))
+    datasheet_destroy (ds);
+  else
+    mc_add_state (mc, ds);
 }
 
 /* Extracts the contents of DS into DATA. */