Esempio n. 1
0
void ArgumentsTest::disallowedCharacter() {
    std::ostringstream out;
    Error redirectError{&out};
    Arguments args;
    args.addNamedArgument('b', "a mistake");

    CORRADE_COMPARE(out.str(), "Utility::Arguments::addNamedArgument(): invalid key a mistake or its short variant\n");
}
Esempio n. 2
0
void ArgumentsTest::parseCustomTypeFlags() {
    Arguments args;
    args.addNamedArgument("key");

    const char* argv[] = { "", "--key", "0xdeadbeef" };
    const int argc = std::extent<decltype(argv)>();

    CORRADE_VERIFY(args.tryParse(argc, argv));
    CORRADE_COMPARE(args.value<unsigned int>("key", ConfigurationValueFlag::Hex), 0xdeadbeef);
}
Esempio n. 3
0
void ArgumentsTest::parseCustomType() {
    Arguments args;
    args.addNamedArgument("pi");

    const char* argv[] = { "", "--pi", "0.3141516e+1" };
    const int argc = std::extent<decltype(argv)>();

    CORRADE_VERIFY(args.tryParse(argc, argv));
    CORRADE_COMPARE(args.value<float>("pi"), 3.141516f);
}
Esempio n. 4
0
void ArgumentsTest::parseMissingOption() {
    Arguments args;
    args.addNamedArgument("output");

    const char* argv[] = { "" };
    const int argc = std::extent<decltype(argv)>();

    std::ostringstream out;
    Error redirectError{&out};
    CORRADE_VERIFY(!args.tryParse(argc, argv));
    CORRADE_COMPARE(out.str(), "Missing command-line argument --output\n");
}
Esempio n. 5
0
void ArgumentsTest::parseDoubleArgument() {
    Arguments args;
    args.addNamedArgument("arg")
        .addBooleanOption('b', "bool");

    const char* argv[] = { "", "--arg", "first", "-b", "--arg", "second", "-b" };
    const int argc = std::extent<decltype(argv)>();

    CORRADE_VERIFY(args.tryParse(argc, argv));
    CORRADE_COMPARE(args.value("arg"), "second");
    CORRADE_VERIFY(args.isSet("bool"));
}