mirror of
https://github.com/meganz/MEGAcmd
synced 2025-08-30 21:35:10 +00:00
Use gmock matchers for more idiomatic assertions/expectations.
This commit is contained in:
@@ -38,13 +38,13 @@ TEST_F(NOINTERACTIVEReadTest, Find)
|
||||
auto r = executeInClient({"find"});
|
||||
|
||||
std::vector<std::string> result_paths = splitByNewline(r.out());
|
||||
ASSERT_FALSE(result_paths.empty());
|
||||
ASSERT_THAT(result_paths, testing::Not(testing::IsEmpty()));
|
||||
|
||||
EXPECT_CONTAINS(result_paths, ".");
|
||||
EXPECT_CONTAINS(result_paths, "testReadingFolder01");
|
||||
EXPECT_CONTAINS(result_paths, "testReadingFolder01/file03.txt");
|
||||
EXPECT_CONTAINS(result_paths, "testReadingFolder01/folder01/file03.txt");
|
||||
EXPECT_CONTAINS(result_paths, "testReadingFolder01/folder02/subfolder03/file02.txt");
|
||||
EXPECT_THAT(result_paths, testing::Contains("."));
|
||||
EXPECT_THAT(result_paths, testing::Contains("testReadingFolder01"));
|
||||
EXPECT_THAT(result_paths, testing::Contains("testReadingFolder01/file03.txt"));
|
||||
EXPECT_THAT(result_paths, testing::Contains("testReadingFolder01/folder01/file03.txt"));
|
||||
EXPECT_THAT(result_paths, testing::Contains("testReadingFolder01/folder02/subfolder03/file02.txt"));
|
||||
}
|
||||
|
||||
TEST_F(NOINTERACTIVELoggedInTest, Whoami)
|
||||
|
@@ -13,6 +13,8 @@
|
||||
* program.
|
||||
*/
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "MegaCmdTestingTools.h"
|
||||
|
||||
std::vector<std::string> splitByNewline(const std::string& str)
|
||||
@@ -57,14 +59,16 @@ void ensureLoggedIn()
|
||||
const char* user = getenv("MEGACMD_TEST_USER");
|
||||
const char* pass = getenv("MEGACMD_TEST_PASS");
|
||||
|
||||
if (!user || !pass)
|
||||
{
|
||||
std::cerr << "ENSURE MEGACMD_TEST_USER and MEGACMD_TEST_PASS are set!" << std::endl;
|
||||
ASSERT_FALSE("MISSING USER/PASS env variables");
|
||||
}
|
||||
ASSERT_THAT(user, testing::AllOf(testing::NotNull(), testing::Not(testing::IsEmpty()))) << "Missing testing user env variable. Ensure that MEGACMD_TEST_USER is set!";
|
||||
ASSERT_THAT(user, testing::AllOf(testing::NotNull(), testing::Not(testing::IsEmpty())))
|
||||
<< "Missing testing user password env variable. Ensure that MEGACMD_TEST_PASS is set!";
|
||||
|
||||
auto result = executeInClient({"login", user, pass});
|
||||
ASSERT_EQ(0, result.status());
|
||||
|
||||
result = executeInClient({"whoami"});
|
||||
ASSERT_EQ(0, result.status());
|
||||
ASSERT_THAT(result.out(), testing::HasSubstr(user));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,31 +27,6 @@
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
|
||||
template<typename C, typename I>
|
||||
testing::AssertionResult AssertContains(const char* container_expr, const char* item_expr, C container, I item)
|
||||
{
|
||||
if (std::find(container.begin(), container.end(), item) != container.end())
|
||||
{
|
||||
return testing::AssertionSuccess();
|
||||
}
|
||||
return testing::AssertionFailure() << "`" << container_expr << "` does not contain item " << item_expr;
|
||||
}
|
||||
|
||||
template<typename C, typename I>
|
||||
testing::AssertionResult AssertNotContains(const char* container_expr, const char* item_expr, C container, I item)
|
||||
{
|
||||
if (std::find(container.begin(), container.end(), item) == container.end())
|
||||
{
|
||||
return testing::AssertionSuccess();
|
||||
}
|
||||
return testing::AssertionFailure() << "`" << container_expr << "` contains item " << item_expr;
|
||||
}
|
||||
|
||||
#define ASSERT_CONTAINS(container, item) ASSERT_PRED_FORMAT2(AssertContains, container, item)
|
||||
#define ASSERT_NCONTAINS(container, item) ASSERT_PRED_FORMAT2(AssertNotContains, container, item)
|
||||
#define EXPECT_CONTAINS(container, item) EXPECT_PRED_FORMAT2(AssertContains, container, item)
|
||||
#define EXPECT_NCONTAINS(container, item) EXPECT_PRED_FORMAT2(AssertNotContains, container, item)
|
||||
|
||||
std::vector<std::string> splitByNewline(const std::string& str);
|
||||
|
||||
class ClientResponse
|
||||
|
Reference in New Issue
Block a user