Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/shared/inc/stringshared.h
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ struct std::formatter<char*, wchar_t>
template <typename TCtx>
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));
}
};

Expand All @@ -1269,7 +1269,7 @@ struct std::formatter<const char*, wchar_t>
template <typename TCtx>
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));
}
};

Expand All @@ -1285,7 +1285,7 @@ struct std::formatter<char[N], wchar_t>
template <typename TCtx>
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));
}
};

Expand All @@ -1301,7 +1301,7 @@ struct std::formatter<std::basic_string<char, Traits, Allocator>, wchar_t>
template <typename TCtx>
auto format(const std::basic_string<char, Traits, Allocator>& 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));
}
};

Expand Down
8 changes: 8 additions & 0 deletions test/windows/StringUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<LPCSTR, std::optional<uint64_t>>> TestCases{
Expand Down
14 changes: 14 additions & 0 deletions test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down