From e4b5c5482f08f52dc3b962cfacd48623fa804e01 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Mar 2017 15:13:51 +0000 Subject: Test, fix and remove debug around git operation function name retrieval --- gentoobrowse-api/service/utils/git.cpp | 3 ++- gentoobrowse-api/service/utils/git.h | 2 +- gentoobrowse-api/unittests/Jamfile.jam | 8 ++++++++ gentoobrowse-api/unittests/testUtils.cpp | 23 +++++++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 gentoobrowse-api/unittests/testUtils.cpp diff --git a/gentoobrowse-api/service/utils/git.cpp b/gentoobrowse-api/service/utils/git.cpp index 1dd3653..bbd69a3 100644 --- a/gentoobrowse-api/service/utils/git.cpp +++ b/gentoobrowse-api/service/utils/git.cpp @@ -10,8 +10,9 @@ namespace Gentoo { throwError(void * const func, int err) { const git_error * e = giterr_last(); - fprintf(stderr, "func %p\n", func); char ** fn = backtrace_symbols(&func, 1); + assert(fn); + assert(*fn); throw ::Gentoo::GitError(*fn, err, e->klass, e->message); } diff --git a/gentoobrowse-api/service/utils/git.h b/gentoobrowse-api/service/utils/git.h index 7df0172..6900435 100644 --- a/gentoobrowse-api/service/utils/git.h +++ b/gentoobrowse-api/service/utils/git.h @@ -11,7 +11,7 @@ namespace Gentoo { gitSafe(int (*func)(P...), A ... p) { if (int _giterror = func(p...) < 0) { - throwError(&func, _giterror); + throwError((void * const)func, _giterror); } } diff --git a/gentoobrowse-api/unittests/Jamfile.jam b/gentoobrowse-api/unittests/Jamfile.jam index 558d7d9..9f60eb4 100644 --- a/gentoobrowse-api/unittests/Jamfile.jam +++ b/gentoobrowse-api/unittests/Jamfile.jam @@ -46,6 +46,14 @@ lib testCommon : ROOT=\"$(me)\" ; +run + testUtils.cpp ../service/utils/git.cpp + : : : + BOOST_TEST_DYN_LINK + testCommon + git2 + : testUtils ; + run testDepend.cpp ../service/depend.cpp : : : diff --git a/gentoobrowse-api/unittests/testUtils.cpp b/gentoobrowse-api/unittests/testUtils.cpp new file mode 100644 index 0000000..e89f0fb --- /dev/null +++ b/gentoobrowse-api/unittests/testUtils.cpp @@ -0,0 +1,23 @@ +#define BOOST_TEST_MODULE TestDepend +#include + +#include +#include + +using namespace Gentoo::Utils::Git; + +BOOST_AUTO_TEST_CASE( gitErrorMessage ) +{ + try { + gitSafeGet(git_repository_open_ext, git_repository_free, "/", 0, nullptr); + } + catch (const Gentoo::GitError & ge) { + BOOST_TEST_CONTEXT(ge.what()) { + BOOST_REQUIRE_EQUAL(ge.errorCode, 1); + BOOST_REQUIRE_EQUAL(ge.errorClass, 6); + BOOST_REQUIRE(ge.operation.find("git_repository_open_ext") + 1); + BOOST_REQUIRE(ge.message.find("repository") + 1); + } + } +} + -- cgit v1.2.3