aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg-test/commands.cpp
blob: 38346291ce3a3545566b3f3bd9e1c1f03ab451dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <catch2/catch.hpp>

#include <vcpkg/commands.contact.h>
#include <vcpkg/commands.h>
#include <vcpkg/commands.upload-metrics.h>
#include <vcpkg/commands.version.h>

#include <stddef.h>

using namespace vcpkg;

namespace
{
    template<class CommandListT, size_t ExpectedCount>
    void check_all_commands(const CommandListT& actual_commands, const char* const (&expected_commands)[ExpectedCount])
    {
        CHECK(actual_commands.size() == ExpectedCount); // makes sure this test is updated if we add a command
        for (const char* expected_command : expected_commands)
        {
            CHECK(Commands::find(StringView{expected_command, strlen(expected_command)}, actual_commands) != nullptr);
        }

        CHECK(Commands::find("x-never-will-exist", actual_commands) == nullptr);
    }
} // unnamed namespace

// clang-format tries to wrap the following lists inappropriately

// clang-format off
TEST_CASE ("get_available_basic_commands works", "[commands]")
{
    check_all_commands(Commands::get_available_basic_commands(), {
        "contact",
        "version",
#if VCPKG_ENABLE_X_UPLOAD_METRICS_COMMAND
        "x-upload-metrics",
#endif // VCPKG_ENABLE_X_UPLOAD_METRICS_COMMAND
        });
}

TEST_CASE ("get_available_paths_commands works", "[commands]")
{
    check_all_commands(Commands::get_available_paths_commands(), {
        "/?",
        "help",
        "search",
        "list",
        "integrate",
        "owns",
        "update",
        "edit",
        "create",
        "cache",
        "portsdiff",
        "autocomplete",
        "hash",
        "fetch",
        "format-manifest",
        "x-ci-clean",
        "x-history",
        "x-package-info",
        "x-vsinstances",
        });
}

TEST_CASE ("get_available_commands_type_a works", "[commands]")
{
    check_all_commands(Commands::get_available_triplet_commands(), {
        "install",
        "x-set-installed",
        "ci",
        "remove",
        "upgrade",
        "build",
        "env",
        "build-external",
        "export",
        "depend-info",
        });
}
// clang-format on