-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathWSLCCLICommandUnitTests.cpp
More file actions
143 lines (114 loc) · 3.87 KB
/
WSLCCLICommandUnitTests.cpp
File metadata and controls
143 lines (114 loc) · 3.87 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*++
Copyright (c) Microsoft. All rights reserved.
Module Name:
WSLCCLICommandUnitTests.cpp
Abstract:
This file contains unit tests for WSLC CLI Command classes.
--*/
#include "precomp.h"
#include "windows/Common.h"
#include "WSLCCLITestHelpers.h"
#include "Command.h"
#include "RootCommand.h"
#include "ContainerCommand.h"
#include "SessionCommand.h"
#include "VersionCommand.h"
using namespace wsl::windows::wslc;
using namespace WSLCTestHelpers;
using namespace WEX::Logging;
using namespace WEX::Common;
using namespace WEX::TestExecution;
namespace WSLCCLICommandUnitTests {
class WSLCCLICommandUnitTests
{
WSLC_TEST_CLASS(WSLCCLICommandUnitTests)
TEST_CLASS_SETUP(TestClassSetup)
{
Log::Comment(L"WSLC CLI Command Unit Tests - Class Setup");
return true;
}
TEST_CLASS_CLEANUP(TestClassCleanup)
{
Log::Comment(L"WSLC CLI Command Unit Tests - Class Cleanup");
return true;
}
// Test: Verify RootCommand has subcommands
TEST_METHOD(RootCommand_HasSubcommands)
{
auto cmd = RootCommand();
auto subcommands = cmd.GetCommands();
// Verify it has subcommands
VERIFY_IS_TRUE(subcommands.size() > 0);
LogComment(L"RootCommand has " + std::to_wstring(subcommands.size()) + L" subcommands");
// Verify each subcommand is valid
for (const auto& subcmd : subcommands)
{
VERIFY_IS_NOT_NULL(subcmd.get());
}
}
// Test: Verify SessionCommand has subcommands
TEST_METHOD(SessionCommand_HasSubcommands)
{
auto cmd = SessionCommand(L"session");
auto subcommands = cmd.GetCommands();
// Verify it has subcommands
VERIFY_IS_TRUE(subcommands.size() > 0);
LogComment(L"SessionCommand has " + std::to_wstring(subcommands.size()) + L" subcommands");
// Log subcommand types
for (const auto& subcmd : subcommands)
{
VERIFY_IS_NOT_NULL(subcmd.get());
}
}
// Test: Verify ContainerCommand has subcommands
TEST_METHOD(ContainerCommand_HasSubcommands)
{
auto cmd = ContainerCommand(L"container");
auto subcommands = cmd.GetCommands();
// Verify it has subcommands
VERIFY_IS_TRUE(subcommands.size() > 0);
LogComment(L"ContainerCommand has " + std::to_wstring(subcommands.size()) + L" subcommands");
// Log subcommand types
for (const auto& subcmd : subcommands)
{
VERIFY_IS_NOT_NULL(subcmd.get());
}
}
// Test: Verify VersionCommand has the correct name
TEST_METHOD(VersionCommand_HasCorrectName)
{
auto cmd = VersionCommand(L"wslc");
VERIFY_ARE_EQUAL(std::wstring_view(L"version"), cmd.Name());
}
// Test: Verify VersionCommand has no subcommands
TEST_METHOD(VersionCommand_HasNoSubcommands)
{
auto cmd = VersionCommand(L"wslc");
VERIFY_ARE_EQUAL(0u, cmd.GetCommands().size());
}
// Test: Verify VersionCommand has no arguments (only the auto-added --help)
TEST_METHOD(VersionCommand_HasNoArguments)
{
auto cmd = VersionCommand(L"wslc");
VERIFY_ARE_EQUAL(0u, cmd.GetArguments().size());
// Test out that auto added help command is the only one
VERIFY_ARE_EQUAL(1u, cmd.GetAllArguments().size());
}
// Test: Verify RootCommand contains VersionCommand as a subcommand
TEST_METHOD(RootCommand_ContainsVersionCommand)
{
auto root = RootCommand();
auto subcommands = root.GetCommands();
bool found = false;
for (const auto& subcmd : subcommands)
{
if (subcmd->Name() == VersionCommand::CommandName)
{
found = true;
break;
}
}
VERIFY_IS_TRUE(found, L"RootCommand should contain VersionCommand");
}
};
} // namespace WSLCCLICommandUnitTests