mirror of
https://github.com/meganz/MEGAcmd
synced 2025-09-01 06:15:09 +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"});
|
auto r = executeInClient({"find"});
|
||||||
|
|
||||||
std::vector<std::string> result_paths = splitByNewline(r.out());
|
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_THAT(result_paths, testing::Contains("."));
|
||||||
EXPECT_CONTAINS(result_paths, "testReadingFolder01");
|
EXPECT_THAT(result_paths, testing::Contains("testReadingFolder01"));
|
||||||
EXPECT_CONTAINS(result_paths, "testReadingFolder01/file03.txt");
|
EXPECT_THAT(result_paths, testing::Contains("testReadingFolder01/file03.txt"));
|
||||||
EXPECT_CONTAINS(result_paths, "testReadingFolder01/folder01/file03.txt");
|
EXPECT_THAT(result_paths, testing::Contains("testReadingFolder01/folder01/file03.txt"));
|
||||||
EXPECT_CONTAINS(result_paths, "testReadingFolder01/folder02/subfolder03/file02.txt");
|
EXPECT_THAT(result_paths, testing::Contains("testReadingFolder01/folder02/subfolder03/file02.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(NOINTERACTIVELoggedInTest, Whoami)
|
TEST_F(NOINTERACTIVELoggedInTest, Whoami)
|
||||||
|
@@ -13,6 +13,8 @@
|
|||||||
* program.
|
* program.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
#include "MegaCmdTestingTools.h"
|
#include "MegaCmdTestingTools.h"
|
||||||
|
|
||||||
std::vector<std::string> splitByNewline(const std::string& str)
|
std::vector<std::string> splitByNewline(const std::string& str)
|
||||||
@@ -57,14 +59,16 @@ void ensureLoggedIn()
|
|||||||
const char* user = getenv("MEGACMD_TEST_USER");
|
const char* user = getenv("MEGACMD_TEST_USER");
|
||||||
const char* pass = getenv("MEGACMD_TEST_PASS");
|
const char* pass = getenv("MEGACMD_TEST_PASS");
|
||||||
|
|
||||||
if (!user || !pass)
|
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())))
|
||||||
std::cerr << "ENSURE MEGACMD_TEST_USER and MEGACMD_TEST_PASS are set!" << std::endl;
|
<< "Missing testing user password env variable. Ensure that MEGACMD_TEST_PASS is set!";
|
||||||
ASSERT_FALSE("MISSING USER/PASS env variables");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto result = executeInClient({"login", user, pass});
|
auto result = executeInClient({"login", user, pass});
|
||||||
ASSERT_EQ(0, result.status());
|
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 <chrono>
|
||||||
#include <future>
|
#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);
|
std::vector<std::string> splitByNewline(const std::string& str);
|
||||||
|
|
||||||
class ClientResponse
|
class ClientResponse
|
||||||
|
Reference in New Issue
Block a user