From 1c8086948ef27af0e8592e264fe06f09492d543c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Jul 2015 18:37:50 +0100 Subject: Replace system(diff..) with a function --- slicer/test/helpers.cpp | 15 +++++++++++++++ slicer/test/helpers.h | 3 +++ slicer/test/serializers.cpp | 7 +++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/slicer/test/helpers.cpp b/slicer/test/helpers.cpp index 5527f5a..58f47bc 100644 --- a/slicer/test/helpers.cpp +++ b/slicer/test/helpers.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include void system(const std::string & cmd) @@ -12,6 +14,19 @@ system(const std::string & cmd) } } +void +diff(const boost::filesystem::path & left, const boost::filesystem::path & right) +{ + std::ifstream fl(left.string()); + std::ifstream fr(right.string()); + + std::string l, r; + std::copy_if(std::istreambuf_iterator(fl), std::istreambuf_iterator(), back_inserter(l), [](char x){ return !isspace(x); }); + std::copy_if(std::istreambuf_iterator(fr), std::istreambuf_iterator(), back_inserter(r), [](char x){ return !isspace(x); }); + + BOOST_REQUIRE_EQUAL(l, r); +} + void * loadlib(const boost::filesystem::path & so) { diff --git a/slicer/test/helpers.h b/slicer/test/helpers.h index f8f7a7d..385ee64 100644 --- a/slicer/test/helpers.h +++ b/slicer/test/helpers.h @@ -14,5 +14,8 @@ loadlib(const boost::filesystem::path &); void closelib(void *); +void +diff(const boost::filesystem::path & left, const boost::filesystem::path & right); + #endif diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp index df6c052..89e7d8d 100644 --- a/slicer/test/serializers.cpp +++ b/slicer/test/serializers.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include "helpers.h" #include "fileStructure.h" @@ -54,7 +53,7 @@ class FileBased : public FileStructure { } BOOST_TEST_CHECKPOINT("Checksum: " << input << " === " << output); - system(stringbf("diff -w %s %s", input, output)); + diff(input, output); } template @@ -96,7 +95,7 @@ class FileBased : public FileStructure { ifree(docWrite); BOOST_TEST_CHECKPOINT("Checksum: " << input << " === " << output); - system(stringbf("diff -w %s %s", input, output)); + diff(input, output); } }; @@ -435,7 +434,7 @@ BOOST_AUTO_TEST_CASE( any ) Slicer::Serialize(object, output); BOOST_TEST_CHECKPOINT("Checksum: " << input << " === " << output); - system(stringbf("diff -w %s %s", input, output)); + diff(input, output); } BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3