[gxml] * figured out how to neatly run outside processes synchronously for testing, yay



commit acf1993847067f97b7d094fde34df2e3f27e21ee
Author: Richard Schwarting <aquarichy gmail com>
Date:   Mon Jul 25 18:35:44 2011 -0400

    * figured out how to neatly run outside processes synchronously for testing, yay

 test/DocumentTest.vala |   13 ++++++++++---
 wscript                |    2 ++
 2 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/test/DocumentTest.vala b/test/DocumentTest.vala
index 1f29d78..3cb2713 100644
--- a/test/DocumentTest.vala
+++ b/test/DocumentTest.vala
@@ -57,7 +57,8 @@ class DocumentTest : GXmlTest {
 		Test.add_func ("/gxml/document/construct_for_stream", () => {
 				try {
 					File fin = File.new_for_path ("test.xml");
-					InputStream instream = fin.read (null); // TODO use cancellable
+					InputStream instream = fin.read (null);
+					// TODO use cancellable
 
 					Document doc = new Document.for_stream (instream);
 
@@ -85,7 +86,11 @@ class DocumentTest : GXmlTest {
 		Test.add_func ("/gxml/document/save", () => {
 				try {
 					Document doc = get_doc ();
+					int exit_status;
 					doc.save_to_path ("test_out_path.xml");
+
+					Process.spawn_sync (null,  { "/usr/bin/diff", "test_out_path.xml", "test_out_path_expected.xml" }, null, 0, null, null /* stdout */, null /* stderr */, out exit_status);
+					assert (exit_status == 0);
 				} catch (GLib.Error e) {
 					GLib.warning ("%s", e.message);
 					assert (false);
@@ -101,10 +106,12 @@ class DocumentTest : GXmlTest {
 					OutputStream outstream = fout.replace (null, true, FileCreateFlags.REPLACE_DESTINATION, null);
 
 					Document doc = new Document.for_stream (instream);
+					int exit_status;
+
 					doc.save_to_stream (outstream);
 
-					GLib.message ("stub");
-					// TODO: figure out how to diff test.xml and test_out.xml
+					Process.spawn_sync (null,  { "/usr/bin/diff", "test_out_stream.xml", "test_out_stream_expected.xml" }, null, 0, null, null /* stdout */, null /* stderr */, out exit_status);
+					assert (exit_status == 0);
 				} catch (GLib.Error e) {
 					GLib.warning ("%s", e.message);
 					assert (false);
diff --git a/wscript b/wscript
index 9b347a1..81e956d 100644
--- a/wscript
+++ b/wscript
@@ -34,6 +34,8 @@ def build(bld):
     bld.recurse('gxml test')
     bld(source="gxml.pc.in", install_path="${LIBDIR}/pkgconfig/", SHORTVERSION=SHORTVERSION, VERSION=VERSION)
     bld(rule="cp ${SRC} ${TGT}", source="test/test.xml", target="build/test/")
+    bld(rule="cp ${SRC} ${TGT}", source="test/test_out_path_expected.xml", target="build/test/")
+    bld(rule="cp ${SRC} ${TGT}", source="test/test_out_stream_expected.xml", target="build/test/")
     bld(rule="rm -rf doc; valadoc --package-name=" + APPNAME + " --package-version=" + VERSION + " --pkg libxml-2.0 --pkg gio-2.0 --pkg gee-1.0 ../gxml/*.vala -o doc");
 
     ## want to call valadoc, but TypeError encountered by WAF, sigh



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