From 1edfb8942385f5afc701829165ac237dbe49fb14 Mon Sep 17 00:00:00 2001 From: ValarDragon Date: Mon, 16 Jul 2018 12:30:54 -0700 Subject: [PATCH 1/2] contribution guide: Add guidelines for testing Indicates to use require's and asserts, and to use table driven tests, with error messages as described in #1664. Closes #1664 --- CONTRIBUTING.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0fcf36def..c04382391 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,6 +67,29 @@ tested by circle using `go test -v -race ./...`. If not, they will need a `circle.yml`. Ideally, every repo has a `Makefile` that defines `make test` and includes its continuous integration status using a badge in the `README.md`. +We expect tests to use `require` or `assert` rather than `t.Skip` or `t.Fail`, +unless there is a reason to do otherwise. +We prefer to use [table driven tests](https://github.com/golang/go/wiki/TableDrivenTests) +where applicable. +Error messages should follow the following format +`, tc #, i #`. +`` is an optional short description of whats failing, `tc` is the +index within the table of the testcase that is failing, and `i` is when there +is a loop, exactly which iteration of the loop failed. +The idea is you should be able to see the +error message and figure out exactly what failed. +Here is an example check: + +``` + +for tcIndex, tc := range cases { + + for i := 0; i < tc.numTxsToTest; i++ { + + require.Equal(t, expectedTx[:32], calculatedTx[:32], + "First 32 bytes of the txs differed. tc #%d, i #%d", tcIndex, i) + ``` + ## Branching Model and Release User-facing repos should adhere to the branching model: http://nvie.com/posts/a-successful-git-branching-model/. From 2b72e3377a4177ed3d1153c0a4ff4120f2ac12c0 Mon Sep 17 00:00:00 2001 From: ValarDragon Date: Mon, 16 Jul 2018 17:24:07 -0700 Subject: [PATCH 2/2] Clarify when to use table driven tests --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c04382391..b18ef2ea9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -69,9 +69,9 @@ includes its continuous integration status using a badge in the `README.md`. We expect tests to use `require` or `assert` rather than `t.Skip` or `t.Fail`, unless there is a reason to do otherwise. -We prefer to use [table driven tests](https://github.com/golang/go/wiki/TableDrivenTests) -where applicable. -Error messages should follow the following format +When testing a function under a variety of different inputs, we prefer to use +[table driven tests](https://github.com/golang/go/wiki/TableDrivenTests). +Table driven test error messages should follow the following format `, tc #, i #`. `` is an optional short description of whats failing, `tc` is the index within the table of the testcase that is failing, and `i` is when there