[インデックス 11759] ファイルの概要
コミット
commit 7ef97def800fc155c3bdc9e84c0af7f6d786ee7b
Author: Rob Pike <r@golang.org>
Date: Fri Feb 10 13:49:50 2012 +1100
testing: fix references to "gotest"
Fixes #2958.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5650050
GitHub上でのコミットページへのリンク
https://github.com/golang/go/commit/7ef97def800fc155c3bdc9e84c0af7f6d786ee7b
元コミット内容
testing: fix references to "gotest"
このコミットは、Go言語の標準ライブラリであるtesting
パッケージ内のドキュメントやコメントにおいて、「gotest」という記述を修正することを目的としています。具体的には、Goのテスト実行コマンドの正式名称である「go test」に統一するための変更です。
変更の背景
Go言語のテストは、go test
コマンドによって実行されます。しかし、初期のGoのドキュメントやコードベースの一部では、このコマンドが非公式に「gotest」と記述されることがありました。このコミットは、このような非公式な記述を、公式かつ一貫性のある「go test」という表現に統一することを目的としています。
この変更は、Goのツールチェインにおける用語の標準化と明確化の一環として行われました。特に、testing
パッケージはGoのテストフレームワークの根幹をなすため、そのドキュメントや内部コメントにおける用語の正確性は非常に重要です。Issue #2958がこの修正の背景にある問題を示しています。
前提知識の解説
Go言語のテストとベンチマーク
Go言語には、標準ライブラリとしてtesting
パッケージが提供されており、これを用いてユニットテスト、ベンチマークテスト、およびサンプルコードのテストを記述・実行できます。
- ユニットテスト:
func TestXxx(t *testing.T)
という形式の関数で記述され、コードの個々の単位(関数、メソッドなど)が正しく動作するかを検証します。 - ベンチマークテスト:
func BenchmarkXxx(b *testing.B)
という形式の関数で記述され、コードのパフォーマンスを測定します。testing.B
型は、ベンチマークの実行回数を自動的に調整し、安定した測定結果を得るための機能を提供します。 go test
コマンド: Goのテストを実行するための公式コマンドです。プロジェクトのルートディレクトリでgo test
を実行すると、カレントディレクトリとそのサブディレクトリにあるすべてのテストファイル(_test.go
で終わるファイル)を自動的に検出し、テストを実行します。ベンチマークテストを実行するには、-test.bench
フラグを使用します(例:go test -test.bench=.
)。
「gotest」と「go test」
Goの歴史において、「go test」は常にテストを実行するための公式かつ標準的なコマンドでした。一方で、「gotest」という表現は、非公式な略称や、初期のドキュメントにおける誤記、あるいはコミュニティ内での俗称として使われることがありました。このコミットが行われた2012年当時、Goはまだ比較的新しい言語であり、このような用語の統一は、ドキュメントの正確性を高め、ユーザーの混乱を防ぐ上で重要な意味を持っていました。
現在のGoの公式ドキュメントやツールチェインでは、「gotest」という単独のコマンドやツールは存在せず、「go test」が唯一のテスト実行コマンドとして認識されています。
技術的詳細
このコミットは、src/pkg/testing/benchmark.go
とsrc/pkg/testing/testing.go
の2つのファイルに対して行われています。変更内容は、主にコメントや文字列リテラル内の「gotest」という記述を「go test」または「the "go test" command」に置き換えることです。これはコードの振る舞いを変更するものではなく、ドキュメントの正確性と一貫性を向上させるための修正です。
具体的には、testing
パッケージの内部構造や、InternalBenchmark
、RunBenchmarks
、Benchmark
、InternalTest
、Main
といった関数や型の説明文において、テスト実行の主体が「gotest」ではなく「go test」コマンドであることを明確にしています。
コアとなるコードの変更箇所
diff --git a/src/pkg/testing/benchmark.go b/src/pkg/testing/benchmark.go
index 0bf567b7c4..41290594ee 100644
--- a/src/pkg/testing/benchmark.go
+++ b/src/pkg/testing/benchmark.go
@@ -16,7 +16,7 @@ var matchBenchmarks = flag.String("test.bench", "", "regular expression to selec
var benchTime = flag.Float64("test.benchtime", 1, "approximate run time for each benchmark, in seconds")
// An internal type but exported because it is cross-package; part of the implementation
-// of gotest.
+// of the "go test" command.
type InternalBenchmark struct {
Name string
F func(b *B)
@@ -213,7 +213,7 @@ func (r BenchmarkResult) String() string {
}
// An internal function but exported because it is cross-package; part of the implementation
-// of gotest.
+// of the "go test" command.
func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) {
// If no flag was specified, don't run benchmarks.
if len(*matchBenchmarks) == 0 {
@@ -281,7 +281,7 @@ func (b *B) trimOutput() {
}
// Benchmark benchmarks a single function. Useful for creating
-// custom benchmarks that do not use gotest.
+// custom benchmarks that do not use the "go test" command.
func Benchmark(f func(b *B)) BenchmarkResult {
b := &B{
common: common{
diff --git a/src/pkg/testing/testing.go b/src/pkg/testing/testing.go
index 68ecebb36f..d907843c91 100644
--- a/src/pkg/testing/testing.go
+++ b/src/pkg/testing/testing.go
@@ -12,8 +12,8 @@
//
// Functions of the form
// func BenchmarkXxx(*testing.B)
-// are considered benchmarks, and are executed by gotest when the -test.bench
-// flag is provided.
+// are considered benchmarks, and are executed by the "go test" command when
+// the -test.bench flag is provided.
//
// A sample benchmark function looks like this:
// func BenchmarkHello(b *testing.B) {
@@ -81,7 +81,7 @@ var (
// The short flag requests that tests run more quickly, but its functionality
// is provided by test writers themselves. The testing package is just its
// home. The all.bash installation script sets it to make installation more
-\t// efficient, but by default the flag is off so a plain "gotest" will do a
+\t// efficient, but by default the flag is off so a plain "go test" will do a
\t// full test of the package.
\tshort = flag.Bool("test.short", false, "run smaller test suite to save time")
@@ -162,7 +162,7 @@ func (c *common) Fail() { c.failed = true }\n func (c *common) Failed() bool { return c.failed }\n \n // FailNow marks the function as having failed and stops its execution.\n-// Execution will continue at the next Test.\n+// Execution will continue at the next test or benchmark.\n func (c *common) FailNow() {\n \tc.Fail()\n \n@@ -246,7 +246,7 @@ func (t *T) Parallel() {\n }\n \n // An internal type but exported because it is cross-package; part of the implementation\n-// of gotest.\n+// of the "go test" command.\n type InternalTest struct {\n \tName string\n \tF func(*T)\n@@ -275,7 +275,7 @@ func tRunner(t *T, test *InternalTest) {\n }\n \n // An internal function but exported because it is cross-package; part of the implementation\n-// of gotest.\n+// of the "go test" command.\n func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) {\n \tflag.Parse()\n \tparseCpuList()\n```
## コアとなるコードの解説
このコミットでは、`src/pkg/testing/benchmark.go`と`src/pkg/testing/testing.go`内の以下の箇所が変更されています。
1. **`src/pkg/testing/benchmark.go`**:
* `InternalBenchmark`型のコメント: 「part of the implementation of gotest.」が「part of the implementation of the \"go test\" command.」に変更されました。これにより、`InternalBenchmark`が`go test`コマンドの実装の一部であることが明確になります。
* `RunBenchmarks`関数のコメント: 同様に、「part of the implementation of gotest.」が「part of the implementation of the \"go test\" command.」に変更されました。
* `Benchmark`関数のコメント: 「Useful for creating custom benchmarks that do not use gotest.」が「Useful for creating custom benchmarks that do not use the \"go test\" command.」に変更されました。これは、`Benchmark`関数が`go test`コマンドを使わないカスタムベンチマークの作成に役立つことを示しています。
2. **`src/pkg/testing/testing.go`**:
* ベンチマーク関数の説明コメント: 「are considered benchmarks, and are executed by gotest when the -test.bench flag is provided.」が「are considered benchmarks, and are executed by the \"go test\" command when the -test.bench flag is provided.」に変更されました。これにより、ベンチマークが`go test`コマンドによって実行されることが明確になります。
* `short`フラグの説明コメント: 「a plain \"gotest\" will do a full test of the package.」が「a plain \"go test\" will do a full test of the package.」に変更されました。これは、`short`フラグがオフの場合に、通常の`go test`コマンドがパッケージの完全なテストを実行することを示しています。
* `FailNow`関数のコメント: 「Execution will continue at the next Test.」が「Execution will continue at the next test or benchmark.」に変更されました。これは、`FailNow`が呼び出された後、実行が次のテストまたはベンチマークに進むことをより正確に記述しています。
* `InternalTest`型のコメント: 「part of the implementation of gotest.」が「part of the implementation of the \"go test\" command.」に変更されました。
* `Main`関数のコメント: 「part of the implementation of gotest.」が「part of the implementation of the \"go test\" command.」に変更されました。
これらの変更はすべて、`testing`パッケージ内のドキュメントとコメントの正確性を高め、Goのテスト実行に関する公式な用語である「go test」への統一を図るものです。コードの機能的な変更は一切含まれていません。
## 関連リンク
* GitHubコミットページ: [https://github.com/golang/go/commit/7ef97def800fc155c3bdc9e84c0af7f6d786ee7b](https://github.com/golang/go/commit/7ef97def800fc155c3bdc9e84c0af7f6d786ee7b)
* Go Code Review (CL): [https://golang.org/cl/5650050](https://golang.org/cl/5650050)
* Go Issue #2958: [https://code.google.com/p/go/issues/detail?id=2958](https://code.google.com/p/go/issues/detail?id=2958) (当時のGoogle Codeのリンクですが、現在はGitHub Issuesに移行している可能性があります)
## 参考にした情報源リンク
* Go Testing Package Documentation: [https://pkg.go.dev/testing](https://pkg.go.dev/testing)
* Go Command `go test` Documentation: [https://go.dev/cmd/go/#hdr-Test_packages](https://go.dev/cmd/go/#hdr-Test_packages)
* Web search for "golang \"gotest\" vs \"go test\" history":
* [https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQFsOtUCRDRhA1RK8ts4TYLfghkoahNpV5_KDhPfSIC3_Zvj-MAPLcmhd70T0aP-9RypjP0PuIS6i4m7z6MuRvmS2hxVk1UlfPH_UDVYMcu9dQG1BWH53Ar3CvEki3ep2cTj9pBnKZRRXoIGyr4fXs1H4fw=](https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQFsOtUCRDRhA1RK8ts4TYLfghkoahNpV5_KDhPfSIC3_Zvj-MAPLcmhd70T0aP-9RypjP0PuIS6i4m7z6MuRvmS2hxVk1UlfPH_UDVYMcu9dQG1BWH53Ar3CvEki3ep2cTj9pBnKZRRXoIGyr4fXs1H4fw=)
* [https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQEB41ccCIvm3Y6UbeLWLLT4xXRJ2KkmDp384IwCFqAZ-Giktqsx9m4zGWBzr996nQZKNdvxg98MhWszh9QpGuAVHAlLzaO8p_Yxd_2N58CVU78RaFPTTPTJGw6GDk1GJgKJcBEzjIJYNKE-52II=](https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQEB41ccCIvm3Y6UbeLWLLT4xXRJ2KkmDp384IwCFqAZ-Giktqsx9m4zGWBzr996nQZKNdvxg98MhWszh9QpGuAVHAlLzaO8p_Yxd_2N58CVU78RaFPTTPTJGw6GDk1GJgKJcBEzjIJYNKE-52II=)
* [https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQGdOLQawMkZ75mQ6F_EsbU6VT4R8GOBjCSAD2OhoGQyo8Gf3IxuJUrZyvOtna3FIiR0yLYTbxYPtogdgf6k2B3Q1BBkt2_XxdiCwbmpp21SXvTvZJBi0OzdzVNI7aX7AVFrNXOqVkA3NdjMT0Y15s44ysLqRbckkzI=](https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQGdOLQawMkZ75mQ6F_EsbU6VT4R8GOBjCSAD2OhoGQyo8Gf3IxuJUrZyvOtna3FIiR0yLYTbxYPtogdgf6k2B3Q1BBkt2_XxdiCwbmpp21SXvTvZJBi0OzdzVNI7aX7AVFrNXOqVkA3NdjMT0Y15s44ysLqRbckkzI=)
* [https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQFYdDmQ5s63FI9CDW8hmMnR-sEYcDd8Wdap-4ju1s7G1b7dzpc9uflZO2E4CK0Nfq5lw3_R0SAxF0hSdo8asv-_-exSBE_xOBnd8Hlcrye4J5nA2-fAWeE624oawR7KKf5J](https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQFYdDmQ5s63FI9CDW8hmMnR-sEYcDd8Wdap-4ju1s7G1b7dzpc9uflZO2E4CK0Nfq5lw3_R0SAxF0hSdo8asv-_-exSBE_xOBnd8Hlcrye4J5nA2-fAWeE624oawR7KKf5J)
* [https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQEffvTZVfGp9DdyFCc_-Psg6ZbZ4zAFaf0rzWL-WFYP1lrYdXByRIZ5abqYgJUs22hvhYrDdpOxqW1OPWVIDoKmjyBeqkXnyQIRAp6yfPmi1wbCnVkX6sa-RFS2kE9XlD8cEN53](https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQEffvTZVfGp9DdyFCc_-Psg6ZbZ4zAFaf0rzWL-WFYP1lrYdXByRIZ5abqYgJUs22hvhYrDdpOxqW1OPWVIDoKmjyBeqkXnyQIRAp6yfPmi1wbCnVkX6sa-RFS2kE9XlD8cEN53)
* [https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQEEi_5SHvscIwJCkitXG3KYJeuQKrYEjxi2hs7AZNL7ezutesqeKdp1si9Z-ZC9x46Ic7UFC73Wa2MHjNML-TgXS_0Q9ZTjKvsGT32UcK3jmtk_9xYigrSTMXjrOw==](https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQEEi_5SHvscIwJCkitXG3KYJeuQKrYEjxi2hs7AZNL7ezutesqeKdp1si9Z-ZC9x46Ic7UFC73Wa2MHjNML-TgXS_0Q9ZTjKvsGT32UcK3jmtk_9xYigrSTMXjrOw==)
* [https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQGmdB0lbe7utTWS0gMwu8Q1_CWz_VO_nrPhmlkvQYiHEuy_6f58mqwJSIo1ChI9JgUdmvsG2q76Fmx2uovH1bVnX6j0YvlrKrr7rjGHlnzzaG88wQKnjdYYY0D8V4UWvXwWtKBLVx05ow-pqo5Cl5Is6QesxBQ=](https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQGmdB0lbe7utTWS0gMwu8Q1_CWz_VO_nrPhmlkvQYiHEuy_6f58mqwJSIo1ChI9JgUdmvsG2q76Fmx2uovH1bVnX6j0YvlrKrr7rjGHlnzzaG88wQKnjdYYY0D8V4UWvXwWtKBLVx05ow-pqo5Cl5Is6QesxBQ=)