-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`_Entries` was getting default constructed to `nullptr`. We should be careful about that. Adds a test too, and fixes a regression in the local tests introduced in #13763. Closes #14557
- Loading branch information
1 parent
29ef492
commit 90485e4
Showing
4 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
src/cascadia/LocalTests_SettingsModel/NewTabMenuTests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
|
||
#include "../TerminalSettingsModel/NewTabMenuEntry.h" | ||
#include "../TerminalSettingsModel/FolderEntry.h" | ||
#include "../TerminalSettingsModel/CascadiaSettings.h" | ||
#include "../types/inc/colorTable.hpp" | ||
#include "JsonTestClass.h" | ||
|
||
#include <defaults.h> | ||
|
||
using namespace Microsoft::Console; | ||
using namespace winrt::Microsoft::Terminal; | ||
using namespace winrt::Microsoft::Terminal::Settings::Model::implementation; | ||
using namespace WEX::Logging; | ||
using namespace WEX::TestExecution; | ||
using namespace WEX::Common; | ||
|
||
namespace SettingsModelLocalTests | ||
{ | ||
// TODO:microsoft/terminal#3838: | ||
// Unfortunately, these tests _WILL NOT_ work in our CI. We're waiting for | ||
// an updated TAEF that will let us install framework packages when the test | ||
// package is deployed. Until then, these tests won't deploy in CI. | ||
|
||
class NewTabMenuTests : public JsonTestClass | ||
{ | ||
// Use a custom AppxManifest to ensure that we can activate winrt types | ||
// from our test. This property will tell taef to manually use this as | ||
// the AppxManifest for this test class. | ||
// This does not yet work for anything XAML-y. See TabTests.cpp for more | ||
// details on that. | ||
BEGIN_TEST_CLASS(NewTabMenuTests) | ||
TEST_CLASS_PROPERTY(L"RunAs", L"UAP") | ||
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TestHostAppXManifest.xml") | ||
END_TEST_CLASS() | ||
|
||
TEST_METHOD(DefaultsToRemainingProfiles); | ||
TEST_METHOD(ParseEmptyFolder); | ||
}; | ||
|
||
void NewTabMenuTests::DefaultsToRemainingProfiles() | ||
{ | ||
Log::Comment(L"If the user doesn't customize the menu, put one entry for each profile"); | ||
|
||
static constexpr std::string_view settingsString{ R"json({ | ||
})json" }; | ||
|
||
try | ||
{ | ||
const auto settings{ winrt::make_self<CascadiaSettings>(settingsString, DefaultJson) }; | ||
|
||
VERIFY_ARE_EQUAL(0u, settings->Warnings().Size()); | ||
|
||
const auto& entries = settings->GlobalSettings().NewTabMenu(); | ||
VERIFY_ARE_EQUAL(1u, entries.Size()); | ||
VERIFY_ARE_EQUAL(winrt::Microsoft::Terminal::Settings::Model::NewTabMenuEntryType::RemainingProfiles, entries.GetAt(0).Type()); | ||
} | ||
catch (const SettingsException& ex) | ||
{ | ||
auto loadError = ex.Error(); | ||
loadError; | ||
throw ex; | ||
} | ||
catch (const SettingsTypedDeserializationException& e) | ||
{ | ||
auto deserializationErrorMessage = til::u8u16(e.what()); | ||
Log::Comment(NoThrowString().Format(deserializationErrorMessage.c_str())); | ||
throw e; | ||
} | ||
} | ||
|
||
void NewTabMenuTests::ParseEmptyFolder() | ||
{ | ||
Log::Comment(L"GH #14557 - An empty folder entry shouldn't crash"); | ||
|
||
static constexpr std::string_view settingsString{ R"json({ | ||
"newTabMenu": [ | ||
{ "type": "folder" } | ||
] | ||
})json" }; | ||
|
||
try | ||
{ | ||
const auto settings{ winrt::make_self<CascadiaSettings>(settingsString, DefaultJson) }; | ||
|
||
VERIFY_ARE_EQUAL(0u, settings->Warnings().Size()); | ||
|
||
const auto& entries = settings->GlobalSettings().NewTabMenu(); | ||
VERIFY_ARE_EQUAL(1u, entries.Size()); | ||
} | ||
catch (const SettingsException& ex) | ||
{ | ||
auto loadError = ex.Error(); | ||
loadError; | ||
throw ex; | ||
} | ||
catch (const SettingsTypedDeserializationException& e) | ||
{ | ||
auto deserializationErrorMessage = til::u8u16(e.what()); | ||
Log::Comment(NoThrowString().Format(deserializationErrorMessage.c_str())); | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters