Skip to content

Commit

Permalink
Fix failing TestHostApp unit tests (#11394)
Browse files Browse the repository at this point in the history
This commit fixes various failing TestHostApp unit tests.
Most of these broke as part of 168d28b (#11184).

## PR Checklist
* [x] Closes #11339
* [x] I work here
* [x] Tests added/passed
  • Loading branch information
lhecker authored Oct 5, 2021
1 parent 6295c8c commit 0b552e1
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ namespace SettingsModelLocalTests
},
{
"name": "profile1",
"guid": "{6239a42c-1111-49a3-80bd-e8fdd045185c}",
"guid": "{6239a42c-2222-49a3-80bd-e8fdd045185c}",
"source": "Terminal.App.UnitTest.1",
"historySize": 2222
},
Expand Down
15 changes: 13 additions & 2 deletions src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ namespace SettingsModelLocalTests
// the GUID generated for a dynamic profile (with a source) is different
// than that of a profile without a source.

static constexpr std::string_view inboxSettings{ R"({
"profiles": [
{
"name" : "profile0",
"source": "Terminal.App.UnitTest.0"
},
{
"name" : "profile1"
}
]
})" };
static constexpr std::string_view userSettings{ R"({
"profiles": [
{
Expand All @@ -312,9 +323,9 @@ namespace SettingsModelLocalTests
]
})" };

const auto settings = winrt::make_self<implementation::CascadiaSettings>(userSettings, DefaultJson);
const auto settings = winrt::make_self<implementation::CascadiaSettings>(userSettings, inboxSettings);

VERIFY_ARE_EQUAL(4u, settings->AllProfiles().Size());
VERIFY_ARE_EQUAL(3u, settings->AllProfiles().Size());

VERIFY_ARE_EQUAL(L"profile0", settings->AllProfiles().GetAt(0).Name());
VERIFY_IS_TRUE(settings->AllProfiles().GetAt(0).HasGuid());
Expand Down
54 changes: 27 additions & 27 deletions src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace SettingsModelLocalTests
// Return Value:
// - the JsonObject representing this instance
template<typename T>
void RoundtripTest(const std::string& jsonString)
void RoundtripTest(const std::string_view& jsonString)
{
const auto json{ VerifyParseSucceeded(jsonString) };
const auto settings{ T::FromJson(json) };
Expand All @@ -69,7 +69,7 @@ namespace SettingsModelLocalTests

void SerializationTests::GlobalSettings()
{
const std::string globalsString{ R"(
static constexpr std::string_view globalsString{ R"(
{
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
Expand Down Expand Up @@ -105,7 +105,7 @@ namespace SettingsModelLocalTests
"actions": []
})" };

const std::string smallGlobalsString{ R"(
static constexpr std::string_view smallGlobalsString{ R"(
{
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"actions": []
Expand All @@ -117,7 +117,7 @@ namespace SettingsModelLocalTests

void SerializationTests::Profile()
{
const std::string profileString{ R"(
static constexpr std::string_view profileString{ R"(
{
"name": "Windows PowerShell",
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
Expand Down Expand Up @@ -152,7 +152,7 @@ namespace SettingsModelLocalTests
"selectionBackground": "#CCAABB",
"useAcrylic": false,
"acrylicOpacity": 0.5,
"opacity": 50,
"backgroundImage": "made_you_look.jpeg",
"backgroundImageStretchMode": "uniformToFill",
Expand All @@ -167,15 +167,15 @@ namespace SettingsModelLocalTests
"experimental.retroTerminalEffect": false
})" };

const std::string smallProfileString{ R"(
static constexpr std::string_view smallProfileString{ R"(
{
"name": "Custom Profile"
})" };

// Setting "tabColor" to null tests two things:
// - null should count as an explicit user-set value, not falling back to the parent's value
// - null should be acceptable even though we're working with colors
const std::string weirdProfileString{ R"(
static constexpr std::string_view weirdProfileString{ R"(
{
"guid" : "{8b039d4d-77ca-5a83-88e1-dfc8e895a127}",
"name": "Weird Profile",
Expand All @@ -192,7 +192,7 @@ namespace SettingsModelLocalTests

void SerializationTests::ColorScheme()
{
const std::string schemeString{ R"({
static constexpr std::string_view schemeString{ R"({
"name": "Campbell",
"cursorColor": "#FFFFFF",
Expand Down Expand Up @@ -225,56 +225,56 @@ namespace SettingsModelLocalTests
void SerializationTests::Actions()
{
// simple command
const std::string actionsString1{ R"([
static constexpr std::string_view actionsString1{ R"([
{ "command": "paste" }
])" };

// complex command
const std::string actionsString2A{ R"([
static constexpr std::string_view actionsString2A{ R"([
{ "command": { "action": "setTabColor" } }
])" };
const std::string actionsString2B{ R"([
static constexpr std::string_view actionsString2B{ R"([
{ "command": { "action": "setTabColor", "color": "#112233" } }
])" };
const std::string actionsString2C{ R"([
static constexpr std::string_view actionsString2C{ R"([
{ "command": { "action": "copy" } },
{ "command": { "action": "copy", "singleLine": true, "copyFormatting": "html" } }
])" };

// simple command with key chords
const std::string actionsString3{ R"([
static constexpr std::string_view actionsString3{ R"([
{ "command": "toggleAlwaysOnTop", "keys": "ctrl+a" },
{ "command": "toggleAlwaysOnTop", "keys": "ctrl+b" }
])" };

// complex command with key chords
const std::string actionsString4A{ R"([
static constexpr std::string_view actionsString4A{ R"([
{ "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+c" },
{ "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+d" }
])" };
const std::string actionsString4B{ R"([
static constexpr std::string_view actionsString4B{ R"([
{ "command": { "action": "findMatch", "direction": "next" }, "keys": "ctrl+shift+s" },
{ "command": { "action": "findMatch", "direction": "prev" }, "keys": "ctrl+shift+r" }
])" };

// command with name and icon and multiple key chords
const std::string actionsString5{ R"([
static constexpr std::string_view actionsString5{ R"([
{ "icon": "image.png", "name": "Scroll To Top Name", "command": "scrollToTop", "keys": "ctrl+e" },
{ "command": "scrollToTop", "keys": "ctrl+f" }
])" };

// complex command with new terminal args
const std::string actionsString6{ R"([
static constexpr std::string_view actionsString6{ R"([
{ "command": { "action": "newTab", "index": 0 }, "keys": "ctrl+g" },
])" };

// complex command with meaningful null arg
const std::string actionsString7{ R"([
static constexpr std::string_view actionsString7{ R"([
{ "command": { "action": "renameWindow", "name": null }, "keys": "ctrl+h" }
])" };

// nested command
const std::string actionsString8{ R"([
static constexpr std::string_view actionsString8{ R"([
{
"name": "Change font size...",
"commands": [
Expand All @@ -286,7 +286,7 @@ namespace SettingsModelLocalTests
])" };

// iterable command
const std::string actionsString9A{ R"([
static constexpr std::string_view actionsString9A{ R"([
{
"name": "New tab",
"commands": [
Expand All @@ -299,7 +299,7 @@ namespace SettingsModelLocalTests
]
}
])" };
const std::string actionsString9B{ R"([
static constexpr std::string_view actionsString9B{ R"([
{
"commands":
[
Expand All @@ -315,7 +315,7 @@ namespace SettingsModelLocalTests
"name": "Send Input ..."
}
])" };
const std::string actionsString9C{ R""([
static constexpr std::string_view actionsString9C{ R""([
{
"commands":
[
Expand All @@ -338,7 +338,7 @@ namespace SettingsModelLocalTests
"name": "Send Input (Evil) ..."
}
])"" };
const std::string actionsString9D{ R""([
static constexpr std::string_view actionsString9D{ R""([
{
"command":
{
Expand All @@ -352,7 +352,7 @@ namespace SettingsModelLocalTests
])"" };

// unbound command
const std::string actionsString10{ R"([
static constexpr std::string_view actionsString10{ R"([
{ "command": "unbound", "keys": "ctrl+c" }
])" };

Expand Down Expand Up @@ -395,7 +395,7 @@ namespace SettingsModelLocalTests

void SerializationTests::CascadiaSettings()
{
const std::string settingsString{ R"({
static constexpr std::string_view settingsString{ R"({
"$help" : "https://aka.ms/terminal-documentation",
"$schema" : "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-1111-5271-96e7-009a87ff44bf}",
Expand Down Expand Up @@ -465,7 +465,7 @@ namespace SettingsModelLocalTests

void SerializationTests::LegacyFontSettings()
{
const std::string profileString{ R"(
static constexpr std::string_view profileString{ R"(
{
"name": "Profile with legacy font settings",
Expand All @@ -474,7 +474,7 @@ namespace SettingsModelLocalTests
"fontWeight": "normal"
})" };

const std::string expectedOutput{ R"(
static constexpr std::string_view expectedOutput{ R"(
{
"name": "Profile with legacy font settings",
Expand Down
10 changes: 7 additions & 3 deletions src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,9 +1031,11 @@ namespace TerminalAppLocalTests
// The first action is going to always be a new-tab action
VERIFY_ARE_EQUAL(ShortcutAction::NewTab, appArgs._startupActions.at(0).Action());

auto actionAndArgs = appArgs._startupActions.at(1);
const auto actionAndArgs = appArgs._startupActions.at(1);
VERIFY_ARE_EQUAL(ShortcutAction::NextTab, actionAndArgs.Action());
VERIFY_IS_NULL(actionAndArgs.Args());
VERIFY_IS_NOT_NULL(actionAndArgs.Args());
const auto myArgs = actionAndArgs.Args().as<NextTabArgs>();
VERIFY_ARE_EQUAL(TabSwitcherMode::Disabled, myArgs.SwitcherMode().Value());
}
{
AppCommandlineArgs appArgs{};
Expand All @@ -1047,7 +1049,9 @@ namespace TerminalAppLocalTests

auto actionAndArgs = appArgs._startupActions.at(1);
VERIFY_ARE_EQUAL(ShortcutAction::PrevTab, actionAndArgs.Action());
VERIFY_IS_NULL(actionAndArgs.Args());
VERIFY_IS_NOT_NULL(actionAndArgs.Args());
const auto myArgs = actionAndArgs.Args().as<PrevTabArgs>();
VERIFY_ARE_EQUAL(TabSwitcherMode::Disabled, myArgs.SwitcherMode().Value());
}
{
AppCommandlineArgs appArgs{};
Expand Down
Loading

0 comments on commit 0b552e1

Please sign in to comment.