Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-02 Thread Miki Tebeka
Thanks. I ended up simplifying the test and remove the dependency on 
external packages.

On Sunday, November 1, 2020 at 11:42:43 PM UTC+2 kortschak wrote:

> Ah, it just clicked.
>
> You're indirectly using go/packages, which will (unless configured not
> to), cause changes to the go.mod and go.sum file. This configuration
> happens for this by adding "-mod=readonly" to
> packages.Config.BuildFlags (I think). But this isn't exposed via the
> go/analysis API (the config is populated here[1] where the user can't
> access it).
>
> This can be confirmed by seeing that building your checker, resetting
> the changes to go.mod and go.sum and then manually running the binary
> on your test cases.
>
> I'm not sure what to do about this.
>
> [1]
>
> https://github.com/golang/tools/blob/582c62ec74d06936c88d4b760c63cbc2925e69c7/go/analysis/internal/checker/checker.go#L152-L155
>
> On Sun, 2020-11-01 at 04:52 -0800, Miki Tebeka wrote:
> > I try to change the "go run" command to use "-mod=readonly", didn't
> > help.
> > 
> > On Sunday, November 1, 2020 at 10:23:07 AM UTC+2 kortschak wrote:
> > > You're using go test, with -mod=readonly, but it's running your
> > > code 
> > > with go run, without -mod=readonly. 
> > > 
> > > Either you'll need to unconditionally pass -mod=readonly to go run
> > > in 
> > > the regression_test.go file, or find wether it's been passed to go
> > > test 
> > > and then conditionally pass it to go run. 
> > > 
> > > 
> > > On Sun, 2020-11-01 at 01:09 -0700, Miki Tebeka wrote: 
> > > > I *do* use "go test", see 
> > > > https://github.com/tebeka/recheck/blob/master/regression_test.go 
> > > > 
> > > > On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 
> > > amits...@gmail.com 
> > > > wrote: 
> > > > > 
> > > > > On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka,  
> > > > > wrote: 
> > > > > > Hi, 
> > > > > > 
> > > > > > I wrote a regexp linter (https://github.com/tebeka/recheck) 
> > > > > > that's using golang.org/x/tools/go/analysis. 
> > > > > > 
> > > > > > To test the tool, I run "go run ./cmd/recheck
> > > testdata/ok.go" 
> > > > > > (using os/exec). The problem is that after the test, go.mod
> > > & 
> > > > > > go.sum are modified since there are some external imports in
> > > the 
> > > > > > go files under testdata. 
> > > > > > 
> > > > > > I've tried using -mod=readonly, building & then running,
> > > moving 
> > > > > > the test file to /tmp - all of them didn't work, the mod
> > > files 
> > > > > > are still changed after the test. 
> > > > > > 
> > > > > > Any idea how can I prevent the test from modifing the mod
> > > files? 
> > > > > 
> > > > > Your example above suggests you are not using go test to
> > > execute 
> > > > > your tests? 
> > > > > 
> > > > > > Thanks, 
> > > > > > Miki 
> > > 
> > > 
> > 
> > -- 
> > 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...@googlegroups.com.
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/golang-nuts/354542dc-0648-4383-98af-63ff4f7dabcfn%40googlegroups.com
> > .
>
>
>

-- 
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/b7229720-4cc1-4942-95f6-a4380401ca7en%40googlegroups.com.


Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-01 Thread 'Dan Kortschak' via golang-nuts
Ah, it just clicked.

You're indirectly using go/packages, which will (unless configured not
to), cause changes to the go.mod and go.sum file. This configuration
happens for this by adding "-mod=readonly" to
packages.Config.BuildFlags (I think). But this isn't exposed via the
go/analysis API (the config is populated here[1] where the user can't
access it).

This can be confirmed by seeing that building your checker, resetting
the changes to go.mod and go.sum and then manually running the binary
on your test cases.

I'm not sure what to do about this.

[1]
https://github.com/golang/tools/blob/582c62ec74d06936c88d4b760c63cbc2925e69c7/go/analysis/internal/checker/checker.go#L152-L155

On Sun, 2020-11-01 at 04:52 -0800, Miki Tebeka wrote:
> I try to change the "go run" command to use "-mod=readonly", didn't
> help.
> 
> On Sunday, November 1, 2020 at 10:23:07 AM UTC+2 kortschak wrote:
> > You're using go test, with -mod=readonly, but it's running your
> > code 
> > with go run, without -mod=readonly. 
> > 
> > Either you'll need to unconditionally pass -mod=readonly to go run
> > in 
> > the regression_test.go file, or find wether it's been passed to go
> > test 
> > and then conditionally pass it to go run. 
> > 
> > 
> > On Sun, 2020-11-01 at 01:09 -0700, Miki Tebeka wrote: 
> > > I *do* use "go test", see 
> > > https://github.com/tebeka/recheck/blob/master/regression_test.go 
> > > 
> > > On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 
> > amits...@gmail.com 
> > > wrote: 
> > > > 
> > > > On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka,  
> > > > wrote: 
> > > > > Hi, 
> > > > > 
> > > > > I wrote a regexp linter (https://github.com/tebeka/recheck) 
> > > > > that's using golang.org/x/tools/go/analysis. 
> > > > > 
> > > > > To test the tool, I run "go run ./cmd/recheck
> > testdata/ok.go" 
> > > > > (using os/exec). The problem is that after the test, go.mod
> > & 
> > > > > go.sum are modified since there are some external imports in
> > the 
> > > > > go files under testdata. 
> > > > > 
> > > > > I've tried using -mod=readonly, building & then running,
> > moving 
> > > > > the test file to /tmp - all of them didn't work, the mod
> > files 
> > > > > are still changed after the test. 
> > > > > 
> > > > > Any idea how can I prevent the test from modifing the mod
> > files? 
> > > > 
> > > > Your example above suggests you are not using go test to
> > execute 
> > > > your tests? 
> > > > 
> > > > > Thanks, 
> > > > > Miki 
> > 
> > 
> 
> -- 
> 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/354542dc-0648-4383-98af-63ff4f7dabcfn%40googlegroups.com
> .


-- 
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/8311ca8d52158493a088d88bef33ee93f82c6e7a.camel%40kortschak.io.


Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-01 Thread seank...@gmail.com
you're using the analysis packages which have dependencies on calling the 
go cmd internally
you could try passing readonly via GOFLAGS

the fact that your go.mod/go.sum changed means you should reevaluate what 
you're doing,
specifically you have an unversioned/untracked dependency on gorilla/mux 
via your testdata

as an aside, go1.16 readonly by default works (tested with tip)

On Sunday, November 1, 2020 at 6:26:17 PM UTC+1 ma...@eliasnaur.com wrote:

> On Sunday, 1 November 2020 at 13:52:34 UTC+1 miki@gmail.com wrote:
>
>> I try to change the "go run" command to use "-mod=readonly", didn't help.
>>
>  
> Drive-by comment in case you weren't aware: Go 1.16 is switching to 
> -mod=readonly
> by default. The proposal and links to the implementation are in
> https://github.com/golang/go/issues/40728.
>
> Hope it helps,
> Elias
>  
>

-- 
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/0eee972d-0ab7-4495-89eb-f4524da352bcn%40googlegroups.com.


Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-01 Thread ma...@eliasnaur.com
On Sunday, 1 November 2020 at 13:52:34 UTC+1 miki@gmail.com wrote:

> I try to change the "go run" command to use "-mod=readonly", didn't help.
>
 
Drive-by comment in case you weren't aware: Go 1.16 is switching to 
-mod=readonly
by default. The proposal and links to the implementation are in
https://github.com/golang/go/issues/40728.

Hope it helps,
Elias
 

-- 
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/9454a1ab-49e8-498e-a627-2fa628108fc6n%40googlegroups.com.


Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-01 Thread Miki Tebeka
I try to change the "go run" command to use "-mod=readonly", didn't help.

On Sunday, November 1, 2020 at 10:23:07 AM UTC+2 kortschak wrote:

> You're using go test, with -mod=readonly, but it's running your code
> with go run, without -mod=readonly.
>
> Either you'll need to unconditionally pass -mod=readonly to go run in
> the regression_test.go file, or find wether it's been passed to go test
> and then conditionally pass it to go run.
>
>
> On Sun, 2020-11-01 at 01:09 -0700, Miki Tebeka wrote:
> > I *do* use "go test", see 
> > https://github.com/tebeka/recheck/blob/master/regression_test.go
> > 
> > On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 amits...@gmail.com
> > wrote:
> > > 
> > > On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka, 
> > > wrote:
> > > > Hi,
> > > > 
> > > > I wrote a regexp linter (https://github.com/tebeka/recheck)
> > > > that's using golang.org/x/tools/go/analysis.
> > > > 
> > > > To test the tool, I run "go run ./cmd/recheck testdata/ok.go"
> > > > (using os/exec). The problem is that after the test, go.mod &
> > > > go.sum are modified since there are some external imports in the
> > > > go files under testdata.
> > > > 
> > > > I've tried using -mod=readonly, building & then running, moving
> > > > the test file to /tmp - all of them didn't work, the mod files
> > > > are still changed after the test.
> > > > 
> > > > Any idea how can I prevent the test from modifing the mod files?
> > > 
> > > Your example above suggests you are not using go test to execute
> > > your tests? 
> > > 
> > > > Thanks,
> > > > Miki
>
>
>

-- 
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/354542dc-0648-4383-98af-63ff4f7dabcfn%40googlegroups.com.


Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-01 Thread Amit Saha


> On 1 Nov 2020, at 7:22 pm, 'Dan Kortschak' via golang-nuts 
>  wrote:
> 
> You're using go test, with -mod=readonly, but it's running your code
> with go run, without -mod=readonly.
> 
> Either you'll need to unconditionally pass -mod=readonly to go run in
> the regression_test.go file, or find wether it's been passed to go test
> and then conditionally pass it to go run.
> 
> 
> On Sun, 2020-11-01 at 01:09 -0700, Miki Tebeka wrote:
>> I *do* use "go test", see 
>> https://github.com/tebeka/recheck/blob/master/regression_test.go

I am not sure I don’t see go test in there. But I think Dan already gave you a 
hint.


>> 
>> On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 amits...@gmail.com
>> wrote:
>>> 
>>> On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka, 
>>> wrote:
 Hi,
 
 I wrote a regexp linter (https://github.com/tebeka/recheck)
 that's using golang.org/x/tools/go/analysis.
 
 To test the tool, I run  "go run ./cmd/recheck testdata/ok.go"
 (using os/exec). The problem is that after the test, go.mod &
 go.sum are modified since there are some external imports in the
 go files under testdata.
 
 I've tried using -mod=readonly, building & then running, moving
 the test file to /tmp - all of them didn't work, the mod files
 are still changed after the test.
 
 Any idea how can I prevent the test from modifing the mod files?
>>> 
>>> Your example above suggests you are not using go test to execute
>>> your tests? 
>>> 
 Thanks,
 Miki
> 
> 
> -- 
> 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/80699bdc8a81f300b2b769ae7c8a40dbdead6d7d.camel%40kortschak.io
>  
> .

-- 
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/643937D0-4B19-4008-8999-7D7E63E0F5F3%40gmail.com.


Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-01 Thread 'Dan Kortschak' via golang-nuts
You're using go test, with -mod=readonly, but it's running your code
with go run, without -mod=readonly.

Either you'll need to unconditionally pass -mod=readonly to go run in
the regression_test.go file, or find wether it's been passed to go test
and then conditionally pass it to go run.


On Sun, 2020-11-01 at 01:09 -0700, Miki Tebeka wrote:
> I *do* use "go test", see 
> https://github.com/tebeka/recheck/blob/master/regression_test.go
> 
> On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 amits...@gmail.com
> wrote:
> > 
> > On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka, 
> > wrote:
> > > Hi,
> > > 
> > > I wrote a regexp linter (https://github.com/tebeka/recheck)
> > > that's using golang.org/x/tools/go/analysis.
> > > 
> > > To test the tool, I run  "go run ./cmd/recheck testdata/ok.go"
> > > (using os/exec). The problem is that after the test, go.mod &
> > > go.sum are modified since there are some external imports in the
> > > go files under testdata.
> > > 
> > > I've tried using -mod=readonly, building & then running, moving
> > > the test file to /tmp - all of them didn't work, the mod files
> > > are still changed after the test.
> > > 
> > > Any idea how can I prevent the test from modifing the mod files?
> > 
> > Your example above suggests you are not using go test to execute
> > your tests? 
> > 
> > > Thanks,
> > > Miki


-- 
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/80699bdc8a81f300b2b769ae7c8a40dbdead6d7d.camel%40kortschak.io.


Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-01 Thread Miki Tebeka
I *do* use "go test", 
see https://github.com/tebeka/recheck/blob/master/regression_test.go

On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 amits...@gmail.com wrote:

>
>
> On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka,  wrote:
>
>> Hi,
>>
>> I wrote a regexp linter (https://github.com/tebeka/recheck) that's using 
>> golang.org/x/tools/go/analysis.
>>
>> To test the tool, I run  "go run ./cmd/recheck testdata/ok.go" (using 
>> os/exec). The problem is that after the test, go.mod & go.sum are modified 
>> since there are some external imports in the go files under testdata.
>>
>> I've tried using -mod=readonly, building & then running, moving the test 
>> file to /tmp - all of them didn't work, the mod files are still changed 
>> after the test.
>>
>> Any idea how can I prevent the test from modifing the mod files?
>>
>
> Your example above suggests you are not using go test to execute your 
> tests? 
>
>
>> Thanks,
>> Miki
>>
>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/701453b4-eaa7-4a92-a8a1-520ae6d66fcfn%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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/bc16d6c7-131d-4666-9b01-2a41ba04c42bn%40googlegroups.com.


Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-10-31 Thread Amit Saha
On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka,  wrote:

> Hi,
>
> I wrote a regexp linter (https://github.com/tebeka/recheck) that's using
> golang.org/x/tools/go/analysis.
>
> To test the tool, I run  "go run ./cmd/recheck testdata/ok.go" (using
> os/exec). The problem is that after the test, go.mod & go.sum are modified
> since there are some external imports in the go files under testdata.
>
> I've tried using -mod=readonly, building & then running, moving the test
> file to /tmp - all of them didn't work, the mod files are still changed
> after the test.
>
> Any idea how can I prevent the test from modifing the mod files?
>

Your example above suggests you are not using go test to execute your
tests?


> Thanks,
> Miki
>
> --
> 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/701453b4-eaa7-4a92-a8a1-520ae6d66fcfn%40googlegroups.com
> 
> .
>

-- 
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/CANODV3my9Dc3t5PkdkSX8RM3PJ65PxByyn5e%2Bj1G-tP%2BGu_Mgg%40mail.gmail.com.