2017-04-27 18:20:21 +08:00
|
|
|
#include "CppUnitTest.h"
|
|
|
|
#include "VcpkgCmdArguments.h"
|
|
|
|
|
2017-04-28 09:55:00 +08:00
|
|
|
#pragma comment(lib, "version")
|
|
|
|
#pragma comment(lib, "winhttp")
|
2017-04-27 10:21:40 +08:00
|
|
|
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
|
|
|
using namespace vcpkg;
|
|
|
|
|
|
|
|
namespace UnitTest1
|
|
|
|
{
|
2017-04-30 14:30:21 +08:00
|
|
|
class ArgumentTests : public TestClass<ArgumentTests>
|
2017-04-27 10:21:40 +08:00
|
|
|
{
|
|
|
|
TEST_METHOD(create_from_arg_sequence_options_lower)
|
|
|
|
{
|
2017-04-29 03:55:50 +08:00
|
|
|
std::vector<std::string> t = {"--vcpkg-root", "C:\\vcpkg", "--debug", "--sendmetrics", "--printmetrics"};
|
2017-04-27 10:21:40 +08:00
|
|
|
auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size());
|
2017-04-28 09:55:00 +08:00
|
|
|
Assert::AreEqual("C:\\vcpkg", v.vcpkg_root_dir.get()->c_str());
|
2017-04-29 08:27:07 +08:00
|
|
|
Assert::IsTrue(v.debug && *v.debug.get());
|
|
|
|
Assert::IsTrue(v.sendmetrics && v.sendmetrics.get());
|
|
|
|
Assert::IsTrue(v.printmetrics && *v.printmetrics.get());
|
2017-04-27 10:21:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(create_from_arg_sequence_options_upper)
|
|
|
|
{
|
2017-04-29 03:55:50 +08:00
|
|
|
std::vector<std::string> t = {"--VCPKG-ROOT", "C:\\vcpkg", "--DEBUG", "--SENDMETRICS", "--PRINTMETRICS"};
|
2017-04-27 10:21:40 +08:00
|
|
|
auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size());
|
2017-04-28 09:55:00 +08:00
|
|
|
Assert::AreEqual("C:\\vcpkg", v.vcpkg_root_dir.get()->c_str());
|
2017-04-29 08:27:07 +08:00
|
|
|
Assert::IsTrue(v.debug && *v.debug.get());
|
|
|
|
Assert::IsTrue(v.sendmetrics && v.sendmetrics.get());
|
|
|
|
Assert::IsTrue(v.printmetrics && *v.printmetrics.get());
|
2017-04-27 10:21:40 +08:00
|
|
|
}
|
2017-07-27 04:54:28 +08:00
|
|
|
|
|
|
|
TEST_METHOD(create_from_arg_sequence_valued_options)
|
|
|
|
{
|
|
|
|
std::vector<std::string> t = {"--a=b", "command", "argument"};
|
|
|
|
auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size());
|
|
|
|
auto opts = v.check_and_get_optional_command_arguments({}, {"--a"});
|
|
|
|
Assert::AreEqual("b", opts.settings["--a"].c_str());
|
|
|
|
Assert::AreEqual(size_t{1}, v.command_arguments.size());
|
|
|
|
Assert::AreEqual("argument", v.command_arguments[0].c_str());
|
|
|
|
Assert::AreEqual("command", v.command.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(create_from_arg_sequence_valued_options2)
|
|
|
|
{
|
|
|
|
std::vector<std::string> t = {"--a", "--b=c"};
|
|
|
|
auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size());
|
|
|
|
auto opts = v.check_and_get_optional_command_arguments({"--a", "--c"}, {"--b", "--d"});
|
|
|
|
Assert::AreEqual("c", opts.settings["--b"].c_str());
|
|
|
|
Assert::IsTrue(opts.settings.find("--d") == opts.settings.end());
|
|
|
|
Assert::IsTrue(opts.switches.find("--a") != opts.switches.end());
|
|
|
|
Assert::IsTrue(opts.settings.find("--c") == opts.settings.end());
|
|
|
|
Assert::AreEqual(size_t{0}, v.command_arguments.size());
|
|
|
|
}
|
2017-04-27 10:21:40 +08:00
|
|
|
};
|
2017-04-28 09:55:00 +08:00
|
|
|
}
|