diff --git a/src/shared/inc/stringshared.h b/src/shared/inc/stringshared.h index a41634b34..c46dec0c3 100644 --- a/src/shared/inc/stringshared.h +++ b/src/shared/inc/stringshared.h @@ -1253,7 +1253,7 @@ struct std::formatter template auto format(const char* str, TCtx& ctx) const { - return std::format_to(ctx.out(), "{}", wsl::shared::string::MultiByteToWide(str)); + return std::format_to(ctx.out(), L"{}", wsl::shared::string::MultiByteToWide(str)); } }; @@ -1269,7 +1269,7 @@ struct std::formatter template auto format(const char* str, TCtx& ctx) const { - return std::format_to(ctx.out(), "{}", wsl::shared::string::MultiByteToWide(str)); + return std::format_to(ctx.out(), L"{}", wsl::shared::string::MultiByteToWide(str)); } }; @@ -1285,7 +1285,7 @@ struct std::formatter template auto format(const char str[N], TCtx& ctx) const { - return std::format_to(ctx.out(), "{}", wsl::shared::string::MultiByteToWide(str)); + return std::format_to(ctx.out(), L"{}", wsl::shared::string::MultiByteToWide(str)); } }; @@ -1301,7 +1301,7 @@ struct std::formatter, wchar_t> template auto format(const std::basic_string& str, TCtx& ctx) const { - return std::format_to(ctx.out(), "{}", wsl::shared::string::MultiByteToWide(str)); + return std::format_to(ctx.out(), L"{}", wsl::shared::string::MultiByteToWide(str)); } }; diff --git a/test/windows/StringUnitTests.cpp b/test/windows/StringUnitTests.cpp index 6a66cd903..593228364 100644 --- a/test/windows/StringUnitTests.cpp +++ b/test/windows/StringUnitTests.cpp @@ -77,6 +77,14 @@ class StringUnitTests { WSL_TEST_CLASS(StringUnitTests) + TEST_METHOD(FormatUtf8StringAsWideString) + { + const std::string input{"安装依赖"}; + const auto expected = wsl::shared::string::MultiByteToWide(input); + + VERIFY_ARE_EQUAL(expected, std::format(L"{}", input)); + } + TEST_METHOD(ParseMemorySize_LegacyForms) { const std::vector>> TestCases{ diff --git a/test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp b/test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp index f0c76ae46..f9b0055d2 100644 --- a/test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp +++ b/test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp @@ -119,6 +119,20 @@ class WSLCE2EImageBuildTests VERIFY_ARE_EQUAL(BuiltImage.NameAndTag(), wsl::shared::string::MultiByteToWide(inspectData.RepoTags.value()[0])); } + WSLC_TEST_METHOD(WSLCE2E_Image_Build_UnicodeOutput_Success) + { + auto testRoot = std::filesystem::current_path() / L"wslc-e2e-build-unicode-output"; + auto cleanup = SetupTestDirectory(testRoot); + + auto dockerfilePath = testRoot / L"Dockerfile"; + WriteTestFileContent(dockerfilePath, "FROM debian:latest\nRUN echo 安装依赖\n"); + + auto buildResult = RunWslc(std::format( + L"build \"{}\" -f \"{}\" --output type=cacheonly", SharedOutputBuildContext().wstring(), dockerfilePath.wstring())); + buildResult.Verify({.ExitCode = 0}); + VERIFY_IS_TRUE(buildResult.StderrContainsSubstring(wsl::shared::string::MultiByteToWide("安装依赖"))); + } + WSLC_TEST_METHOD(WSLCE2E_Image_Build_BuildArgsFileAndMultipleTags_Success) { auto imageCleanup1 = DeleteImageOnExit(BuiltImageTag1);