# HG changeset patch # User David Demelier # Date 1464209039 -7200 # Node ID fcfa8ac395fde1d42f013fea15c7cbbb01f9f0bc # Parent af42e0c98f8b9af803d31cae13b36160ff6644ea Irccd: unbreak test-js-util diff -r af42e0c98f8b -r fcfa8ac395fd tests/js-util/empty.js diff -r af42e0c98f8b -r fcfa8ac395fd tests/js-util/main.cpp --- a/tests/js-util/main.cpp Wed May 25 22:42:20 2016 +0200 +++ b/tests/js-util/main.cpp Wed May 25 22:43:59 2016 +0200 @@ -18,62 +18,61 @@ #include -#include -#include +#include +#include +#include +#include +#include +#include using namespace irccd; -TEST(TestJsUtil, formatSimple) -{ - duk::Context ctx; +class TestJsUtil : public testing::Test { +protected: + Irccd m_irccd; + std::shared_ptr m_plugin; - loadJsIrccd(ctx); - loadJsUtil(ctx); + TestJsUtil() + : m_plugin(std::make_shared("empty", SOURCEDIR "/empty.js")) + { + m_irccd.moduleService().get("Irccd")->load(m_irccd, *m_plugin); + m_irccd.moduleService().get("Irccd.Util")->load(m_irccd, *m_plugin); + } +}; +TEST_F(TestJsUtil, formatSimple) +{ try { - auto ret = duk::pevalString(ctx, + auto ret = duk::pevalString(m_plugin->context(), "result = Irccd.Util.format(\"#{target}\", { target: \"markand\" })" ); - if (ret != 0) { - throw duk::error(ctx, -1); - } + if (ret != 0) + throw duk::error(m_plugin->context(), -1); } catch (const std::exception &ex) { FAIL() << ex.what(); } } -TEST(TestJsUtil, splituser) +TEST_F(TestJsUtil, splituser) { - duk::Context ctx; - - loadJsIrccd(ctx); - loadJsUtil(ctx); + try { + if (duk::pevalString(m_plugin->context(), "result = Irccd.Util.splituser(\"user!~user@hyper/super/host\");") != 0) + throw duk::error(m_plugin->context(), -1); - try { - if (duk::pevalString(ctx, "result = Irccd.Util.splituser(\"user!~user@hyper/super/host\");") != 0) { - throw duk::error(ctx, -1); - } - - ASSERT_EQ("user", duk::getGlobal(ctx, "result")); + ASSERT_EQ("user", duk::getGlobal(m_plugin->context(), "result")); } catch (const std::exception &ex) { FAIL() << ex.what(); } } -TEST(TestJsUtil, splithost) +TEST_F(TestJsUtil, splithost) { - duk::Context ctx; - - loadJsIrccd(ctx); - loadJsUtil(ctx); + try { + if (duk::pevalString(m_plugin->context(), "result = Irccd.Util.splithost(\"user!~user@hyper/super/host\");") != 0) + throw duk::error(m_plugin->context(), -1); - try { - if (duk::pevalString(ctx, "result = Irccd.Util.splithost(\"user!~user@hyper/super/host\");") != 0) { - throw duk::error(ctx, -1); - } - - ASSERT_EQ("!~user@hyper/super/host", duk::getGlobal(ctx, "result")); + ASSERT_EQ("!~user@hyper/super/host", duk::getGlobal(m_plugin->context(), "result")); } catch (const std::exception &ex) { FAIL() << ex.what(); }