From 0b552e1ae8802ec0b384550408e9ebfd7af3029b Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Tue, 5 Oct 2021 20:21:03 +0200 Subject: [PATCH] Fix failing TestHostApp unit tests (#11394) 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 --- .../DeserializationTests.cpp | 2 +- .../LocalTests_SettingsModel/ProfileTests.cpp | 15 +- .../SerializationTests.cpp | 54 +++---- .../CommandlineTest.cpp | 10 +- .../LocalTests_TerminalApp/SettingsTests.cpp | 152 +++++++++++++----- 5 files changed, 161 insertions(+), 72 deletions(-) diff --git a/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp b/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp index 7f6638954c0..ea603c9420f 100644 --- a/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp @@ -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 }, diff --git a/src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp b/src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp index 54c405592aa..ee42b89a47d 100644 --- a/src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp @@ -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": [ { @@ -312,9 +323,9 @@ namespace SettingsModelLocalTests ] })" }; - const auto settings = winrt::make_self(userSettings, DefaultJson); + const auto settings = winrt::make_self(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()); diff --git a/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp b/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp index e538967f9f8..10214b861e6 100644 --- a/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp @@ -53,7 +53,7 @@ namespace SettingsModelLocalTests // Return Value: // - the JsonObject representing this instance template - void RoundtripTest(const std::string& jsonString) + void RoundtripTest(const std::string_view& jsonString) { const auto json{ VerifyParseSucceeded(jsonString) }; const auto settings{ T::FromJson(json) }; @@ -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}", @@ -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": [] @@ -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}", @@ -152,7 +152,7 @@ namespace SettingsModelLocalTests "selectionBackground": "#CCAABB", "useAcrylic": false, - "acrylicOpacity": 0.5, + "opacity": 50, "backgroundImage": "made_you_look.jpeg", "backgroundImageStretchMode": "uniformToFill", @@ -167,7 +167,7 @@ namespace SettingsModelLocalTests "experimental.retroTerminalEffect": false })" }; - const std::string smallProfileString{ R"( + static constexpr std::string_view smallProfileString{ R"( { "name": "Custom Profile" })" }; @@ -175,7 +175,7 @@ namespace SettingsModelLocalTests // 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", @@ -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", @@ -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": [ @@ -286,7 +286,7 @@ namespace SettingsModelLocalTests ])" }; // iterable command - const std::string actionsString9A{ R"([ + static constexpr std::string_view actionsString9A{ R"([ { "name": "New tab", "commands": [ @@ -299,7 +299,7 @@ namespace SettingsModelLocalTests ] } ])" }; - const std::string actionsString9B{ R"([ + static constexpr std::string_view actionsString9B{ R"([ { "commands": [ @@ -315,7 +315,7 @@ namespace SettingsModelLocalTests "name": "Send Input ..." } ])" }; - const std::string actionsString9C{ R""([ + static constexpr std::string_view actionsString9C{ R""([ { "commands": [ @@ -338,7 +338,7 @@ namespace SettingsModelLocalTests "name": "Send Input (Evil) ..." } ])"" }; - const std::string actionsString9D{ R""([ + static constexpr std::string_view actionsString9D{ R""([ { "command": { @@ -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" } ])" }; @@ -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}", @@ -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", @@ -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", diff --git a/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp b/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp index a9975b661dc..0d63043deba 100644 --- a/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp +++ b/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp @@ -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(); + VERIFY_ARE_EQUAL(TabSwitcherMode::Disabled, myArgs.SwitcherMode().Value()); } { AppCommandlineArgs appArgs{}; @@ -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(); + VERIFY_ARE_EQUAL(TabSwitcherMode::Disabled, myArgs.SwitcherMode().Value()); } { AppCommandlineArgs appArgs{}; diff --git a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp index fd7a8e446fd..f2c6fac9d81 100644 --- a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp @@ -16,6 +16,31 @@ using namespace winrt::Microsoft::Terminal::Control; namespace TerminalAppLocalTests { + static constexpr std::wstring_view inboxSettings{ LR"({ + "schemes": [{ + "name": "Campbell", + "foreground": "#CCCCCC", + "background": "#0C0C0C", + "cursorColor": "#FFFFFF", + "black": "#0C0C0C", + "red": "#C50F1F", + "green": "#13A10E", + "yellow": "#C19C00", + "blue": "#0037DA", + "purple": "#881798", + "cyan": "#3A96DD", + "white": "#CCCCCC", + "brightBlack": "#767676", + "brightRed": "#E74856", + "brightGreen": "#16C60C", + "brightYellow": "#F9F1A5", + "brightBlue": "#3B78FF", + "brightPurple": "#B4009E", + "brightCyan": "#61D6D6", + "brightWhite": "#F2F2F2" + }] + })" }; + // 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 @@ -107,11 +132,10 @@ namespace TerminalAppLocalTests "iterateOn": "profiles", "command": { "action": "splitPane", "profile": "${profile.name}" } }, - ], - "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. + ] })" }; - CascadiaSettings settings{ settingsJson, {} }; + CascadiaSettings settings{ settingsJson, inboxSettings }; VERIFY_ARE_EQUAL(0u, settings.Warnings().Size()); @@ -231,11 +255,10 @@ namespace TerminalAppLocalTests "iterateOn": "profiles", "command": { "action": "splitPane", "profile": "${profile.name}" } }, - ], - "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. + ] })" }; - CascadiaSettings settings{ settingsJson, {} }; + CascadiaSettings settings{ settingsJson, inboxSettings }; VERIFY_ARE_EQUAL(0u, settings.Warnings().Size()); @@ -357,11 +380,10 @@ namespace TerminalAppLocalTests "iterateOn": "profiles", "command": { "action": "splitPane", "profile": "${profile.name}" } }, - ], - "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. + ] })" }; - CascadiaSettings settings{ settingsJson, {} }; + CascadiaSettings settings{ settingsJson, inboxSettings }; VERIFY_ARE_EQUAL(0u, settings.Warnings().Size()); @@ -495,11 +517,10 @@ namespace TerminalAppLocalTests } ] }, - ], - "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. + ] })" }; - CascadiaSettings settings{ settingsJson, {} }; + CascadiaSettings settings{ settingsJson, inboxSettings }; VERIFY_ARE_EQUAL(0u, settings.Warnings().Size()); VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size()); @@ -590,11 +611,10 @@ namespace TerminalAppLocalTests }, ] }, - ], - "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. + ] })" }; - CascadiaSettings settings{ settingsJson, {} }; + CascadiaSettings settings{ settingsJson, inboxSettings }; VERIFY_ARE_EQUAL(0u, settings.Warnings().Size()); VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size()); @@ -714,11 +734,10 @@ namespace TerminalAppLocalTests { "command": { "action": "splitPane", "profile": "${profile.name}", "split": "down" } } ] } - ], - "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. + ] })" }; - CascadiaSettings settings{ settingsJson, {} }; + CascadiaSettings settings{ settingsJson, inboxSettings }; VERIFY_ARE_EQUAL(0u, settings.Warnings().Size()); VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size()); @@ -851,11 +870,10 @@ namespace TerminalAppLocalTests } ] } - ], - "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. + ] })" }; - CascadiaSettings settings{ settingsJson, {} }; + CascadiaSettings settings{ settingsJson, inboxSettings }; VERIFY_ARE_EQUAL(0u, settings.Warnings().Size()); VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size()); @@ -954,11 +972,10 @@ namespace TerminalAppLocalTests } ] } - ], - "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. + ] })" }; - CascadiaSettings settings{ settingsJson, {} }; + CascadiaSettings settings{ settingsJson, inboxSettings }; VERIFY_ARE_EQUAL(0u, settings.Warnings().Size()); VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size()); @@ -1085,9 +1102,72 @@ namespace TerminalAppLocalTests } ], "schemes": [ - { "name": "scheme_0" }, - { "name": "scheme_1" }, - { "name": "scheme_2" }, + { + "name": "Campbell", + "foreground": "#CCCCCC", + "background": "#0C0C0C", + "cursorColor": "#FFFFFF", + "black": "#0C0C0C", + "red": "#C50F1F", + "green": "#13A10E", + "yellow": "#C19C00", + "blue": "#0037DA", + "purple": "#881798", + "cyan": "#3A96DD", + "white": "#CCCCCC", + "brightBlack": "#767676", + "brightRed": "#E74856", + "brightGreen": "#16C60C", + "brightYellow": "#F9F1A5", + "brightBlue": "#3B78FF", + "brightPurple": "#B4009E", + "brightCyan": "#61D6D6", + "brightWhite": "#F2F2F2" + }, + { + "name": "Campbell PowerShell", + "foreground": "#CCCCCC", + "background": "#012456", + "cursorColor": "#FFFFFF", + "black": "#0C0C0C", + "red": "#C50F1F", + "green": "#13A10E", + "yellow": "#C19C00", + "blue": "#0037DA", + "purple": "#881798", + "cyan": "#3A96DD", + "white": "#CCCCCC", + "brightBlack": "#767676", + "brightRed": "#E74856", + "brightGreen": "#16C60C", + "brightYellow": "#F9F1A5", + "brightBlue": "#3B78FF", + "brightPurple": "#B4009E", + "brightCyan": "#61D6D6", + "brightWhite": "#F2F2F2" + }, + { + "name": "Vintage", + "foreground": "#C0C0C0", + "background": "#000000", + "cursorColor": "#FFFFFF", + "black": "#000000", + "red": "#800000", + "green": "#008000", + "yellow": "#808000", + "blue": "#000080", + "purple": "#800080", + "cyan": "#008080", + "white": "#C0C0C0", + "brightBlack": "#808080", + "brightRed": "#FF0000", + "brightGreen": "#00FF00", + "brightYellow": "#FFFF00", + "brightBlue": "#0000FF", + "brightPurple": "#FF00FF", + "brightCyan": "#00FFFF", + "brightWhite": "#FFFFFF" + } ], "actions": [ { @@ -1100,10 +1180,6 @@ namespace TerminalAppLocalTests CascadiaSettings settings{ settingsJson, {} }; - // Since at least one profile does not reference a color scheme, - // we add a warning saying "the color scheme is unknown" - VERIFY_ARE_EQUAL(1u, settings.Warnings().Size()); - VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size()); auto nameMap{ settings.ActionMap().NameMap() }; @@ -1130,8 +1206,6 @@ namespace TerminalAppLocalTests auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(nameMap, settings.ActiveProfiles().GetView(), settings.GlobalSettings().ColorSchemes()); _logCommandNames(expandedCommands.GetView()); - // This is the same warning as above - VERIFY_ARE_EQUAL(1u, settings.Warnings().Size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); // Yes, this test is testing splitPane with profiles named after each @@ -1139,7 +1213,7 @@ namespace TerminalAppLocalTests // just easy tests to write. { - auto command = expandedCommands.Lookup(L"iterable command scheme_0"); + auto command = expandedCommands.Lookup(L"iterable command Campbell"); VERIFY_IS_NOT_NULL(command); auto actionAndArgs = command.ActionAndArgs(); VERIFY_IS_NOT_NULL(actionAndArgs); @@ -1153,11 +1227,11 @@ namespace TerminalAppLocalTests VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"scheme_0", realArgs.TerminalArgs().Profile()); + VERIFY_ARE_EQUAL(L"Campbell", realArgs.TerminalArgs().Profile()); } { - auto command = expandedCommands.Lookup(L"iterable command scheme_1"); + auto command = expandedCommands.Lookup(L"iterable command Campbell PowerShell"); VERIFY_IS_NOT_NULL(command); auto actionAndArgs = command.ActionAndArgs(); VERIFY_IS_NOT_NULL(actionAndArgs); @@ -1171,11 +1245,11 @@ namespace TerminalAppLocalTests VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"scheme_1", realArgs.TerminalArgs().Profile()); + VERIFY_ARE_EQUAL(L"Campbell PowerShell", realArgs.TerminalArgs().Profile()); } { - auto command = expandedCommands.Lookup(L"iterable command scheme_2"); + auto command = expandedCommands.Lookup(L"iterable command Vintage"); VERIFY_IS_NOT_NULL(command); auto actionAndArgs = command.ActionAndArgs(); VERIFY_IS_NOT_NULL(actionAndArgs); @@ -1189,7 +1263,7 @@ namespace TerminalAppLocalTests VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"scheme_2", realArgs.TerminalArgs().Profile()); + VERIFY_ARE_EQUAL(L"Vintage", realArgs.TerminalArgs().Profile()); } }