|
|
@@ -9,6 +9,8 @@
|
|
|
|
|
|
#include "xcode_gtest_helper.h"
|
|
|
|
|
|
+using testing::NotNull;
|
|
|
+
|
|
|
namespace program {
|
|
|
struct ArgumentTestHelper {
|
|
|
template <typename Impl> bool has_main(Impl const & args) const {
|
|
|
@@ -24,11 +26,11 @@ template <typename T, size_t N> static T parse(char const * const (&argv)[N]) {
|
|
|
return T(N, argv);
|
|
|
}
|
|
|
|
|
|
-std::string g_type_name;
|
|
|
+program::detail::Any g_action;
|
|
|
|
|
|
template <typename Args, typename Action>
|
|
|
-int typed_main(Args const &, Action const &) {
|
|
|
- g_type_name = typeid(Action).name();
|
|
|
+int typed_main(Args const &, Action const & action) {
|
|
|
+ g_action = program::detail::Any(&action);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -42,6 +44,15 @@ struct Commit : program::Arguments<Commit> {
|
|
|
std::string message = option("message", 'm');
|
|
|
};
|
|
|
|
|
|
+class Push : public program::Arguments<Push> {
|
|
|
+public:
|
|
|
+ using Arguments::Arguments;
|
|
|
+ std::string remote = argument(0, "repository") = PROGRAM_DEFER(_remote());
|
|
|
+
|
|
|
+private:
|
|
|
+ std::string _remote() const;
|
|
|
+};
|
|
|
+
|
|
|
struct Bad1 : program::Arguments<Bad1> {
|
|
|
using Arguments::Arguments;
|
|
|
|
|
|
@@ -56,15 +67,24 @@ struct Bad2 : program::Arguments<Bad2> {
|
|
|
Commit commit = action("commit");
|
|
|
};
|
|
|
|
|
|
-struct Git : program::Arguments<Git> {
|
|
|
+class Git : program::Arguments<Git> {
|
|
|
+public:
|
|
|
using Arguments::Arguments;
|
|
|
|
|
|
+ std::string pwd = option('C');
|
|
|
bool verbose = flag("verbose", 'v');
|
|
|
|
|
|
+private:
|
|
|
Commit commit = action("commit");
|
|
|
Checkout checkout = action("checkout");
|
|
|
+ Push push = action("push");
|
|
|
};
|
|
|
|
|
|
+std::string Push::_remote() const {
|
|
|
+ if (Git const * git = Arguments::parent<Git>()) { return git->pwd; }
|
|
|
+ return "";
|
|
|
+}
|
|
|
+
|
|
|
TEST(ActionTest, CannotMixActionAndArgument) {
|
|
|
EXPECT_THROW(Bad1(), program::ArgumentMixingError);
|
|
|
EXPECT_THROW(Bad2(), program::ArgumentMixingError);
|
|
|
@@ -77,5 +97,16 @@ TEST(ActionTest, ActionIsRouted) {
|
|
|
program::ArgumentTestHelper helper;
|
|
|
EXPECT_TRUE(helper.has_main(git));
|
|
|
helper.main(git);
|
|
|
- EXPECT_THAT(g_type_name, typeid(Commit).name());
|
|
|
+ EXPECT_THAT(g_action.get<Commit>(), NotNull());
|
|
|
+ EXPECT_THAT(g_action.get<Commit>()->message, "this is a message");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ActionTest, CanFetchParentInfo) {
|
|
|
+ Git git = parse<Git>({"", "-C", "./submodules/X", "push"});
|
|
|
+ program::ArgumentTestHelper helper;
|
|
|
+ EXPECT_TRUE(helper.has_main(git));
|
|
|
+ helper.main(git);
|
|
|
+
|
|
|
+ EXPECT_THAT(g_action.get<Push>(), NotNull());
|
|
|
+ EXPECT_THAT(g_action.get<Push>()->remote, "./submodules/X");
|
|
|
}
|