]> granicus.if.org Git - graphviz/commitdiff
add a test case for a GVPR bug
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 16 Oct 2021 20:23:31 +0000 (13:23 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 19 Oct 2021 14:46:14 +0000 (07:46 -0700)
Related to #2138.

rtest/2138.gvpr [new file with mode: 0644]
rtest/test_regression.py

diff --git a/rtest/2138.gvpr b/rtest/2138.gvpr
new file mode 100644 (file)
index 0000000..a5f07a0
--- /dev/null
@@ -0,0 +1,43 @@
+BEGIN{
+  int i, j, l, cnt;
+  string POS, st, tst, tok[int];
+
+  void tstStuff(string inStr){
+    print ("//  tok array count: ",cnt);
+    for (i=0;i<cnt;i++){
+      print("// tok[",i,"]    >>",tok[i],"<<   should NOT include trailing spaces or junk chars");
+      st=tok[i];
+      //st=sub(tok[i],"[        ]"); // remove tabs and spaces !!
+      l=length(st);
+      print("// length (st) : ",l);
+      j=index(st," ");
+      print("// index of space (st) : ", j, "   << must NOT be less than -1");
+      st=sub(st,"[      ]");
+      print ("// st   >>",st,"<<");
+      l=length(st);
+      print("// length (st) : ",l);
+      print("//");
+    }
+   }
+   
+  tst=" abc def   ghijk 3456789 012  ";
+  print("\n*****", tst, "******");
+  print("*********  space delimiter  *****************");  
+  print("*********  split results  *****************");
+  cnt=split(tst, tok );
+  tstStuff();
+  print("\n*********  tokens results  ***************");
+  cnt=tokens(tst, tok );
+  tstStuff();
+
+  tst="^abc^def^^^ghijk^3456789^012^^^";
+  print("\n*****", tst, "******");
+  print("*********  ^ delimiter  *****************");
+  print("*********  split results  *****************");
+  cnt=split(tst, tok,"^" );
+  tstStuff();
+  print("\n*********  tokens results  ***************");
+  cnt=tokens(tst, tok, "^" );
+  tstStuff();
+}
index 6b4ac674d375fa53e5ce9ab6727bc7a31ed76988..2fb0098e763c6a807b298b40e0d8c9568d12e311 100644 (file)
@@ -1248,6 +1248,45 @@ def test_2131():
 
   assert p.returncode == 0, "gv2gml rejected a basic graph"
 
+@pytest.mark.skipif(shutil.which("gvpr") is None,
+                    reason="gvpr not available")
+@pytest.mark.parametrize("examine", ("indices", "tokens"))
+@pytest.mark.xfail(strict=True)
+def test_2138(examine: str):
+  """
+  gvpr splitting and tokenizing should not result in trailing garbage
+  https://gitlab.com/graphviz/graphviz/-/issues/2138
+  """
+
+  # find our co-located GVPR program
+  script = (Path(__file__).parent / "2138.gvpr").resolve()
+  assert script.exists(), "missing test case"
+
+  # run it with NUL input
+  out = subprocess.check_output(["gvpr", "-f", script],
+                                stdin=subprocess.DEVNULL)
+
+  # Decode into text. We do this instead of `universal_newlines=True` above
+  # because the trailing garbage can contain invalid UTF-8 data causing cryptic
+  # failures. We want to correctly surface this as trailing garbage, not an
+  # obscure UTF-8 decoding error.
+  result = out.decode("utf-8", "replace")
+
+  if examine == "indices":
+    # check no indices are miscalculated
+    index_re = r"^// index of space \(st\) :\s*(?P<index>-?\d+)\s*<< must " \
+               r"NOT be less than -1$"
+    for m in re.finditer(index_re, result, flags=re.MULTILINE):
+      index = int(m.group("index"))
+      assert index >= -1, "illegal index computed"
+
+  if examine == "tokens":
+    # check for text the author of 2138.gvpr expected to find
+    assert "// tok[3]    >>3456789<<   should NOT include trailing spaces or " \
+      "junk chars" in result, "token 3456789 not found or has trailing garbage"
+    assert "// tok[7]    >>012<<   should NOT include trailing spaces or "     \
+      "junk chars" in result, "token 012 not found or has trailing garbage"
+
 def test_package_version():
   """
   The graphviz_version.h header should define a non-empty PACKAGE_VERSION