From 91fb78a55829e71740ccee284ce20cc3476df519 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Jan 2017 21:47:16 +0000 Subject: Use libtidy instead of messy shelling out to tidy --- gentoobrowse-api/unittests/Jamfile.jam | 2 ++ gentoobrowse-api/unittests/testNotifications.cpp | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/gentoobrowse-api/unittests/Jamfile.jam b/gentoobrowse-api/unittests/Jamfile.jam index 200234f..1ecae8a 100644 --- a/gentoobrowse-api/unittests/Jamfile.jam +++ b/gentoobrowse-api/unittests/Jamfile.jam @@ -3,6 +3,7 @@ import testing ; lib boost_utf : : boost_unit_test_framework ; lib dbpp-postgresql : : : : /usr/include/dbpp-postgresql ; lib dl ; +lib tidy ; lib dryice : : : : /usr/include/icetray ; path-constant me : . ; @@ -108,6 +109,7 @@ run ../db/schema.sql BOOST_TEST_DYN_LINK testCommon + tidy testCommon : testNotifications ; diff --git a/gentoobrowse-api/unittests/testNotifications.cpp b/gentoobrowse-api/unittests/testNotifications.cpp index 15d62ea..8759e85 100644 --- a/gentoobrowse-api/unittests/testNotifications.cpp +++ b/gentoobrowse-api/unittests/testNotifications.cpp @@ -4,6 +4,7 @@ #include "mockDefs.h" #include #include +#include BOOST_GLOBAL_FIXTURE( Mail ); @@ -21,12 +22,14 @@ save(const std::string & name, Gentoo::EmailPtr e) std::ofstream text((binDir / (name + ".txt")).string()); text << e->body[0]->payload; - char buf[BUFSIZ]; - sprintf(buf, "tidy --indent yes --wrap 0 -quiet -output %s/%s.html", - binDir.c_str(), name.c_str()); - FILE * tidy = popen(buf, "w"); - BOOST_REQUIRE_EQUAL(1, fwrite(e->body[1]->payload.c_str(), e->body[1]->payload.length(), 1, tidy)); - BOOST_REQUIRE_EQUAL(0, pclose(tidy)); + TidyDoc tdoc = tidyCreate(); + BOOST_REQUIRE_EQUAL(1, tidyOptSetBool(tdoc, TidyIndentContent, yes)); + BOOST_REQUIRE_EQUAL(1, tidyOptSetInt(tdoc, TidyWrapLen, 0)); + BOOST_REQUIRE_EQUAL(0, tidyParseString(tdoc, e->body[1]->payload.c_str())); + BOOST_REQUIRE_EQUAL(0, tidyCleanAndRepair(tdoc)); + BOOST_REQUIRE_EQUAL(0, tidySaveFile(tdoc, (binDir / name).replace_extension(".html").c_str())); + BOOST_REQUIRE_EQUAL(0, tidyRunDiagnostics(tdoc)); + tidyRelease(tdoc); } void -- cgit v1.2.3