Skip to content

Commit fec6951

Browse files
authored
Merge pull request #45815 from JuliaLang/sf/ko_kr_utf8
Clarify non-Unicode Korean tests
2 parents cce506f + c78a8db commit fec6951

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

stdlib/Dates/test/io.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ end
548548
@test Time("$t12", "$HH:MMp") == t
549549
end
550550
local tmstruct, strftime
551-
withlocales(["C"]) do
551+
withlocales(["C"]) do locale
552552
# test am/pm comparison handling
553553
tmstruct = Libc.strptime("%I:%M%p", t12)
554554
strftime = Libc.strftime("%I:%M%p", tmstruct)

test/misc.jl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -986,19 +986,28 @@ end
986986
@test_nowarn Core.eval(Main, :(import ....Main))
987987

988988
# issue #27239
989+
using Base.BinaryPlatforms: HostPlatform, libc
989990
@testset "strftime tests issue #27239" begin
990-
# change to non-Unicode Korean
991+
# change to non-Unicode Korean to test that it is properly transcoded into valid UTF-8
991992
korloc = ["ko_KR.EUC-KR", "ko_KR.CP949", "ko_KR.949", "Korean_Korea.949"]
992-
timestrs = String[]
993-
withlocales(korloc) do
994-
# system dependent formats
995-
push!(timestrs, Libc.strftime(0.0))
996-
push!(timestrs, Libc.strftime("%a %A %b %B %p %Z", 0))
993+
at_least_one_locale_found = false
994+
withlocales(korloc) do locale
995+
at_least_one_locale_found = true
996+
# Test both the default format and a custom formatting string
997+
for s in (Libc.strftime(0.0), Libc.strftime("%a %A %b %B %p %Z", 0))
998+
# Ensure that we always get valid UTF-8 back
999+
@test isvalid(s)
1000+
1001+
# On `musl` it is impossible for `setlocale` to fail, it just falls back to
1002+
# the default system locale, which on our buildbots is en_US.UTF-8. We'll
1003+
# assert that what we get does _not_ start with `Thu`, as that's what all
1004+
# en_US.UTF-8 encodings would start with.
1005+
# X-ref: https://musl.openwall.narkive.com/kO1vpTWJ/setlocale-behavior-with-missing-locales
1006+
@test !startswith(s, "Thu") broken=(libc(HostPlatform()) == "musl")
1007+
end
9971008
end
998-
# tests
999-
isempty(timestrs) && @warn "skipping stftime tests: no locale found for testing"
1000-
for s in timestrs
1001-
@test isvalid(s)
1009+
if !at_least_one_locale_found
1010+
@warn "skipping stftime tests: no locale found for testing"
10021011
end
10031012
end
10041013

test/testhelpers/withlocales.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ function withlocales(f, newlocales)
99
locales[cat] = unsafe_string(cstr)
1010
end
1111
end
12-
timestrs = String[]
1312
try
1413
# change to each of given locales
1514
for lc in newlocales
1615
set = true
1716
for (cat, _) in locales
1817
set &= ccall(:setlocale, Cstring, (Cint, Cstring), cat, lc) != C_NULL
1918
end
20-
set && f()
19+
set && f(lc)
2120
end
2221
finally
2322
# recover locales

0 commit comments

Comments
 (0)