| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- //
- // cli_test.cxx
- // cli-test
- //
- // Created by Sam Jaffe on 10/9/20.
- // Copyright © 2020 Sam Jaffe. All rights reserved.
- //
- #include "cli/cli.h"
- #include <gmock/gmock.h>
- #include <gtest/gtest.h>
- #if XCODE_UNIT_TEST
- // This is a hack to allow XCode to properly display failures when running
- // unit tests.
- #undef EXPECT_THAT
- #define EXPECT_THAT ASSERT_THAT
- #undef EXPECT_THROW
- #define EXPECT_THROW ASSERT_THROW
- #undef EXPECT_TRUE
- #define EXPECT_TRUE ASSERT_TRUE
- #undef EXPECT_FALSE
- #define EXPECT_FALSE ASSERT_FALSE
- #endif
- TEST(CliTest, EndsOnQuit) {
- std::stringstream input{R"(quit)"};
- cli::cli(input).run();
- }
- TEST(CliTest, CanInputNoArgsCommand) {
- bool was_hit{false};
- std::stringstream input{R"(act)"};
- cli::cli(input).register_callback("act", [&](){ was_hit = true; }).run();
- EXPECT_TRUE(was_hit);
- }
- TEST(CliTest, WillSkipCallbackIfNotEnoughArgs) {
- bool was_hit{false};
- std::stringstream input{R"(act)"};
- cli::cli(input).register_callback("act", [&](int){ was_hit = true; }).run();
- EXPECT_FALSE(was_hit);
- }
- struct example {};
- void cli_print(example const &) { throw example{}; }
- TEST(CliTest, QueryInvokesADLFunction) {
- std::stringstream input{R"(query)"};
- auto func = [](){ return example{}; };
- EXPECT_THROW(cli::cli(input).register_query("query", func).run(), example);
- }
|