From aa0d61fc562fed474d6bd72de6e9cf72ee83a0e7 Mon Sep 17 00:00:00 2001 From: kucherenkovova Date: Wed, 12 Jul 2023 22:48:56 +0300 Subject: [PATCH] record invocation arguments in generated code resolves [#554](https://github.com/golang/mock/issues/554) --- gomock/internal/mock_gomock/mock_matcher.go | 6 +++++- gomock/mock_test.go | 6 +++++- .../tests/aux_imports_embedded_interface/bugreport_mock.go | 6 +++++- mockgen/internal/tests/const_array_length/mock.go | 6 +++++- mockgen/internal/tests/copyright_file/mock.go | 6 +++++- .../tests/custom_package_name/greeter/greeter_mock_test.go | 6 +++++- mockgen/internal/tests/dot_imports/mock.go | 6 +++++- mockgen/internal/tests/empty_interface/mock.go | 6 +++++- mockgen/internal/tests/extra_import/mock.go | 6 +++++- .../tests/generated_identifier_conflict/bugreport_mock.go | 6 +++++- .../tests/import_embedded_interface/bugreport_mock.go | 6 +++++- .../internal/tests/import_embedded_interface/net_mock.go | 6 +++++- .../internal/tests/import_source/definition/source_mock.go | 6 +++++- mockgen/internal/tests/import_source/source_mock.go | 6 +++++- .../internal_pkg/subdir/internal/pkg/reflect_output/mock.go | 6 +++++- .../internal_pkg/subdir/internal/pkg/source_output/mock.go | 6 +++++- mockgen/internal/tests/missing_import/output/source_mock.go | 6 +++++- mockgen/internal/tests/mock_in_test_package/mock_test.go | 6 +++++- mockgen/internal/tests/overlapping_methods/mock.go | 6 +++++- mockgen/internal/tests/panicing_test/mock_test.go | 6 +++++- mockgen/internal/tests/self_package/mock.go | 6 +++++- mockgen/internal/tests/test_package/mock_test.go | 6 +++++- mockgen/internal/tests/unexported_method/bugreport_mock.go | 6 +++++- mockgen/internal/tests/vendor_dep/mock.go | 6 +++++- .../internal/tests/vendor_dep/source_mock_package/mock.go | 6 +++++- mockgen/internal/tests/vendor_pkg/mock.go | 6 +++++- mockgen/mockgen.go | 4 +++- sample/concurrent/mock/concurrent_mock.go | 6 +++++- sample/mock_user_test.go | 6 +++++- 29 files changed, 143 insertions(+), 29 deletions(-) diff --git a/gomock/internal/mock_gomock/mock_matcher.go b/gomock/internal/mock_gomock/mock_matcher.go index 6ba1f20..57e25a0 100644 --- a/gomock/internal/mock_gomock/mock_matcher.go +++ b/gomock/internal/mock_gomock/mock_matcher.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: go.uber.org/mock/gomock (interfaces: Matcher) - +// +// Generated by this command: +// +// mockgen -destination internal/mock_gomock/mock_matcher.go go.uber.org/mock/gomock Matcher +// // Package mock_gomock is a generated GoMock package. package mock_gomock diff --git a/gomock/mock_test.go b/gomock/mock_test.go index 03c5fd1..2206c60 100644 --- a/gomock/mock_test.go +++ b/gomock/mock_test.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: example_test.go - +// +// Generated by this command: +// +// mockgen -destination mock_test.go -package gomock_test -source example_test.go +// // Package gomock_test is a generated GoMock package. package gomock_test diff --git a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go index ea51e2a..f53bc2b 100644 --- a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go +++ b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: bugreport.go - +// +// Generated by this command: +// +// mockgen -aux_files faux=faux/faux.go -destination bugreport_mock.go -package bugreport -source=bugreport.go Example +// // Package bugreport is a generated GoMock package. package bugreport diff --git a/mockgen/internal/tests/const_array_length/mock.go b/mockgen/internal/tests/const_array_length/mock.go index b39fe8c..782c1a5 100644 --- a/mockgen/internal/tests/const_array_length/mock.go +++ b/mockgen/internal/tests/const_array_length/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: input.go - +// +// Generated by this command: +// +// mockgen -package const_length -destination mock.go -source input.go +// // Package const_length is a generated GoMock package. package const_length diff --git a/mockgen/internal/tests/copyright_file/mock.go b/mockgen/internal/tests/copyright_file/mock.go index cb77319..ff04142 100644 --- a/mockgen/internal/tests/copyright_file/mock.go +++ b/mockgen/internal/tests/copyright_file/mock.go @@ -7,7 +7,11 @@ // Code generated by MockGen. DO NOT EDIT. // Source: input.go - +// +// Generated by this command: +// +// mockgen -package empty_interface -destination mock.go -source input.go -copyright_file=mock_copyright_header +// // Package empty_interface is a generated GoMock package. package empty_interface diff --git a/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go b/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go index 2b020eb..50362c9 100644 --- a/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go +++ b/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: greeter.go - +// +// Generated by this command: +// +// mockgen -source greeter.go -destination greeter_mock_test.go -package greeter +// // Package greeter is a generated GoMock package. package greeter diff --git a/mockgen/internal/tests/dot_imports/mock.go b/mockgen/internal/tests/dot_imports/mock.go index dffee9d..bf02da8 100644 --- a/mockgen/internal/tests/dot_imports/mock.go +++ b/mockgen/internal/tests/dot_imports/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: input.go - +// +// Generated by this command: +// +// mockgen -package dot_imports -destination mock.go -source input.go +// // Package dot_imports is a generated GoMock package. package dot_imports diff --git a/mockgen/internal/tests/empty_interface/mock.go b/mockgen/internal/tests/empty_interface/mock.go index 13b9f30..56a0d24 100644 --- a/mockgen/internal/tests/empty_interface/mock.go +++ b/mockgen/internal/tests/empty_interface/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: input.go - +// +// Generated by this command: +// +// mockgen -package empty_interface -destination mock.go -source input.go +// // Package empty_interface is a generated GoMock package. package empty_interface diff --git a/mockgen/internal/tests/extra_import/mock.go b/mockgen/internal/tests/extra_import/mock.go index d3f6c53..3622083 100644 --- a/mockgen/internal/tests/extra_import/mock.go +++ b/mockgen/internal/tests/extra_import/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: go.uber.org/mock/mockgen/internal/tests/extra_import (interfaces: Foo) - +// +// Generated by this command: +// +// mockgen -destination mock.go -package extra_import . Foo +// // Package extra_import is a generated GoMock package. package extra_import diff --git a/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go b/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go index e188273..d819590 100644 --- a/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go +++ b/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: bugreport.go - +// +// Generated by this command: +// +// mockgen -destination bugreport_mock.go -package bugreport -source=bugreport.go +// // Package bugreport is a generated GoMock package. package bugreport diff --git a/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go b/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go index 2c482f5..54b559d 100644 --- a/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go +++ b/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: bugreport.go - +// +// Generated by this command: +// +// mockgen -destination bugreport_mock.go -package bugreport -source=bugreport.go +// // Package bugreport is a generated GoMock package. package bugreport diff --git a/mockgen/internal/tests/import_embedded_interface/net_mock.go b/mockgen/internal/tests/import_embedded_interface/net_mock.go index 401529d..abe13c6 100644 --- a/mockgen/internal/tests/import_embedded_interface/net_mock.go +++ b/mockgen/internal/tests/import_embedded_interface/net_mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: net.go - +// +// Generated by this command: +// +// mockgen -destination net_mock.go -package bugreport -source=net.go +// // Package bugreport is a generated GoMock package. package bugreport diff --git a/mockgen/internal/tests/import_source/definition/source_mock.go b/mockgen/internal/tests/import_source/definition/source_mock.go index 52a1be6..cb9bf18 100644 --- a/mockgen/internal/tests/import_source/definition/source_mock.go +++ b/mockgen/internal/tests/import_source/definition/source_mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: source.go - +// +// Generated by this command: +// +// mockgen -package source -destination source_mock.go -source=source.go +// // Package source is a generated GoMock package. package source diff --git a/mockgen/internal/tests/import_source/source_mock.go b/mockgen/internal/tests/import_source/source_mock.go index 1309a43..993813f 100644 --- a/mockgen/internal/tests/import_source/source_mock.go +++ b/mockgen/internal/tests/import_source/source_mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: source.go - +// +// Generated by this command: +// +// mockgen -destination ../source_mock.go -source=source.go +// // Package mock_source is a generated GoMock package. package mock_source diff --git a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go index 76892c1..f1139ee 100644 --- a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go +++ b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg (interfaces: Intf) - +// +// Generated by this command: +// +// mockgen -destination subdir/internal/pkg/reflect_output/mock.go go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg Intf +// // Package mock_pkg is a generated GoMock package. package mock_pkg diff --git a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go index 3cf24f8..33ee528 100644 --- a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go +++ b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: subdir/internal/pkg/input.go - +// +// Generated by this command: +// +// mockgen -source subdir/internal/pkg/input.go -destination subdir/internal/pkg/source_output/mock.go +// // Package mock_pkg is a generated GoMock package. package mock_pkg diff --git a/mockgen/internal/tests/missing_import/output/source_mock.go b/mockgen/internal/tests/missing_import/output/source_mock.go index 34f979d..4b31ab5 100644 --- a/mockgen/internal/tests/missing_import/output/source_mock.go +++ b/mockgen/internal/tests/missing_import/output/source_mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: source.go - +// +// Generated by this command: +// +// mockgen -package source -destination=../output/source_mock.go -source=source.go +// // Package source is a generated GoMock package. package source diff --git a/mockgen/internal/tests/mock_in_test_package/mock_test.go b/mockgen/internal/tests/mock_in_test_package/mock_test.go index 13fc812..43af998 100644 --- a/mockgen/internal/tests/mock_in_test_package/mock_test.go +++ b/mockgen/internal/tests/mock_in_test_package/mock_test.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: user.go - +// +// Generated by this command: +// +// mockgen --source=user.go --destination=mock_test.go --package=users_test +// // Package users_test is a generated GoMock package. package users_test diff --git a/mockgen/internal/tests/overlapping_methods/mock.go b/mockgen/internal/tests/overlapping_methods/mock.go index 1882380..b56e276 100644 --- a/mockgen/internal/tests/overlapping_methods/mock.go +++ b/mockgen/internal/tests/overlapping_methods/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: overlap.go - +// +// Generated by this command: +// +// mockgen -package overlap -destination mock.go -source overlap.go -aux_files go.uber.org/mock/mockgen/internal/tests/overlapping_methods=interfaces.go +// // Package overlap is a generated GoMock package. package overlap diff --git a/mockgen/internal/tests/panicing_test/mock_test.go b/mockgen/internal/tests/panicing_test/mock_test.go index 265227b..fb8c58e 100644 --- a/mockgen/internal/tests/panicing_test/mock_test.go +++ b/mockgen/internal/tests/panicing_test/mock_test.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: panic.go - +// +// Generated by this command: +// +// mockgen --source=panic.go --destination=mock_test.go --package=paniccode +// // Package paniccode is a generated GoMock package. package paniccode diff --git a/mockgen/internal/tests/self_package/mock.go b/mockgen/internal/tests/self_package/mock.go index 6600429..7aa6ddf 100644 --- a/mockgen/internal/tests/self_package/mock.go +++ b/mockgen/internal/tests/self_package/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: go.uber.org/mock/mockgen/internal/tests/self_package (interfaces: Methods) - +// +// Generated by this command: +// +// mockgen -package core -self_package go.uber.org/mock/mockgen/internal/tests/self_package -destination mock.go go.uber.org/mock/mockgen/internal/tests/self_package Methods +// // Package core is a generated GoMock package. package core diff --git a/mockgen/internal/tests/test_package/mock_test.go b/mockgen/internal/tests/test_package/mock_test.go index 05e66d2..6a7f100 100644 --- a/mockgen/internal/tests/test_package/mock_test.go +++ b/mockgen/internal/tests/test_package/mock_test.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: user_test.go - +// +// Generated by this command: +// +// mockgen --source=user_test.go --destination=mock_test.go --package=users_test +// // Package users_test is a generated GoMock package. package users_test diff --git a/mockgen/internal/tests/unexported_method/bugreport_mock.go b/mockgen/internal/tests/unexported_method/bugreport_mock.go index 305902e..99955ec 100644 --- a/mockgen/internal/tests/unexported_method/bugreport_mock.go +++ b/mockgen/internal/tests/unexported_method/bugreport_mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: bugreport.go - +// +// Generated by this command: +// +// mockgen -destination bugreport_mock.go -package bugreport -source=bugreport.go Example +// // Package bugreport is a generated GoMock package. package bugreport diff --git a/mockgen/internal/tests/vendor_dep/mock.go b/mockgen/internal/tests/vendor_dep/mock.go index 62c55c6..5d8a061 100644 --- a/mockgen/internal/tests/vendor_dep/mock.go +++ b/mockgen/internal/tests/vendor_dep/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: go.uber.org/mock/mockgen/internal/tests/vendor_dep (interfaces: VendorsDep) - +// +// Generated by this command: +// +// mockgen -package vendor_dep -destination mock.go go.uber.org/mock/mockgen/internal/tests/vendor_dep VendorsDep +// // Package vendor_dep is a generated GoMock package. package vendor_dep diff --git a/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go b/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go index c3f76d7..3312141 100644 --- a/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go +++ b/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: vendor_dep.go - +// +// Generated by this command: +// +// mockgen -destination source_mock_package/mock.go -source=vendor_dep.go +// // Package mock_vendor_dep is a generated GoMock package. package mock_vendor_dep diff --git a/mockgen/internal/tests/vendor_pkg/mock.go b/mockgen/internal/tests/vendor_pkg/mock.go index 53cc47d..9b6264c 100644 --- a/mockgen/internal/tests/vendor_pkg/mock.go +++ b/mockgen/internal/tests/vendor_pkg/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: golang.org/x/tools/present (interfaces: Elem) - +// +// Generated by this command: +// +// mockgen -destination mock.go -package vendor_pkg golang.org/x/tools/present Elem +// // Package vendor_pkg is a generated GoMock package. package vendor_pkg diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index d63470d..4409035 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -291,7 +291,9 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac g.p("// Source: %v (interfaces: %v)", g.srcPackage, g.srcInterfaces) } } - g.p("") + g.p("//") + g.p("// Generated by this command:") + g.p("// %v", strings.Join(os.Args, " ")) // Get all required imports, and generate unique names for them all. im := pkg.Imports() diff --git a/sample/concurrent/mock/concurrent_mock.go b/sample/concurrent/mock/concurrent_mock.go index 055fde7..31beb2e 100644 --- a/sample/concurrent/mock/concurrent_mock.go +++ b/sample/concurrent/mock/concurrent_mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: go.uber.org/mock/sample/concurrent (interfaces: Math) - +// +// Generated by this command: +// +// mockgen -destination mock/concurrent_mock.go go.uber.org/mock/sample/concurrent Math +// // Package mock_concurrent is a generated GoMock package. package mock_concurrent diff --git a/sample/mock_user_test.go b/sample/mock_user_test.go index 632928b..0967eea 100644 --- a/sample/mock_user_test.go +++ b/sample/mock_user_test.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: go.uber.org/mock/sample (interfaces: Index,Embed,Embedded) - +// +// Generated by this command: +// +// mockgen -destination mock_user_test.go -package user_test go.uber.org/mock/sample Index,Embed,Embedded +// // Package user_test is a generated GoMock package. package user_test