xaizek / uncov (License: AGPLv3+) (since 2018-12-07)
Uncov(er) is a tool that collects and processes code coverage reports.
<root> / tests / Invocation.cpp (466ddd4b2408cd8c9327ba4de4770205d0a596da) (3,770B) (mode 100644) [raw]
// Copyright (C) 2016 xaizek <xaizek@posteo.net>
//
// This file is part of uncov.
//
// uncov is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uncov is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with uncov.  If not, see <http://www.gnu.org/licenses/>.

#include "Catch/catch.hpp"

#include <boost/algorithm/string/predicate.hpp>

#include <stdexcept>

#include "Invocation.hpp"

#include "TestUtils.hpp"

TEST_CASE("Constructor throws on empty argument list", "[Invocation]")
{
    REQUIRE_THROWS_AS(Invocation invocation({}), std::invalid_argument);
}

TEST_CASE("Invocation errors on too few arguments", "[Invocation]")
{
    SECTION("Program name only")
    {
        REQUIRE(Invocation({ "uncov" }).getError() != std::string());
    }

    SECTION("Program name and repository")
    {
        Invocation invocation({ "uncov", "." });
        REQUIRE(invocation.getError() != std::string());
    }
}

TEST_CASE("Well-formed command-line is parsed correctly", "[Invocation]")
{
    Invocation invocation({ "uncov", ".", "show", "arg1", "arg2" });
    REQUIRE(invocation.getError() == std::string());
    CHECK(invocation.getRepositoryPath() == ".");
    CHECK(invocation.getSubcommandName() == "show");
    CHECK(invocation.getSubcommandArgs() == vs({ "arg1", "arg2" }));
}

TEST_CASE("Repository argument is optional", "[Invocation]")
{
    SECTION("No repo argument")
    {
        Invocation invocation({ "uncov", "show", "arg1", "arg2" });
        REQUIRE(invocation.getError() == std::string());
        CHECK(invocation.getRepositoryPath() == ".");
        CHECK(invocation.getSubcommandName() == "show");
        CHECK(invocation.getSubcommandArgs() == vs({ "arg1", "arg2" }));
    }

    SECTION("Path with slash")
    {
        Invocation invocation({ "uncov", "a/path", "show", "arg1", "arg2" });
        REQUIRE(invocation.getError() == std::string());
        CHECK(invocation.getRepositoryPath() == "a/path");
        CHECK(invocation.getSubcommandName() == "show");
        CHECK(invocation.getSubcommandArgs() == vs({ "arg1", "arg2" }));
    }

    SECTION("Subcommand without arguments")
    {
        Invocation invocation({ "uncov", "builds" });
        REQUIRE(invocation.getError() == std::string());
        CHECK(invocation.getRepositoryPath() == ".");
        CHECK(invocation.getSubcommandName() == "builds");
        CHECK(invocation.getSubcommandArgs() == vs({}));
    }
}

TEST_CASE("Options are parsed", "[Invocation]")
{
    SECTION("Without repository name")
    {
        Invocation invocation({ "uncov", "--help", "--version" });
        REQUIRE(invocation.getError() == std::string());
        CHECK(invocation.shouldPrintHelp());
        CHECK(invocation.shouldPrintVersion());
    }

    SECTION("With repository name")
    {
        Invocation invocation({ "uncov", "--help", "." });
        REQUIRE(invocation.getError() == std::string());
        CHECK(invocation.shouldPrintHelp());
    }
}

TEST_CASE("Usage message includes program name", "[Invocation]")
{
    Invocation invocation({ "asdf", "subcommand" });

    CHECK(boost::contains(invocation.getUsage(), "asdf"));
}

TEST_CASE("Wrong option causes an error", "[Invocation]")
{
    Invocation invocation({ "uncov", "--no-such-option" });

    CHECK(invocation.getError() != std::string());
}
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/uncov

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/uncov

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master