The only broken thing in the code below is the TestHello function.
rsc.io/quote uses rsc.io/sampler where the Hello func
(https://pkg.go.dev/rsc.io/sampler#Hello) is documented to return a
localized string by default. Localized, in the sense of respecting the
user's locale. That is not compatible with your test function
expecting to always get the same string regardless of locale. That's a
bug.

On Sun, Mar 26, 2023 at 7:47 PM Kamil Ziemian <kziemian...@gmail.com> wrote:

> According to the law that any change can break your program/workflow, I want 
> to mention that code shown in "Using Go Modules" 
> https://go.dev/blog/using-go-modules is broken in funny way.
>
> Consider code below
> package hello
>
> import "rsc.io/quote"
>
> func Hello() string {
>     return quote.Hello()
> }
>
> We also have test file
> package hello
>
> import "testing"
>
> func TestHello(t *testing.T) {
>     want := "Hello, world."
>     if got := Hello(); got != want {
>         t.Errorf("Hello() = %q, want %q", got, want)
>     }
> }
>
> So I run `go test' and get
> --- FAIL: TestHello (0.00s)
>     hello_test.go:9: Hello() = "Witaj świecie.", want "Hello, world."
> FAIL
> exit status 1
> FAIL example.com/hello 0.002s
>
> What happened? My first language is polish, so my system, Ubuntu 22.04, use 
> it as main language. In some way "rsc.io/quote" figure it out and now 
> function quote.Hello() returns "Witaj świecie.", which in polish mean "Hello, 
> world.". Since we compered result we get with string "Hello, world." we 
> obviously fail the test.
>
> This is just teaching example, so this is not so big deal, but fact that some 
> code of this type is not portable between OS with different languages is a 
> bit disturbing.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-UvP9FzMzUyTVzFdKnb%2BHo_zjnonvyUa%3DtchEWu7JV4Ug%40mail.gmail.com.

Reply via email to