mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
test: one run-directory writer for the packages that share it
internal/tracecorpus and cmd/internal-tools/exploration-reach declared the same 24-line writeRun, identical apart from whether the seed was a parameter. The package's charter is on it: a helper goes here once it has callers in two packages, and stays in a package's own tests until then.
This commit is contained in:
1 parent
5a0439d394
commit
5ae825109e
3 files changed
+47
-43
No files matched your search
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/priyanshujain/sanderling/internal/driver/ioscompanion"
|
"github.com/priyanshujain/sanderling/internal/driver/ioscompanion"
|
||||||
"github.com/priyanshujain/sanderling/internal/hierarchy"
|
"github.com/priyanshujain/sanderling/internal/hierarchy"
|
||||||
|
"github.com/priyanshujain/sanderling/internal/testsupport"
|
||||||
"github.com/priyanshujain/sanderling/internal/trace"
|
"github.com/priyanshujain/sanderling/internal/trace"
|
||||||
"github.com/priyanshujain/sanderling/internal/tracecorpus"
|
"github.com/priyanshujain/sanderling/internal/tracecorpus"
|
||||||
)
|
)
|
||||||
@@ -136,27 +137,8 @@ func measureRun(t *testing.T, seed int64, dumps ...string) Reach {
|
|||||||
|
|
||||||
func writeRun(t *testing.T, seed int64, dumps ...string) string {
|
func writeRun(t *testing.T, seed int64, dumps ...string) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
directory := t.TempDir()
|
return testsupport.WriteRunFromDumps(
|
||||||
writer, err := trace.NewWriter(directory)
|
t, t.TempDir(), trace.Meta{Seed: seed, Platform: "web"}, dumps...)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := writer.WriteMeta(trace.Meta{Seed: seed, Platform: "web"}); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
for index, dump := range dumps {
|
|
||||||
tree, err := hierarchy.Parse(dump)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := writer.WriteStep(trace.Step{Index: index + 1, Hierarchy: tree}); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := writer.Close(); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
return directory
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendFinalize(t *testing.T, directory string, index int) {
|
func appendFinalize(t *testing.T, directory string, index int) {
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Package testsupport holds test helpers that more than one package needs.
|
||||||
|
// It exists because the suite's helper layer grew by copying: a helper written
|
||||||
|
// inside one package's tests is invisible to the next package that needs it, so
|
||||||
|
// the next package writes it again. Anything here has at least two callers in
|
||||||
|
// different packages; a helper with one belongs in that package's own tests.
|
||||||
|
package testsupport
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/priyanshujain/sanderling/internal/hierarchy"
|
||||||
|
"github.com/priyanshujain/sanderling/internal/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WriteRunFromDumps writes a complete run directory: meta.json, then one step
|
||||||
|
// per hierarchy dump numbered from 1. It goes through trace.NewWriter rather
|
||||||
|
// than composing the files by hand so a fixture cannot claim a trace_version
|
||||||
|
// the writer would not have produced.
|
||||||
|
func WriteRunFromDumps(t *testing.T, directory string, meta trace.Meta, dumps ...string) string {
|
||||||
|
t.Helper()
|
||||||
|
writer, err := trace.NewWriter(directory)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := writer.WriteMeta(meta); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for index, dump := range dumps {
|
||||||
|
tree, err := hierarchy.Parse(dump)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := writer.WriteStep(trace.Step{Index: index + 1, Hierarchy: tree}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := writer.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return directory
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/priyanshujain/sanderling/internal/hierarchy"
|
"github.com/priyanshujain/sanderling/internal/testsupport"
|
||||||
"github.com/priyanshujain/sanderling/internal/trace"
|
"github.com/priyanshujain/sanderling/internal/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -73,27 +73,8 @@ func TestLoadRefusesElementsWithNoStoredShape(t *testing.T) {
|
|||||||
|
|
||||||
func writeRun(t *testing.T, dumps ...string) string {
|
func writeRun(t *testing.T, dumps ...string) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
directory := t.TempDir()
|
return testsupport.WriteRunFromDumps(
|
||||||
writer, err := trace.NewWriter(directory)
|
t, t.TempDir(), trace.Meta{Seed: 7, Platform: "web"}, dumps...)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := writer.WriteMeta(trace.Meta{Seed: 7, Platform: "web"}); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
for index, dump := range dumps {
|
|
||||||
tree, err := hierarchy.Parse(dump)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := writer.WriteStep(trace.Step{Index: index + 1, Hierarchy: tree}); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := writer.Close(); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
return directory
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func downgrade(t *testing.T, path string) {
|
func downgrade(t *testing.T, path string) {
|
||||||
|
|||||||
Reference in new issue
Block a user