From 9d320a7cdadb00fdbd7ac2244547460db086166c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Jan 2017 20:26:54 +0000 Subject: Use libtidy instead of messy shelling out to tidy --- gentoobrowse/src/Jamfile.jam | 2 ++ gentoobrowse/src/test.cpp | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/gentoobrowse/src/Jamfile.jam b/gentoobrowse/src/Jamfile.jam index 1e070a1..7276226 100644 --- a/gentoobrowse/src/Jamfile.jam +++ b/gentoobrowse/src/Jamfile.jam @@ -8,6 +8,7 @@ lib icespider-fcgi ; lib icespider-filesessions ; lib icespider-testing ; lib adhocutil ; +lib tidy ; lib Ice ; lib IceUtil ; lib pthread ; @@ -78,6 +79,7 @@ run ROOT=\"$(me)\" boost_filesystem gentoobrowse + tidy icespider-testing boost_unit_test_framework : gentoobrowse-test ; diff --git a/gentoobrowse/src/test.cpp b/gentoobrowse/src/test.cpp index 994a8df..af684cd 100644 --- a/gentoobrowse/src/test.cpp +++ b/gentoobrowse/src/test.cpp @@ -5,9 +5,14 @@ #include #include #include +#include using namespace IceSpider; +int streamGet(void * s) { return reinterpret_cast(s)->get(); } +void streamUnget(void * s, unsigned char ch) { reinterpret_cast(s)->putback(ch); } +Bool streamEof(void * s) { return reinterpret_cast(s)->eof() ? yes : no; } + class ChromiumRequest : public TestRequest { public: ChromiumRequest(const Core * c, HttpMethod m, const std::string & p) : @@ -29,12 +34,15 @@ class ChromiumRequest : public TestRequest { void validateHtml(const char * name) { - char buf[BUFSIZ]; - sprintf(buf, "tidy --indent yes --wrap 0 -quiet -output %s/%s.html", - binDir.c_str(), name); - FILE * tidy = popen(buf, "w"); - while (fwrite(buf, output.readsome(buf, BUFSIZ), 1, tidy) > 0) ; - BOOST_REQUIRE_EQUAL(0, pclose(tidy)); + TidyDoc tdoc = tidyCreate(); + TidyInputSource tis{ &output, &streamGet, &streamUnget, &streamEof }; + BOOST_REQUIRE_EQUAL(1, tidyOptSetBool(tdoc, TidyIndentContent, yes)); + BOOST_REQUIRE_EQUAL(1, tidyOptSetInt(tdoc, TidyWrapLen, 0)); + BOOST_REQUIRE_EQUAL(0, tidyParseSource(tdoc, &tis)); + 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); } }; -- cgit v1.2.3