diff --git a/base/testingt.go b/base/testingt.go index 20c2100..7009d0e 100644 --- a/base/testingt.go +++ b/base/testingt.go @@ -1,6 +1,6 @@ package base -//TestingT is a convenience interface that matches some methods of `testing.T` +//TestingT is a convenience interface that matches Some methods of `testing.T` type TestingT interface { Failed() bool Logf(format string, args ...interface{}) diff --git a/base/testmetadata.go b/base/testmetadata.go index d60d454..3b15018 100644 --- a/base/testmetadata.go +++ b/base/testmetadata.go @@ -5,7 +5,7 @@ import ( "sync" ) -// TestMetaData holds some information about the test, it's id, whether it failed or not +// TestMetaData holds Some information about the test, it's id, whether it failed or not // and the output it sent to t.Errorf or t.Error etc. type TestMetaData struct { sync.RWMutex @@ -47,13 +47,13 @@ func (t *TestMetaData) FailNow() { t.failed = true } -//Helper does nothing. It's just in case some package that consumes t +//Helper does nothing. It's just in case Some package that consumes t // calls it. func (t *TestMetaData) Helper() { // do nothing } -//Name returns the id (the test name, possibly with some uniqueid appended) +//Name returns the id (the test name, possibly with Some uniqueid appended) func (t *TestMetaData) Name() string { t.RLock() defer t.RUnlock() diff --git a/base/types.go b/base/types.go index 15040af..e552286 100644 --- a/base/types.go +++ b/base/types.go @@ -4,10 +4,10 @@ import ( "github.com/corbym/gogiven/testdata" ) -// GivenData is a func type that gets given some interesting givens as a parameter +// GivenData is a func type that gets given Some interesting givens as a parameter type GivenData func(givens testdata.InterestingGivens) -// CapturedIOData is a func type that gets given a reference to some CapturedIO data for the test +// CapturedIOData is a func type that gets given a reference to Some CapturedIO data for the test type CapturedIOData func(capturedIO testdata.CapturedIO) //CapturedIOGivenData is a combination of GivenData and CapturedIOData types diff --git a/generator.go b/generator.go index fb2fff2..baeaa5e 100644 --- a/generator.go +++ b/generator.go @@ -28,10 +28,12 @@ func GenerateTestOutput() { value, _ := globalTestContextMap.Load(key) currentTestContext := value.(*TestContext) tests := currentTestContext.SomeTests() - pageData := &generator.PageData{ - Title: transformFileNameToHeader(currentTestContext.FileName()), - SomeMap: tests.AsMapOfSome(), - } + + pageData := generator.NewPageData( + transformFileNameToHeader(currentTestContext.fileName), + tests.asMapOfSome(), + ) + output := Generator.Generate(pageData) extension := Generator.FileExtension() diff --git a/generator/pagedata.go b/generator/pagedata.go index 4bfae41..6935d3f 100644 --- a/generator/pagedata.go +++ b/generator/pagedata.go @@ -1,9 +1,63 @@ package generator -import "github.com/corbym/gogiven/base" +import ( + "github.com/corbym/gogiven/base" + "github.com/corbym/gogiven/testdata" +) + +type TestResult struct { + TestId string + Failed bool + Skipped bool + TestOutput string +} + +func NewTestResult(data *base.TestMetaData) (result *TestResult) { + result = &TestResult{ + Skipped: data.Skipped(), + TestId: data.Name(), + TestOutput: data.TestOutput(), + Failed: data.Failed(), + } + return +} + +type TestData struct { + TestResult *TestResult + TestTitle string + InterestingGivens testdata.InterestingGivens + CapturedIO testdata.CapturedIO + GivenWhenThen []string +} + +func NewTestData(some *base.Some) (testData *TestData) { + testData = &TestData{ + TestResult: NewTestResult(some.TestMetaData()), + InterestingGivens: some.InterestingGivens(), + CapturedIO: some.CapturedIO(), + GivenWhenThen: some.GivenWhenThen(), + TestTitle: some.TestTitle(), + } + return +} //PageData is the struct that populates the template with data from the test output. type PageData struct { - Title string - SomeMap *base.SomeMap + Title string + TestResults map[string]*TestData +} + +func NewPageData(title string, someMap *base.SomeMap) (pageData *PageData) { + pageData = new(PageData) + pageData.Title = title + pageData.TestResults = copyTestResults(someMap) + return +} + +func copyTestResults(someMap *base.SomeMap) (testData map[string]*TestData) { + testData = make(map[string]*TestData) + for k, v := range *someMap { + testData[k] = NewTestData(v) + } + return } diff --git a/generator_test.go b/generator_test.go index 7392400..cee972a 100644 --- a/generator_test.go +++ b/generator_test.go @@ -25,8 +25,7 @@ func TestGenerateTestOutput(t *testing.T) { func TestGenerateTestOutput_DefaultsToCurrentDir(t *testing.T) { old := os.Getenv("GOGIVENS_OUTPUT_DIR") defer func() { - remove := os.Remove("./generator_test.html") - then.AssertThat(t, remove, is.Nil()) + os.Remove("./generator_test.html") }() defer func() { os.Setenv("GOGIVENS_OUTPUT_DIR", old) }() os.Setenv("GOGIVENS_OUTPUT_DIR", "doesnotexist") diff --git a/safemap.go b/safemap.go index 7e92f81..a4c27e5 100644 --- a/safemap.go +++ b/safemap.go @@ -43,8 +43,7 @@ func (rm *safeMap) Keys() []string { return keys } -// AsMapOfSome copies the safeMap into a normal map[string]*Some type -func (rm *safeMap) AsMapOfSome() *base.SomeMap { +func (rm *safeMap) asMapOfSome() *base.SomeMap { rm.RLock() defer rm.RUnlock() var newMap = &base.SomeMap{}