Hi Kamil,

FWIW, you probably would be better off going through the official module
tutorials:

  "Tutorial: Get started with Go" --
https://go.dev/doc/tutorial/getting-started.html
  "Tutorial: Create a Go module" --
https://go.dev/doc/tutorial/create-module

Those are listed at the start of the official Go documentation page (
https://go.dev/doc/).

The blog posts you are going through and asking about are older (from 2019
or so, I think), and as such are snapshots in time to some degree.

The behavior of the 'go' tool has changed somewhat since those blog posts
were first published. Two notable examples of changes in behavior, which
might explain some of what you encountered:

--------------------------------------------------------------------------------
Go 1.16 release (https://go.dev/doc/go1.16#go-command)
--------------------------------------------------------------------------------
"Build commands like go build and go test no longer modify go.mod and
go.sum by default. Instead, they report an error if a module requirement or
checksum needs to be added or updated [...]. Module requirements and sums
may be adjusted with go mod tidy or go get."

--------------------------------------------------------------------------------
Go 1.17 release (https://go.dev/doc/go1.17#go-command)
--------------------------------------------------------------------------------
"[...] the go.mod file for each module needs to include more detail about
the transitive dependencies relevant to that module. If a module specifies
go 1.17 or higher in its go.mod file, its go.mod file now contains an
explicit require directive for every module that provides a
transitively-imported package. (In previous versions, the go.mod file
typically only included explicit requirements for directly-imported
packages.)"

FWIW, both of those changes were large improvements, and were heavily based
on feedback from the broader community.

Best regards,
thepudds


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

> 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 a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/p4YTbDqTUhI/unsubscribe.
> To unsubscribe from this group and all its topics, 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
> <https://groups.google.com/d/msgid/golang-nuts/86f5e89b-f65b-4936-9d59-75192e8fa6d2n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAPdK6PL53jLprzmUetmEbTcG1yv7G-uiRj%2Bf3-TycTBPgT6RkQ%40mail.gmail.com.

Reply via email to