Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report accurate tested-doc count #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions htmldoc/document_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ func NewDocumentStore() DocumentStore {
}
}

// DocumentCount : Return number of documents in the document store.
func (dS *DocumentStore) DocumentCount() int {
return len(dS.Documents)
}

// IgnoredDocCount : Return number of documents in the document store where `IgnoreTest` is true.
func (dS *DocumentStore) IgnoredDocCount() int {
count := 0
for _, document := range dS.Documents {
if document.IgnoreTest {
count++
}
}
return count
}

// AddDocument : Add a document to the document store.
func (dS *DocumentStore) AddDocument(doc *Document) {
// Save reference to document to various data stores
Expand Down Expand Up @@ -70,6 +86,8 @@ func (dS *DocumentStore) discoverRecurse(dPath string) {
fis, err := f.Readdir(-1)
output.CheckErrorPanic(err)

isDirIgnored := dS.isDirIgnored(dPath)

// Iterate over contents of directory
for _, fileinfo := range fis {
fPath := path.Join(dPath, fileinfo.Name())
Expand All @@ -82,7 +100,7 @@ func (dS *DocumentStore) discoverRecurse(dPath string) {
FilePath: path.Join(dS.BasePath, fPath),
SitePath: fPath,
BasePath: dPath,
IgnoreTest: dS.isDirIgnored(dPath),
IgnoreTest: isDirIgnored,
}
newDoc.Init()
dS.AddDocument(newDoc)
Expand All @@ -94,7 +112,7 @@ func (dS *DocumentStore) discoverRecurse(dPath string) {

}

// ResolvePath : Resolves internal absolute paths to documents.
// ResolvePath : Resolves internal paths to documents.
func (dS *DocumentStore) ResolvePath(refPath string) (*Document, bool) {
// Match root document
if refPath == "/" {
Expand Down
27 changes: 23 additions & 4 deletions htmldoc/document_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import (
"github.com/daviddengcn/go-assert"
)

// Expected number of .html files under "fixtures/documents"
const ExpectedHtmlDocumentCount = 6

func TestDocumentStoreDiscover(t *testing.T) {
// documentstore can scan an os directory
dS := NewDocumentStore()
dS.BasePath = "fixtures/documents"
dS.DocumentExtension = ".html" // Ignores .htm
dS.DirectoryIndex = "index.html"
dS.Discover()
// Fixtures dir has eight documents in various folders
assert.Equals(t, "document count", len(dS.Documents), 6)
assert.Equals(t, "document count", dS.DocumentCount(), ExpectedHtmlDocumentCount)
assert.Equals(t, "ignored document count", dS.IgnoredDocCount(), 0)

for _, document := range dS.Documents {
assert.IsFalse(t, document.SitePath+" is not ignored", document.IgnoreTest)
}
}

func TestDocumentStoreIgnorePatterns(t *testing.T) {
Expand All @@ -25,8 +32,20 @@ func TestDocumentStoreIgnorePatterns(t *testing.T) {
dS.DirectoryIndex = "index.html"
dS.IgnorePatterns = []interface{}{"^lib/"}
dS.Discover()
// Fixtures dir has seven documents in various folders, (one ignored in lib)
assert.Equals(t, "document count", len(dS.Documents), 6)
// IgnorePatterns does not affect stored document count
assert.Equals(t, "document count", dS.DocumentCount(), ExpectedHtmlDocumentCount)
assert.Equals(t, "ignored document count", dS.IgnoredDocCount(), 1)

ignoredFile := "lib/unwanted-file.html"
f, exists := dS.DocumentPathMap[ignoredFile]
assert.IsTrue(t, ignoredFile+" exists", exists)
assert.IsTrue(t, ignoredFile+" is flagged as ignored", f.IgnoreTest)

for _, document := range dS.Documents {
if document.SitePath != ignoredFile {
assert.IsFalse(t, document.FilePath+" is not ignored", document.IgnoreTest)
}
}
}

func TestDocumentStoreDocumentExists(t *testing.T) {
Expand Down
7 changes: 6 additions & 1 deletion htmltest/htmltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,10 @@ func (hT *HTMLTest) CountErrors() int {

// CountDocuments : Return number of documents in hT document store
func (hT *HTMLTest) CountDocuments() int {
return len(hT.documentStore.Documents)
return hT.documentStore.DocumentCount()
}

// CountTestedDocuments : Return number of documents in hT document store that were tested
func (hT *HTMLTest) CountTestedDocuments() int {
return hT.documentStore.DocumentCount() - hT.documentStore.IgnoredDocCount()
}
5 changes: 3 additions & 2 deletions htmltest/htmltest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func TestNormalLookingPage(t *testing.T) {

func TestCountDocuments(t *testing.T) {
hT := tTestDirectory("fixtures/documents/folder-ok")
assert.Equals(t, "CountDocuments", hT.CountDocuments(), 3)
assert.Equals(t, "CountTestedDocuments", hT.CountTestedDocuments(), 3)
assert.Equals(t, "CountErrors", hT.CountErrors(), 0)
}

func TestCountErrors(t *testing.T) {
Expand All @@ -105,7 +106,7 @@ func TestFileExtensionOption(t *testing.T) {
"FileExtension": ".htm",
"DirectoryIndex": "index.htm",
})
assert.Equals(t, "CountDocuments", hT.CountDocuments(), 3)
assert.Equals(t, "CountTestedDocuments", hT.CountTestedDocuments(), 3)
tExpectIssueCount(t, hT, 1)
}

Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ func run(options optsMap) int {
color.Set(color.FgHiGreen)
fmt.Println("✔✔✔ passed in", timeEnd.Sub(timeStart))
if !fileMode {
fmt.Println("tested", hT.CountDocuments(), "documents")
testedDocCount := hT.CountTestedDocuments()
fmt.Print("tested ", testedDocCount, " documents")
docCount := hT.CountDocuments()
if testedDocCount < docCount {
fmt.Println(" out of", docCount)
} else {
fmt.Println()
}
}
color.Unset()
return 0
Expand Down
Loading