Text file src/cmd/go/testdata/script/mod_all.txt

     1  # This test illustrates the relationship between the 'all' pattern and
     2  # the dependencies of the main module.
     3  
     4  # The package import graph used in this test looks like:
     5  #
     6  # main --------- a --------- b
     7  # |              |
     8  # |              a_test ---- c
     9  # |                          |
    10  # |                          c_test ---- d
    11  # |
    12  # main_test ---- t --------- u
    13  #                |
    14  #                t_test ---- w
    15  #                            |
    16  #                            w_test ---- x
    17  #
    18  # main/testonly_test ---- q --------- r
    19  #                         |
    20  #                         q_test ---- s
    21  #
    22  # And the module dependency graph looks like:
    23  #
    24  # main --- a.1 ---- b.1
    25  #  \   \    \
    26  #   \   \    c.1 -- d.1
    27  #    \   \
    28  #     \    t.1 ---- u.1
    29  #      \    \
    30  #       \    w.1 -- x.1
    31  #        \
    32  #          q.1 ---- r.1
    33  #           \
    34  #            s.1
    35  
    36  env PKGFMT='{{if .Module}}{{.ImportPath}}{{end}}'
    37  env MODFMT='{{.Path}}'
    38  
    39  
    40  # 'go list -deps' lists packages and tests in the main module,
    41  # along with their transitive dependencies.
    42  
    43  go list -f $PKGFMT -deps ./...
    44  stdout -count=4 '^.'
    45  stdout '^example.com/a$'
    46  stdout '^example.com/b$'
    47  stdout '^example.com/main$'
    48  stdout '^example.com/main/testonly'
    49  
    50  
    51  # 'go list -deps -test' lists transitive imports of tests and non-tests in the
    52  # main module.
    53  
    54  go list -f $PKGFMT -deps -test ./...
    55  stdout -count=13 '^.'
    56  stdout '^example.com/a$'
    57  stdout '^example.com/b$'
    58  stdout '^example.com/main$'
    59  stdout '^example.com/main.test$'
    60  stdout '^example.com/main \[example.com/main.test\]$'
    61  stdout '^example.com/main_test \[example.com/main.test\]$'
    62  stdout '^example.com/main/testonly$'
    63  stdout '^example.com/main/testonly.test$'
    64  stdout '^example.com/main/testonly_test \[example.com/main/testonly.test\]$'
    65  stdout '^example.com/q$'
    66  stdout '^example.com/r$'
    67  stdout '^example.com/t$'
    68  stdout '^example.com/u$'
    69  
    70  
    71  # 'go list all' lists the fixpoint of iterating 'go list -deps -test' starting
    72  # with the packages in the main module, then reducing to only the non-test
    73  # variants of those packages.
    74  
    75  go list -f $PKGFMT all
    76  stdout -count=13 '^.'
    77  stdout '^example.com/a$'
    78  stdout '^example.com/b$'
    79  stdout '^example.com/c$'
    80  stdout '^example.com/d$'
    81  stdout '^example.com/main$'
    82  stdout '^example.com/main/testonly$'
    83  stdout '^example.com/q$'
    84  stdout '^example.com/r$'
    85  stdout '^example.com/s$'
    86  stdout '^example.com/t$'
    87  stdout '^example.com/u$'
    88  stdout '^example.com/w$'
    89  stdout '^example.com/x$'
    90  
    91  
    92  # 'go list -test all' is equivalent to 'go list -test $(go list all)'
    93  # and both should include tests for every package in 'all'.
    94  
    95  go list -test -f $PKGFMT example.com/a example.com/b example.com/c example.com/d example.com/main example.com/main/testonly example.com/q example.com/r example.com/s example.com/t example.com/u example.com/w example.com/x
    96  cp stdout list-test-explicit.txt
    97  
    98  go list -test -f $PKGFMT all
    99  cmp stdout list-test-explicit.txt
   100  stdout -count=36 '^.'
   101  stdout '^example.com/a$'
   102  stdout '^example.com/b$'
   103  stdout '^example.com/c$'
   104  stdout '^example.com/d$'
   105  stdout '^example.com/main$'
   106  stdout '^example.com/main/testonly$'
   107  stdout '^example.com/q$'
   108  stdout '^example.com/r$'
   109  stdout '^example.com/s$'
   110  stdout '^example.com/t$'
   111  stdout '^example.com/u$'
   112  stdout '^example.com/w$'
   113  stdout '^example.com/x$'
   114  stdout '^example.com/a.test$'
   115  stdout '^example.com/a_test \[example.com/a.test\]$'
   116  stdout '^example.com/b.test$'
   117  stdout '^example.com/b_test \[example.com/b.test\]$'
   118  stdout '^example.com/c.test$'
   119  stdout '^example.com/c_test \[example.com/c.test\]$'
   120  stdout '^example.com/main.test$'
   121  stdout '^example.com/main \[example.com/main.test\]$'
   122  stdout '^example.com/main_test \[example.com/main.test\]$'
   123  stdout '^example.com/main/testonly.test$'
   124  stdout '^example.com/main/testonly_test \[example.com/main/testonly.test\]$'
   125  stdout '^example.com/q.test$'
   126  stdout '^example.com/q_test \[example.com/q.test\]$'
   127  stdout '^example.com/r.test$'
   128  stdout '^example.com/r_test \[example.com/r.test\]$'
   129  stdout '^example.com/s.test$'
   130  stdout '^example.com/s_test \[example.com/s.test\]$'
   131  stdout '^example.com/t.test$'
   132  stdout '^example.com/t_test \[example.com/t.test\]$'
   133  stdout '^example.com/u.test$'
   134  stdout '^example.com/u_test \[example.com/u.test\]$'
   135  stdout '^example.com/w.test$'
   136  stdout '^example.com/w_test \[example.com/w.test\]$'
   137  
   138  
   139  # 'go list -m all' covers the packages in 'go list -test -deps all'.
   140  
   141  go list -m -f $MODFMT all
   142  stdout -count=12 '^.'
   143  stdout '^example.com/a$'
   144  stdout '^example.com/b$'
   145  stdout '^example.com/c$'
   146  stdout '^example.com/d$'
   147  stdout '^example.com/main$'
   148  stdout '^example.com/q$'
   149  stdout '^example.com/r$'
   150  stdout '^example.com/s$'
   151  stdout '^example.com/t$'
   152  stdout '^example.com/u$'
   153  stdout '^example.com/w$'
   154  stdout '^example.com/x$'
   155  
   156  
   157  # 'go mod vendor' copies in only the packages transitively imported by the main
   158  # module, and omits their tests. As a result, the 'all' and '...' patterns
   159  # report fewer packages when using '-mod=vendor'.
   160  
   161  go mod vendor
   162  
   163  go list -f $PKGFMT -mod=vendor all
   164  stdout -count=8 '^.'
   165  stdout '^example.com/a$'
   166  stdout '^example.com/b$'
   167  stdout '^example.com/main$'
   168  stdout '^example.com/main/testonly$'
   169  stdout '^example.com/q$'
   170  stdout '^example.com/r$'
   171  stdout '^example.com/t$'
   172  stdout '^example.com/u$'
   173  
   174  go list -test -f $PKGFMT -mod=vendor all
   175  stdout -count=13 '^.'
   176  stdout '^example.com/a$'
   177  stdout '^example.com/b$'
   178  stdout '^example.com/main$'
   179  stdout '^example.com/main/testonly$'
   180  stdout '^example.com/q$'
   181  stdout '^example.com/r$'
   182  stdout '^example.com/t$'
   183  stdout '^example.com/u$'
   184  stdout '^example.com/main.test$'
   185  stdout '^example.com/main \[example.com/main.test\]$'
   186  stdout '^example.com/main_test \[example.com/main.test\]$'
   187  stdout '^example.com/main/testonly.test$'
   188  stdout '^example.com/main/testonly_test \[example.com/main/testonly.test\]$'
   189  
   190  rm vendor
   191  
   192  # Convert all modules to go 1.17 to enable lazy loading.
   193  go mod edit -go=1.17 a/go.mod
   194  go mod edit -go=1.17 b/go.mod
   195  go mod edit -go=1.17 c/go.mod
   196  go mod edit -go=1.17 d/go.mod
   197  go mod edit -go=1.17 q/go.mod
   198  go mod edit -go=1.17 r/go.mod
   199  go mod edit -go=1.17 s/go.mod
   200  go mod edit -go=1.17 t/go.mod
   201  go mod edit -go=1.17 u/go.mod
   202  go mod edit -go=1.17 w/go.mod
   203  go mod edit -go=1.17 x/go.mod
   204  go mod edit -go=1.17
   205  cmp go.mod go.mod.beforetidy
   206  go mod tidy
   207  cmp go.mod go.mod.aftertidy
   208  
   209  # With lazy loading, 'go list all' with neither -mod=vendor nor -test should
   210  # match -mod=vendor without -test in 1.15.
   211  
   212  go list -f $PKGFMT all
   213  stdout -count=8 '^.'
   214  stdout '^example.com/a$'
   215  stdout '^example.com/b$'
   216  stdout '^example.com/main$'
   217  stdout '^example.com/main/testonly$'
   218  stdout '^example.com/q$'
   219  stdout '^example.com/r$'
   220  stdout '^example.com/t$'
   221  stdout '^example.com/u$'
   222  
   223  # 'go list -test all' should expand that to include the test variants of the
   224  # packages in 'all', but not the dependencies of outside tests.
   225  
   226  go list -test -f $PKGFMT all
   227  stdout -count=25 '^.'
   228  stdout '^example.com/a$'
   229  stdout '^example.com/b$'
   230  stdout '^example.com/main$'
   231  stdout '^example.com/main/testonly$'
   232  stdout '^example.com/q$'
   233  stdout '^example.com/r$'
   234  stdout '^example.com/t$'
   235  stdout '^example.com/u$'
   236  stdout '^example.com/a.test$'
   237  stdout '^example.com/a_test \[example.com/a.test\]$'
   238  stdout '^example.com/b.test$'
   239  stdout '^example.com/b_test \[example.com/b.test\]$'
   240  stdout '^example.com/main.test$'
   241  stdout '^example.com/main \[example.com/main.test\]$'
   242  stdout '^example.com/main_test \[example.com/main.test\]$'
   243  stdout '^example.com/main/testonly.test$'
   244  stdout '^example.com/main/testonly_test \[example.com/main/testonly.test\]$'
   245  stdout '^example.com/q.test$'
   246  stdout '^example.com/q_test \[example.com/q.test\]$'
   247  stdout '^example.com/r.test$'
   248  stdout '^example.com/r_test \[example.com/r.test\]$'
   249  stdout '^example.com/t.test$'
   250  stdout '^example.com/t_test \[example.com/t.test\]$'
   251  stdout '^example.com/u.test$'
   252  stdout '^example.com/u_test \[example.com/u.test\]$'
   253  
   254  # 'go list -test -deps all' should include the dependencies of those tests,
   255  # but not the tests of the dependencies of outside tests.
   256  
   257  go list -test -deps -f $PKGFMT all
   258  stdout -count=28 '^.'
   259  stdout '^example.com/a$'
   260  stdout '^example.com/b$'
   261  stdout '^example.com/c$'
   262  stdout '^example.com/main$'
   263  stdout '^example.com/main/testonly$'
   264  stdout '^example.com/q$'
   265  stdout '^example.com/r$'
   266  stdout '^example.com/s$'
   267  stdout '^example.com/t$'
   268  stdout '^example.com/u$'
   269  stdout '^example.com/w$'
   270  stdout '^example.com/a.test$'
   271  stdout '^example.com/a_test \[example.com/a.test\]$'
   272  stdout '^example.com/b.test$'
   273  stdout '^example.com/b_test \[example.com/b.test\]$'
   274  stdout '^example.com/main.test$'
   275  stdout '^example.com/main \[example.com/main.test\]$'
   276  stdout '^example.com/main_test \[example.com/main.test\]$'
   277  stdout '^example.com/main/testonly.test$'
   278  stdout '^example.com/main/testonly_test \[example.com/main/testonly.test\]$'
   279  stdout '^example.com/q.test$'
   280  stdout '^example.com/q_test \[example.com/q.test\]$'
   281  stdout '^example.com/r.test$'
   282  stdout '^example.com/r_test \[example.com/r.test\]$'
   283  stdout '^example.com/t.test$'
   284  stdout '^example.com/t_test \[example.com/t.test\]$'
   285  stdout '^example.com/u.test$'
   286  stdout '^example.com/u_test \[example.com/u.test\]$'
   287  
   288  # 'go list -m all' should cover all of the modules providing packages in
   289  # 'go list -test -deps all', but should exclude modules d and x,
   290  # which are not relevant to the main module and are outside of the
   291  # lazy-loading horizon.
   292  
   293  go list -m -f $MODFMT all
   294  stdout -count=10 '^.'
   295  stdout '^example.com/a$'
   296  stdout '^example.com/b$'
   297  stdout '^example.com/c$'
   298  ! stdout '^example.com/d$'
   299  stdout '^example.com/main$'
   300  stdout '^example.com/q$'
   301  stdout '^example.com/r$'
   302  stdout '^example.com/s$'
   303  stdout '^example.com/t$'
   304  stdout '^example.com/u$'
   305  stdout '^example.com/w$'
   306  ! stdout '^example.com/x$'
   307  
   308  -- go.mod --
   309  module example.com/main
   310  
   311  // Note: this go.mod file initially specifies go 1.15,
   312  // but includes some redundant roots so that it
   313  // also already obeys the 1.17 lazy loading invariants.
   314  go 1.15
   315  
   316  require (
   317  	example.com/a v0.1.0
   318  	example.com/b v0.1.0 // indirect
   319  	example.com/q v0.1.0
   320  	example.com/r v0.1.0 // indirect
   321  	example.com/t v0.1.0
   322  	example.com/u v0.1.0 // indirect
   323  )
   324  
   325  replace (
   326  	example.com/a v0.1.0 => ./a
   327  	example.com/b v0.1.0 => ./b
   328  	example.com/c v0.1.0 => ./c
   329  	example.com/d v0.1.0 => ./d
   330  	example.com/q v0.1.0 => ./q
   331  	example.com/r v0.1.0 => ./r
   332  	example.com/s v0.1.0 => ./s
   333  	example.com/t v0.1.0 => ./t
   334  	example.com/u v0.1.0 => ./u
   335  	example.com/w v0.1.0 => ./w
   336  	example.com/x v0.1.0 => ./x
   337  )
   338  -- main.go --
   339  package main
   340  
   341  import _ "example.com/a"
   342  
   343  func main() {}
   344  -- main_test.go --
   345  package main_test
   346  
   347  import _ "example.com/t"
   348  -- testonly/testonly_test.go --
   349  package testonly_test
   350  
   351  import _ "example.com/q"
   352  -- a/go.mod --
   353  module example.com/a
   354  
   355  go 1.15
   356  
   357  require (
   358  	example.com/b v0.1.0
   359  	example.com/c v0.1.0
   360  )
   361  -- a/a.go --
   362  package a
   363  
   364  import _ "example.com/b"
   365  -- a/a_test.go --
   366  package a_test
   367  
   368  import _ "example.com/c"
   369  -- b/go.mod --
   370  module example.com/b
   371  
   372  go 1.15
   373  -- b/b.go --
   374  package b
   375  -- b/b_test.go --
   376  package b_test
   377  -- c/go.mod --
   378  module example.com/c
   379  
   380  go 1.15
   381  
   382  require example.com/d v0.1.0
   383  -- c/c.go --
   384  package c
   385  -- c/c_test.go --
   386  package c_test
   387  
   388  import _ "example.com/d"
   389  -- d/go.mod --
   390  module example.com/d
   391  
   392  go 1.15
   393  -- d/d.go --
   394  package d
   395  -- q/go.mod --
   396  module example.com/q
   397  
   398  go 1.15
   399  
   400  require (
   401  	example.com/r v0.1.0
   402  	example.com/s v0.1.0
   403  )
   404  -- q/q.go --
   405  package q
   406  import _ "example.com/r"
   407  -- q/q_test.go --
   408  package q_test
   409  import _ "example.com/s"
   410  -- r/go.mod --
   411  module example.com/r
   412  
   413  go 1.15
   414  -- r/r.go --
   415  package r
   416  -- r/r_test.go --
   417  package r_test
   418  -- s/go.mod --
   419  module example.com/s
   420  
   421  go 1.15
   422  -- s/s.go --
   423  package s
   424  -- s/s_test.go --
   425  package s_test
   426  -- t/go.mod --
   427  module example.com/t
   428  
   429  go 1.15
   430  
   431  require (
   432  	example.com/u v0.1.0
   433  	example.com/w v0.1.0
   434  )
   435  -- t/t.go --
   436  package t
   437  
   438  import _ "example.com/u"
   439  -- t/t_test.go --
   440  package t_test
   441  
   442  import _ "example.com/w"
   443  -- u/go.mod --
   444  module example.com/u
   445  
   446  go 1.15
   447  -- u/u.go --
   448  package u
   449  -- u/u_test.go --
   450  package u_test
   451  -- w/go.mod --
   452  module example.com/w
   453  
   454  go 1.15
   455  
   456  require example.com/x v0.1.0
   457  -- w/w.go --
   458  package w
   459  -- w/w_test.go --
   460  package w_test
   461  
   462  import _ "example.com/x"
   463  -- x/go.mod --
   464  module example.com/x
   465  
   466  go 1.15
   467  -- x/x.go --
   468  package x
   469  -- go.mod.beforetidy --
   470  module example.com/main
   471  
   472  // Note: this go.mod file initially specifies go 1.15,
   473  // but includes some redundant roots so that it
   474  // also already obeys the 1.17 lazy loading invariants.
   475  go 1.17
   476  
   477  require (
   478  	example.com/a v0.1.0
   479  	example.com/b v0.1.0 // indirect
   480  	example.com/q v0.1.0
   481  	example.com/r v0.1.0 // indirect
   482  	example.com/t v0.1.0
   483  	example.com/u v0.1.0 // indirect
   484  )
   485  
   486  replace (
   487  	example.com/a v0.1.0 => ./a
   488  	example.com/b v0.1.0 => ./b
   489  	example.com/c v0.1.0 => ./c
   490  	example.com/d v0.1.0 => ./d
   491  	example.com/q v0.1.0 => ./q
   492  	example.com/r v0.1.0 => ./r
   493  	example.com/s v0.1.0 => ./s
   494  	example.com/t v0.1.0 => ./t
   495  	example.com/u v0.1.0 => ./u
   496  	example.com/w v0.1.0 => ./w
   497  	example.com/x v0.1.0 => ./x
   498  )
   499  -- go.mod.aftertidy --
   500  module example.com/main
   501  
   502  // Note: this go.mod file initially specifies go 1.15,
   503  // but includes some redundant roots so that it
   504  // also already obeys the 1.17 lazy loading invariants.
   505  go 1.17
   506  
   507  require (
   508  	example.com/a v0.1.0
   509  	example.com/q v0.1.0
   510  	example.com/t v0.1.0
   511  )
   512  
   513  require (
   514  	example.com/b v0.1.0 // indirect
   515  	example.com/r v0.1.0 // indirect
   516  	example.com/u v0.1.0 // indirect
   517  )
   518  
   519  replace (
   520  	example.com/a v0.1.0 => ./a
   521  	example.com/b v0.1.0 => ./b
   522  	example.com/c v0.1.0 => ./c
   523  	example.com/d v0.1.0 => ./d
   524  	example.com/q v0.1.0 => ./q
   525  	example.com/r v0.1.0 => ./r
   526  	example.com/s v0.1.0 => ./s
   527  	example.com/t v0.1.0 => ./t
   528  	example.com/u v0.1.0 => ./u
   529  	example.com/w v0.1.0 => ./w
   530  	example.com/x v0.1.0 => ./x
   531  )
   532  

View as plain text