forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
141 lines (124 loc) · 4.6 KB
/
Copy pathmain.cpp
File metadata and controls
141 lines (124 loc) · 4.6 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#include <winrt/Windows.Foundation.h>
#include <iostream>
#include <string>
#include <vector>
#include <Public/AppInstallerLogging.h>
#include <Public/AppInstallerTelemetry.h>
#include "TestCommon.h"
#include "TestHooks.h"
using namespace winrt;
using namespace Windows::Foundation;
using namespace std::string_literals;
using namespace AppInstaller;
// Logs the the AppInstaller log target to break up individual tests
struct LoggingBreakListener : public Catch::TestEventListenerBase
{
using TestEventListenerBase::TestEventListenerBase;
void testCaseStarting(const Catch::TestCaseInfo& info) override
{
Catch::TestEventListenerBase::testCaseStarting(info);
AICLI_LOG(Test, Info, << "========== Test Case Begins :: " << info.name << " ==========");
TestCommon::TempFile::SetTestFailed(false);
}
void testCaseEnded(const Catch::TestCaseStats& testCaseStats) override
{
AICLI_LOG(Test, Info, << "========== Test Case Ends :: " << currentTestCaseInfo->name << " ==========");
if (!testCaseStats.totals.delta(lastTotals).testCases.allOk())
{
TestCommon::TempFile::SetTestFailed(true);
}
lastTotals = testCaseStats.totals;
Catch::TestEventListenerBase::testCaseEnded(testCaseStats);
}
Catch::Totals lastTotals{};
};
CATCH_REGISTER_LISTENER(LoggingBreakListener);
int main(int argc, char** argv)
{
init_apartment();
bool hasSetTestDataBasePath = false;
bool waitBeforeReturn = false;
bool keepSQLLogging = false;
std::vector<char*> args;
for (int i = 0; i < argc; ++i)
{
if ("-ktf"s == argv[i])
{
TestCommon::TempFile::SetDestructorBehavior(TestCommon::TempFileDestructionBehavior::Keep);
}
else if ("-seof"s == argv[i])
{
TestCommon::TempFile::SetDestructorBehavior(TestCommon::TempFileDestructionBehavior::ShellExecuteOnFailure);
}
else if ("-log"s == argv[i])
{
Logging::AddFileLogger();
}
else if ("-logto"s == argv[i])
{
++i;
Logging::AddFileLogger(argv[i]);
}
else if ("-tdd"s == argv[i])
{
++i;
if (i < argc)
{
TestCommon::TestDataFile::SetTestDataBasePath(argv[i]);
hasSetTestDataBasePath = true;
}
}
else if ("-wait"s == argv[i])
{
waitBeforeReturn = true;
}
else if ("-logsql"s == argv[i])
{
keepSQLLogging = true;
}
else
{
args.push_back(argv[i]);
}
}
// If not set, use the current executables path
if (!hasSetTestDataBasePath)
{
wchar_t fullFileName[1024];
DWORD chars = ARRAYSIZE(fullFileName);
if (QueryFullProcessImageNameW(GetCurrentProcess(), 0, fullFileName, &chars))
{
std::filesystem::path filepath{ fullFileName };
filepath.remove_filename();
TestCommon::TestDataFile::SetTestDataBasePath(filepath);
}
}
// Enable logging, to force log string building to run.
// Disable SQL by default, as it generates 10s of MBs of log file and
// increases the the full test run time by 60% or more.
// By not creating a log target, it will all be thrown away.
Logging::Log().EnableChannel(Logging::Channel::All);
if (!keepSQLLogging)
{
Logging::Log().DisableChannel(Logging::Channel::SQL);
}
Logging::Log().SetLevel(Logging::Level::Verbose);
Logging::EnableWilFailureTelemetry();
// Force all tests to run against settings inside this container.
// This prevents test runs from trashing the users actual settings.
Runtime::TestHook_SetPathOverride(Runtime::PathName::LocalState, Runtime::GetPathTo(Runtime::PathName::LocalState) / "Tests");
Runtime::TestHook_SetPathOverride(Runtime::PathName::UserFileSettings, Runtime::GetPathTo(Runtime::PathName::UserFileSettings) / "Tests");
Runtime::TestHook_SetPathOverride(Runtime::PathName::StandardSettings, Runtime::GetPathTo(Runtime::PathName::StandardSettings) / "Tests");
Runtime::TestHook_SetPathOverride(Runtime::PathName::SecureSettings, Runtime::GetPathTo(Runtime::PathName::Temp) / "WinGet_SecureSettings_Tests");
int result = Catch::Session().run(static_cast<int>(args.size()), args.data());
if (waitBeforeReturn)
{
// Wait for some input before returning
std::cin.get();
}
return result;
}