Skip to content

Commit

Permalink
Codecov added, new verison of fmt, removed positional arg parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
abbyssoul committed Mar 19, 2018
1 parent e386cf0 commit b2dd723
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 46 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ script:

after_success:
- make clean && make coverage_report
- bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
- coveralls-lcov --repo-token ${COVERALLS_TOKEN} coverage.info # uploads to coveralls
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
libSolace
===============
[![Build Status](https://travis-ci.org/abbyssoul/libsolace.png?branch=master)](https://travis-ci.org/abbyssoul/libsolace)
[![Coverity Scan](https://scan.coverity.com/projects/9728/badge.svg)](https://scan.coverity.com/projects/abbyssoul-libsolace)
[![Coverage Status](https://coveralls.io/repos/github/abbyssoul/libsolace/badge.svg?branch=master)](https://coveralls.io/github/abbyssoul/libsolace?branch=master)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Build Status][travis-shield]]][travis-link]
[![Coverity Scan][coverity-shield]][coverity-link]
[![Coverage Status][coveralls-shield]][coveralls-link]
[![License][license-shield]][license-link]

[travis-shield]: https://travis-ci.org/abbyssoul/libsolace.png?branch=master
[travis-link]: https://travis-ci.org/abbyssoul/libsolace
[codecov-shield]: https://codecov.io/gh/abbyssoul/libsolace/branch/master/graph/badge.svg
[codecov-link]: https://codecov.io/gh/abbyssoul/libsolace
[coverity-shield]: https://scan.coverity.com/projects/9728/badge.svg
[coverity-link]: https://scan.coverity.com/projects/abbyssoul-libsolace
[coveralls-shield]: https://coveralls.io/repos/github/abbyssoul/libsolace/badge.svg?branch=master
[coveralls-link]: https://coveralls.io/github/abbyssoul/libsolace?branch=master
[license-shield]: https://img.shields.io/badge/License-Apache%202.0-blue.svg
[license-link]: https://opensource.org/licenses/Apache-2.0

libSolace is a toolkit for building mission critical application.
Idea of this library is partually inspired by [NASA's Rules for Developing Safety Critical Code](http://spinroot.com/gerard/pdf/P10.pdf).
Expand Down
2 changes: 1 addition & 1 deletion external/fmt
10 changes: 5 additions & 5 deletions include/solace/framework/commandlineParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class CommandlineParser {

CommandlineParser(const char* appDescription,
const std::initializer_list<Option>& options,
const std::initializer_list<Argument>& arguments);
const std::initializer_list<Command>& arguments);

// CommandlineParser(const char* appDescription,
// const std::initializer_list<Option>& options,
Expand All @@ -404,15 +404,15 @@ class CommandlineParser {
_prefix(rhs._prefix),
_description(rhs._description),
_options(rhs._options),
_arguments(rhs._arguments),
// _arguments(rhs._arguments),
_commands(rhs._commands)
{}

CommandlineParser(CommandlineParser&& rhs) noexcept :
_prefix(exchange(rhs._prefix, DefaultPrefix)),
_description(exchange(rhs._description, nullptr)),
_options(std::move(rhs._options)),
_arguments(std::move(rhs._arguments)),
// _arguments(std::move(rhs._arguments)),
_commands(std::move(rhs._commands))
{}

Expand All @@ -431,7 +431,7 @@ class CommandlineParser {
swap(_prefix, rhs._prefix);
swap(_description, rhs._description);
swap(_options, rhs._options);
swap(_arguments, rhs._arguments);
// swap(_arguments, rhs._arguments);
swap(_commands, rhs._commands);

return (*this);
Expand Down Expand Up @@ -527,7 +527,7 @@ class CommandlineParser {
Array<Option> _options;

/// Mandatory arguments application requires.
Array<Argument> _arguments;
// Array<Argument> _arguments;

/// Mandatory commands application expects.
Array<Command> _commands;
Expand Down
59 changes: 32 additions & 27 deletions src/framework/commandlineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ CommandlineParser::CommandlineParser(const char* appDescription) :
_prefix(DefaultPrefix),
_description(appDescription),
_options(),
_arguments()
_commands()
{
}

Expand All @@ -319,18 +319,18 @@ CommandlineParser::CommandlineParser(const char* appDescription,
_prefix(DefaultPrefix),
_description(appDescription),
_options(options),
_arguments()
_commands()
{
}


CommandlineParser::CommandlineParser(const char* appDescription,
const std::initializer_list<Option>& options,
const std::initializer_list<Argument>& arguments) :
const std::initializer_list<Command>& commands) :
_prefix(DefaultPrefix),
_description(appDescription),
_options(options),
_arguments(arguments)
_commands(commands)
{
}

Expand Down Expand Up @@ -492,39 +492,44 @@ CommandlineParser::parse(int argc, const char *argv[]) const {

// Positional arguments processing
if (firstPositionalArgument >= nbOfArguments)
return (_arguments.empty() && _commands.empty())
return (/*_arguments.empty() && */_commands.empty())
? Ok(this)
: fail("No mandatory arguments given");

const auto nbPositionalArguments = nbOfArguments - firstPositionalArgument;

if (_commands.empty()) {
if (nbPositionalArguments > _arguments.size()) {
return fail("Too many arguments given {}, expected: {}",
nbPositionalArguments,
_arguments.size());
}
if (nbPositionalArguments != 0 && _commands.empty())
return fail("No command given");

// if (_commands.empty()) {
// if (nbPositionalArguments > _arguments.size()) {
// return fail("Too many arguments given {}, expected: {}",
// nbPositionalArguments,
// _arguments.size());
// }

if (nbPositionalArguments < _arguments.size()) {
return fail("No value given for argument {} '{}'",
_arguments.size() - nbPositionalArguments,
_arguments[_arguments.size() - nbPositionalArguments - 1].name());
}

for (uint i = 0; i < nbPositionalArguments; ++i) {
Context cntx {nbOfArguments, argv,
_arguments[i].name(),
argv[firstPositionalArgument + i],
*this};
// if (nbPositionalArguments < _arguments.size()) {
// return fail("No value given for argument {} '{}'",
// _arguments.size() - nbPositionalArguments,
// _arguments[_arguments.size() - nbPositionalArguments - 1].name());
// }

_arguments[i].match(cntx);
// for (uint i = 0; i < nbPositionalArguments; ++i) {
// Context cntx {nbOfArguments, argv,
// _arguments[i].name(),
// argv[firstPositionalArgument + i],
// *this};

if (cntx.isStopRequired) {
return Err(Error("", 0));
}
}
} else {
// _arguments[i].match(cntx);

// if (cntx.isStopRequired) {
// return Err(Error("", 0));
// }
// }

// } else {
if (!_commands.empty()) {

if (nbPositionalArguments < 1) {
return fail("No command given");
Expand Down
17 changes: 8 additions & 9 deletions test/framework/test_commandlineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ class TestCommandlineParser: public CppUnit::TestFixture {
CPPUNIT_TEST(testCustomNoValue);
CPPUNIT_TEST(testCustomNoValueExpected);

CPPUNIT_TEST(testMandatoryArgument);
CPPUNIT_TEST(testMandatoryArgumentMissing);
CPPUNIT_TEST(testMandatoryArgumentWithoutGivenFlags);
CPPUNIT_TEST(testMandatoryArgumentOnly);

CPPUNIT_TEST(testMandatoryArgumentNotEnought);
CPPUNIT_TEST(testMandatoryArgumentTooMany);
// CPPUNIT_TEST(testMandatoryArgument);
// CPPUNIT_TEST(testMandatoryArgumentMissing);
// CPPUNIT_TEST(testMandatoryArgumentWithoutGivenFlags);
// CPPUNIT_TEST(testMandatoryArgumentOnly);
// CPPUNIT_TEST(testMandatoryArgumentNotEnought);
// CPPUNIT_TEST(testMandatoryArgumentTooMany);

CPPUNIT_TEST(testCommandGivenButNotExpected);
CPPUNIT_TEST(testMandatoryCommandNotGiven);
Expand Down Expand Up @@ -576,7 +575,7 @@ class TestCommandlineParser: public CppUnit::TestFixture {
CPPUNIT_ASSERT(customCalled);
CPPUNIT_ASSERT_EQUAL(756, xValue);
}

/*
void testMandatoryArgument() {
bool parsedSuccessully = false;
Expand Down Expand Up @@ -726,7 +725,7 @@ class TestCommandlineParser: public CppUnit::TestFixture {
CPPUNIT_ASSERT(mandatoryArgStr.empty());
CPPUNIT_ASSERT_EQUAL(0, mandatoryArgInt);
}

*/

void testCommandGivenButNotExpected() {
bool parsedSuccessully = false;
Expand Down

0 comments on commit b2dd723

Please sign in to comment.