forked from EvergreenCrypto/docker-finance
container: root: common: utility: refactor/add tests
This commit is contained in:
@@ -102,9 +102,6 @@ struct ByteFixture
|
|||||||
struct CommonFixture
|
struct CommonFixture
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
using EErrorCode = ::TInterpreter::EErrorCode;
|
|
||||||
std::unique_ptr<EErrorCode> ecode;
|
|
||||||
CommonFixture() { ecode = std::make_unique<EErrorCode>(); }
|
|
||||||
};
|
};
|
||||||
} // namespace tests
|
} // namespace tests
|
||||||
} // namespace dfi
|
} // namespace dfi
|
||||||
|
|||||||
@@ -282,11 +282,64 @@ TEST_F(ByteTransform, unordered_set)
|
|||||||
ASSERT_EQ(byte.decode(two), one);
|
ASSERT_EQ(byte.decode(two), one);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief Common fixture (free functions)
|
||||||
|
//! \note Not a 'common' fixture but rather a fixture for 'common'
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
struct CommonFree : public ::testing::Test, public ::dfi::tests::CommonFixture
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(CommonFree, Line)
|
||||||
|
{
|
||||||
|
ASSERT_NO_THROW(common::line(""));
|
||||||
|
ASSERT_THROW(common::line("a bar without a foo"), type::RuntimeError);
|
||||||
|
ASSERT_NO_THROW(common::line("#define FOO 1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CommonFree, add_include_dir)
|
||||||
|
{
|
||||||
|
ASSERT_THROW(
|
||||||
|
common::add_include_dir("/should-not-exist"), type::RuntimeError);
|
||||||
|
ASSERT_NO_THROW(common::add_include_dir("/usr/include"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CommonFree, add_linked_lib)
|
||||||
|
{
|
||||||
|
ASSERT_THROW(
|
||||||
|
common::add_linked_lib("/should-not-exist.so"), type::RuntimeError);
|
||||||
|
ASSERT_NO_THROW(common::add_linked_lib("/usr/lib/LLVMgold.so"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CommonFree, remove_linked_lib)
|
||||||
|
{
|
||||||
|
ASSERT_THROW(
|
||||||
|
common::remove_linked_lib("/should-not-exist.so"), type::RuntimeError);
|
||||||
|
ASSERT_NO_THROW(common::add_linked_lib("/usr/lib/LLVMgold.so"));
|
||||||
|
ASSERT_NO_THROW(common::remove_linked_lib("/usr/lib/LLVMgold.so"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CommonFree, get_env)
|
||||||
|
{
|
||||||
|
ASSERT_THROW(common::get_env("should-not-exist"), type::RuntimeError);
|
||||||
|
ASSERT_NO_THROW(common::get_env("DOCKER_FINANCE_VERSION"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CommonFree, exec)
|
||||||
|
{
|
||||||
|
ASSERT_NE(common::exec("should-not-exist"), 0);
|
||||||
|
ASSERT_EQ(common::exec("pwd"), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CommonFree, make_timestamp)
|
||||||
|
{
|
||||||
|
ASSERT_EQ(common::make_timestamp().size(), 20);
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief Common fixture (raw files)
|
//! \brief Common fixture (raw files)
|
||||||
//! \note Not a 'common' fixture but rather a fixture for 'common'
|
//! \note Not a 'common' fixture but rather a fixture for 'common'
|
||||||
//! \since docker-finance 1.1.0
|
//! \since docker-finance 1.1.0
|
||||||
struct CommonRawFiles : public ::testing::Test,
|
struct CommonFreeFiles : public ::testing::Test,
|
||||||
public ::dfi::tests::CommonFixture
|
public ::dfi::tests::CommonFixture
|
||||||
{
|
{
|
||||||
std::string path_1, path_2;
|
std::string path_1, path_2;
|
||||||
|
|
||||||
@@ -325,107 +378,114 @@ struct CommonRawFiles : public ::testing::Test,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(CommonRawFiles, RawLoadSingle)
|
TEST_F(CommonFreeFiles, LoadSingle)
|
||||||
{
|
{
|
||||||
ASSERT_THROW(
|
ASSERT_THROW(common::load({path_1 + "should-not-exist"}), type::RuntimeError);
|
||||||
common::Command::load({path_1 + "should-not-exist"}), type::RuntimeError);
|
ASSERT_THROW(common::line("my_foo foo;"), type::RuntimeError);
|
||||||
gInterpreter->ProcessLine("my_foo foo;", ecode.get());
|
|
||||||
ASSERT_NE(ecode, nullptr);
|
|
||||||
EXPECT_NE(*ecode, EErrorCode::kNoError);
|
|
||||||
|
|
||||||
ASSERT_NO_THROW(common::Command::load(path_1));
|
ASSERT_NO_THROW(common::load(path_1));
|
||||||
gInterpreter->ProcessLine("my_foo foo;", ecode.get());
|
ASSERT_NO_THROW(common::line("my_foo foo;"));
|
||||||
ASSERT_NE(ecode, nullptr);
|
|
||||||
EXPECT_EQ(*ecode, EErrorCode::kNoError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CommonRawFiles, RawLoadMultiple)
|
TEST_F(CommonFreeFiles, LoadMultiple)
|
||||||
{
|
{
|
||||||
ASSERT_THROW(
|
ASSERT_THROW(
|
||||||
common::Command::load(
|
common::load(
|
||||||
{{path_1 + "should-not-exist"}, {path_2 + "nor-should-this"}}),
|
{{path_1 + "should-not-exist"}, {path_2 + "nor-should-this"}}),
|
||||||
type::RuntimeError);
|
type::RuntimeError);
|
||||||
gInterpreter->ProcessLine("my_bar bar;", ecode.get());
|
ASSERT_THROW(common::line("my_bar bar;"), type::RuntimeError);
|
||||||
ASSERT_NE(ecode, nullptr);
|
|
||||||
EXPECT_NE(*ecode, EErrorCode::kNoError);
|
|
||||||
|
|
||||||
ASSERT_NO_THROW(common::Command::load({path_1, path_2}));
|
ASSERT_NO_THROW(common::load({path_1, path_2}));
|
||||||
gInterpreter->ProcessLine("my_bar bar;", ecode.get());
|
ASSERT_NO_THROW(common::line("my_bar bar;"));
|
||||||
ASSERT_NE(ecode, nullptr);
|
|
||||||
EXPECT_EQ(*ecode, EErrorCode::kNoError);
|
|
||||||
}
|
}
|
||||||
// TODO(afiore): RawUnload
|
|
||||||
|
|
||||||
//! \brief Common fixture (repo files)
|
TEST_F(CommonFreeFiles, UnloadSingle)
|
||||||
//! \note Not a 'common' fixture but rather a fixture for 'common'
|
{
|
||||||
|
ASSERT_NO_THROW(common::load(path_1));
|
||||||
|
ASSERT_NO_THROW(common::line("my_foo foo;"));
|
||||||
|
|
||||||
|
ASSERT_NO_THROW(common::unload(path_1));
|
||||||
|
ASSERT_THROW(common::line("my_foo foo;"), type::RuntimeError);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CommonFreeFiles, UnloadMultiple)
|
||||||
|
{
|
||||||
|
ASSERT_NO_THROW(common::load({path_1, path_2}));
|
||||||
|
ASSERT_NO_THROW(common::line("my_foo foo;"));
|
||||||
|
ASSERT_NO_THROW(common::line("my_bar bar;"));
|
||||||
|
|
||||||
|
ASSERT_NO_THROW(common::unload({path_1, path_2}));
|
||||||
|
ASSERT_THROW(common::line("my_foo foo;"), type::RuntimeError);
|
||||||
|
ASSERT_THROW(common::line("my_bar bar;"), type::RuntimeError);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CommonFreeFiles, ReloadSingle)
|
||||||
|
{
|
||||||
|
ASSERT_NO_THROW(common::load(path_1));
|
||||||
|
ASSERT_NO_THROW(common::line("my_foo foo;"));
|
||||||
|
|
||||||
|
ASSERT_NO_THROW(common::reload(path_1));
|
||||||
|
ASSERT_NO_THROW(common::line("my_foo foo;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CommonFreeFiles, ReloadMultiple)
|
||||||
|
{
|
||||||
|
ASSERT_NO_THROW(common::load({path_1, path_2}));
|
||||||
|
ASSERT_NO_THROW(common::line("my_foo foo;"));
|
||||||
|
ASSERT_NO_THROW(common::line("my_bar bar;"));
|
||||||
|
|
||||||
|
ASSERT_NO_THROW(common::reload({path_1, path_2}));
|
||||||
|
ASSERT_NO_THROW(common::line("my_foo foo;"));
|
||||||
|
ASSERT_NO_THROW(common::line("my_bar bar;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief MacroFreeFiles fixture
|
||||||
//! \since docker-finance 1.1.0
|
//! \since docker-finance 1.1.0
|
||||||
struct CommonRepoFiles : public ::testing::Test,
|
//! \todo Move to Macro tests
|
||||||
public ::dfi::tests::CommonFixture
|
struct MacroFreeFiles : public ::testing::Test,
|
||||||
|
public ::dfi::tests::CommonFixture
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(CommonRepoFiles, MacroLoad)
|
TEST_F(MacroFreeFiles, LoadSingle)
|
||||||
{
|
{
|
||||||
ASSERT_THROW(
|
ASSERT_THROW(
|
||||||
::dfi::macro::load("macro/should-not/exist.C"), type::RuntimeError);
|
::dfi::macro::load("macro/should-not/exist.C"), type::RuntimeError);
|
||||||
gInterpreter->ProcessLine(
|
ASSERT_THROW(
|
||||||
"dfi::macro::common::crypto::botan::Hash h;", ecode.get());
|
common::line("dfi::macro::common::crypto::botan::Hash h;"),
|
||||||
ASSERT_NE(ecode, nullptr);
|
type::RuntimeError);
|
||||||
EXPECT_NE(*ecode, EErrorCode::kNoError);
|
|
||||||
|
|
||||||
// TODO(afiore): macro loading should not need to be prepended with "macro/"
|
// TODO(afiore): macro loading should not need to be prepended with "macro/"
|
||||||
// (see TODO in common impl regarding plugins-like functionality)
|
// (see TODO in common impl regarding plugins-like functionality)
|
||||||
ASSERT_NO_THROW(::dfi::macro::load("macro/crypto/hash.C"));
|
ASSERT_NO_THROW(::dfi::macro::load("macro/crypto/hash.C"));
|
||||||
gInterpreter->ProcessLine(
|
ASSERT_NO_THROW(common::line("dfi::macro::common::crypto::botan::Hash h;"));
|
||||||
"dfi::macro::common::crypto::botan::Hash h;", ecode.get());
|
|
||||||
ASSERT_NE(ecode, nullptr);
|
|
||||||
EXPECT_EQ(*ecode, EErrorCode::kNoError);
|
|
||||||
// TODO(afiore): multiple load
|
|
||||||
}
|
}
|
||||||
// TODO(afiore): MacroUnload
|
// TODO(afiore): multiple load
|
||||||
|
// TODO(afiore): unload, reload
|
||||||
|
|
||||||
TEST_F(CommonRepoFiles, PluginLoad)
|
//! \brief PluginFreeFiles fixture
|
||||||
|
//! \since docker-finance 1.1.0
|
||||||
|
//! \todo Move to Plugin tests
|
||||||
|
struct PluginFreeFiles : public ::testing::Test,
|
||||||
|
public ::dfi::tests::CommonFixture
|
||||||
|
{
|
||||||
|
// NOTE: custom plugin bind-mount is read-only
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(PluginFreeFiles, LoadSingle)
|
||||||
{
|
{
|
||||||
ASSERT_THROW(
|
ASSERT_THROW(
|
||||||
::dfi::plugin::load("repo/should-not/exist.cc"), type::RuntimeError);
|
::dfi::plugin::load("repo/should-not/exist.cc"), type::RuntimeError);
|
||||||
gInterpreter->ProcessLine(
|
ASSERT_THROW(
|
||||||
"dfi::plugin::my_plugin_namespace::example2();", ecode.get());
|
common::line("dfi::plugin::my_plugin_namespace::example2();"),
|
||||||
ASSERT_NE(ecode, nullptr);
|
type::RuntimeError);
|
||||||
EXPECT_NE(*ecode, EErrorCode::kNoError);
|
|
||||||
|
|
||||||
ASSERT_NO_THROW(::dfi::plugin::load("repo/example.cc"));
|
ASSERT_NO_THROW(::dfi::plugin::load("repo/example.cc"));
|
||||||
gInterpreter->ProcessLine(
|
ASSERT_NO_THROW(
|
||||||
"dfi::plugin::my_plugin_namespace::example2();", ecode.get());
|
common::line("dfi::plugin::my_plugin_namespace::example2();"));
|
||||||
ASSERT_NE(ecode, nullptr);
|
|
||||||
EXPECT_EQ(*ecode, EErrorCode::kNoError);
|
|
||||||
|
|
||||||
// TODO(afiore): multiple load
|
|
||||||
}
|
|
||||||
// TODO(afiore): PluginUnload
|
|
||||||
|
|
||||||
//! \brief Common fixture (free functions)
|
|
||||||
//! \note Not a 'common' fixture but rather a fixture for 'common'
|
|
||||||
//! \since docker-finance 1.1.0
|
|
||||||
struct CommonFree : public ::testing::Test, public ::dfi::tests::CommonFixture
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(CommonFree, env)
|
|
||||||
{
|
|
||||||
ASSERT_THROW(common::get_env("should-not-exist"), type::RuntimeError);
|
|
||||||
ASSERT_NO_THROW(common::get_env("DOCKER_FINANCE_VERSION"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(CommonFree, exec)
|
|
||||||
{
|
|
||||||
ASSERT_NE(common::exec("should-not-exist"), 0);
|
|
||||||
ASSERT_EQ(common::exec("pwd"), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(CommonFree, make_timestamp)
|
|
||||||
{
|
|
||||||
ASSERT_EQ(common::make_timestamp().size(), 20);
|
|
||||||
}
|
}
|
||||||
|
// TODO(afiore): multiple load
|
||||||
|
// TODO(afiore): unload, reload
|
||||||
|
|
||||||
} // namespace unit
|
} // namespace unit
|
||||||
} // namespace tests
|
} // namespace tests
|
||||||
|
|||||||
Reference in New Issue
Block a user