Jan Mercl you right that only TestHello is broken, but it is still broken. 
As I said, the fact that such simple code in not portable is disturbing. I 
guess most of the code is tested on OS with English as the main language, 
at least code for this blog post seems to be, so you can guess what else 
may be broken but such silly bug? I guess not much, but this is still 
disturbing.

I have another problem, I don't understand what happened since version 1.13 
of Go with go.mod file. According to the post "Using Go Modules" 
https://go.dev/blog/using-go-modules "Only direct dependencies are recorded 
in the go.mod file". Today it seems that go.mod also list indirect 
dependencies, which is very good idea.

But I cannot understand why in the blog post we have in go.mod file
require rsc.io/quote v1.5.2
so "rsc.io/quote" is considered direct dependency, while go.mod produced by 
Go 1.20 give me
rsc.io/quote v1.5.2 // indirect
so now "rsc.io/quote" is indirect dependency, even when I write in package
import "rsc.io/quote"

I would be glad for any word of explanation.

Best regards,
Kamil

niedziela, 26 marca 2023 o 19:55:52 UTC+2 Jan Mercl napisał(a):

> 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 <kziem...@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/86f5e89b-f65b-4936-9d59-75192e8fa6d2n%40googlegroups.com.

Reply via email to