komuw / ote

ote updates a packages' go.mod file with a comment next to all dependencies that are test dependencies; identifying them as such.
MIT License
34 stars 0 forks source link

test-only require block should be added after the last require block #38

Closed komuw closed 3 years ago

komuw commented 3 years ago

After merging https://github.com/komuw/ote/pull/37 ; if you have a modfile like;

module testdata/mod1

require (
    github.com/frankban/quicktest v1.12.1
    github.com/go-ole/go-ole v1.2.5 // indirect
    github.com/shirou/gopsutil v2.20.9+incompatible //PriorComment
    rsc.io/quote v1.5.2
)

exclude golang.org/x/net v1.2.3

retract (
    v1.0.1 // Contains retractions only.
    v1.0.0 // Published accidentally.
)

ote produces a modfile like;

module testdata/mod1

require (
    github.com/go-ole/go-ole v1.2.5 // indirect
    rsc.io/quote v1.5.2
)

exclude golang.org/x/net v1.2.3

retract (
    v1.0.1 // Contains retractions only.
    v1.0.0 // Published accidentally.
)

require (
    github.com/frankban/quicktest v1.12.1 // test
    github.com/shirou/gopsutil v2.20.9+incompatible // test; PriorComment
)

ie, the require block of test-only dependencies is last. Instead it should come immediately after the last require block, ie; before the exclude

komuw commented 3 years ago

see: https://github.com/golang/mod/blob/0f08993efd8a8ec67e75bcccf86b0e1569b0ab0a/modfile/rule.go#L965-L1000

komuw commented 3 years ago

note; we do not have to do this. Even gotip/go1.17 does not organise the require block of indirect dependencies to be immediately after the require block of direct dependencies