All,
First the good news. After a bit of hacking around in the
hugolib/helpers module I managed to up the test coverage from 25.5% to
74.8%. That is without touching the pygments module(*) which looks to be
difficult to test in it’s current form. And I don’t yet have pygments
installed to start testing it.
The result is available on github in the ‘extend-hugolib-tests’ branch at:
Note: this branch is not in the final PR form, so hold off merging it.
The bad news is we have a fairly large amount of test failures,
especially in the path.go module. See the output of the ‘go test’
command below.
So before I create panic :), at least of some of these are going to
be my fault because I don’t yet understand Steve’s intention with some
of these, the
TestUrlPrep
test being a case in point.
The remaining tests:
TestReplaceExtension
TestFilename
TestFileAndExt
TestGuessSection
Look reasonable, but fail. At the moment I’m not sure if I’ve
misinterpreted what the function is supposed to do, or not?
TestFindCWD
I believe my understanding and therefore the test
implementation is wrong. It looks like the code is trying to find out
where the server was started from based on the location of the exe on
Windows. Is this correct? But can’t the whole thing be replaced with a
simple call to os.Getwd() - which will work on Windows and Linux.
Anyhow can you take a quick look and point me in the right direction so
I can close off these test failures (or misunderstands). Once everything
passes I’ll wrap everything up in a neat little PR.
Once the PR is out of the way I propose to just take the module with the
next lowest test coverage and start working to improve the test coverage
there.
I can see where TLC can be applied in the code I’ve looked at, but I’m
not keen on refactoring stuff on a large scale until the project as a
whole has a lot more test coverage. Refactoring without tests gives me
the hebejebes
Owen
go test output:
$ go test -cover ./...
--- FAIL: TestReplaceExtension (0.00 seconds)
path_test.go:95: Test 0 failed. Expected "/some/randompath/file.html"
got "file.html"
path_test.go:95: Test 1 failed. Expected "/banana.HTML" got
"banana.HTML"
path_test.go:95: Test 2 failed. Expected "./banana.xml" got
"banana.xml"
path_test.go:95: Test 3 failed. Expected "banana/pie/index.xml" got
"index.xml"
path_test.go:95: Test 4 failed. Expected "../pies/fish/index.xml" got
"index.xml"
--- FAIL: TestFilename (0.00 seconds)
path_test.go:371: Test 5 failed. Expected "filename-no-ext" got
"./filename-no-ext"
path_test.go:371: Test 6 failed. Expected "filename-no-ext" got
"/filename-no-ext"
path_test.go:371: Test 8 failed. Expected "" got "directoy/"
--- FAIL: TestFileAndExt (0.00 seconds)
path_test.go:396: Test 5 failed. Expected filename "filename-no-ext"
got "./filename-no-ext".
path_test.go:396: Test 6 failed. Expected filename "filename-no-ext"
got "/filename-no-ext".
path_test.go:396: Test 8 failed. Expected filename "" got "directoy/".
--- FAIL: TestGuessSection (0.00 seconds)
path_test.go:427: Test 2 failed. Expected "/" got ""
path_test.go:427: Test 3 failed. Expected "/" got ""
path_test.go:427: Test 4 failed. Expected "/" got "content"
path_test.go:427: Test 5 failed. Expected "/blog" got ""
path_test.go:427: Test 6 failed. Expected "/blog/" got "blog"
path_test.go:427: Test 7 failed. Expected "blog" got ""
path_test.go:427: Test 8 failed. Expected "/blog" got ""
path_test.go:427: Test 9 failed. Expected "/blog/" got "blog"
path_test.go:427: Test 10 failed. Expected "/blog/" got "content"
--- FAIL: TestFindCWD (0.00 seconds)
path_test.go:453: Test 0 failed. Expected
"/home/owen/go/src/github.com/owenwaller/hugo/helpers" but got
"/tmp/go-build092258256/github.com/owenwaller/hugo/helpers/_test"
NO error returning url = "/section/name/"
Ugly case. Returning x = "/section/name.html"
--- FAIL: TestUrlPrep (0.00 seconds)
url_test.go:65: Test #0 failed. Expected "/section/name/index.html" got
"/section/name/"
FAIL
coverage: 74.8% of statements
FAIL github.com/owenwaller/hugo/helpers 0.013s