diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-16 20:26:54 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-16 21:47:53 +0000 |
commit | 9d320a7cdadb00fdbd7ac2244547460db086166c (patch) | |
tree | 94149e7f7d403863313589adf60dfeff988d3b9b | |
parent | Add basic icespider tests and check core pages with tidy (diff) | |
download | gentoobrowse-9d320a7cdadb00fdbd7ac2244547460db086166c.tar.bz2 gentoobrowse-9d320a7cdadb00fdbd7ac2244547460db086166c.tar.xz gentoobrowse-9d320a7cdadb00fdbd7ac2244547460db086166c.zip |
Use libtidy instead of messy shelling out to tidy
-rw-r--r-- | gentoobrowse/src/Jamfile.jam | 2 | ||||
-rw-r--r-- | 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 <define>ROOT=\"$(me)\" <library>boost_filesystem <library>gentoobrowse + <library>tidy <library>icespider-testing <library>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 <definedDirs.h> #include <boost/filesystem/operations.hpp> #include <testRequest.h> +#include <tidy.h> using namespace IceSpider; +int streamGet(void * s) { return reinterpret_cast<std::istream *>(s)->get(); } +void streamUnget(void * s, unsigned char ch) { reinterpret_cast<std::istream *>(s)->putback(ch); } +Bool streamEof(void * s) { return reinterpret_cast<std::istream *>(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); } }; |