-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a framework to exercise the
go test
output
Prior to this patch, there was no way to exercise the behavior of `-rewrite` nor how errors and sub-tests would be reported in the output of `go test -v`. This patch introduces such "reflective" tests, where a test can compare the output and modified file through running `go test` recursively.
- Loading branch information
Showing
6 changed files
with
260 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2019 The Cockroach Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
// implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
// +build gotest | ||
|
||
package datadriven | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
var dataDir = flag.String("datadir", "", "directory where to find datafiles") | ||
|
||
func TestRewrite(t *testing.T) { | ||
if *dataDir == "" { | ||
t.Fatal("don't run this test directly; run TestGoTestInterface or similar instead") | ||
} | ||
Walk(t, *dataDir, func(t *testing.T, path string) { | ||
RunTest(t, path, func(t *testing.T, d *TestData) string { | ||
t.Logf("directive: %v %+v", d.Cmd, d.CmdArgs) | ||
switch d.Cmd { | ||
case "hello": | ||
return d.CmdArgs[0].Key + " was said" | ||
case "nothing": | ||
return "" | ||
case "blank": | ||
l := 0 | ||
if len(d.CmdArgs) > 0 { | ||
l = len(d.CmdArgs[1].Key) | ||
} | ||
return fmt.Sprintf("%*s\n", l, "") | ||
case "skip": | ||
// Verify that calling t.Skip() does not fail with an API error on | ||
// testing.T. | ||
t.Skip("woo") | ||
case "error": | ||
t.Error("some error: " + d.CmdArgs[0].Key) | ||
default: | ||
t.Fatalf("unknown directive: %s", d.Cmd) | ||
} | ||
return d.Expected | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
hello world | ||
---- | ||
world was said |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Whitespace in input | ||
hello world | ||
|
||
---- | ||
world was said | ||
|
||
# Command with no output | ||
nothing | ||
---- | ||
|
||
# Command with whitespace output | ||
blank | ||
---- | ||
---- | ||
|
||
---- | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
hello universe | ||
---- | ||
incorrect output | ||
|
||
hello planet | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Whitespace in input | ||
hello world | ||
|
||
---- | ||
wrong | ||
|
||
# Command with no output | ||
nothing | ||
---- | ||
wrong | ||
|
||
# Command with whitespace output | ||
blank | ||
---- | ||
wrong | ||
|
||
blank | ||
---- | ||
---- | ||
wrong | ||
---- | ||
---- | ||
|
||
# This one is correct, we just test the rewrite does not do excess work. | ||
blank | ||
---- | ||
---- | ||
|
||
---- | ||
---- |