grim/resticide
Clone
Summary
Browse
Changes
Graph
Give the --help output some tlc, also added a --version argument
develop
2016-07-09, Gary Kramlich
32bc94f303e2
Give the --help output some tlc, also added a --version argument
package
reporter
import
(
"bitbucket.org/rw_grim/resticide/test"
)
// ReportHandler is an interface that can be used to handle the reporting of
// tests.
type
ReportHandler
interface
{
Init
(
verbose
bool
)
Start
(
tests
int
)
Finish
(
tests
int
,
passed
int
,
failed
int
)
TestStart
(
test
test
.
Test
)
TestFinish
(
test
test
.
Test
,
res
test
.
Result
)
LoadTestsFailed
(
err
error
)
LoadTestFailed
(
path
string
,
err
error
)
}
// Reporter is the highlevel reporting object
type
Reporter
struct
{
handlers
[]
ReportHandler
verbose
bool
}
type
handlerFunc
func
(
handler
ReportHandler
)
// NewReporter creates a new reporter
func
NewReporter
(
verbose
bool
)
*
Reporter
{
reporter
:=
new
(
Reporter
)
reporter
.
verbose
=
verbose
return
reporter
}
func
(
reporter
*
Reporter
)
report
(
function
handlerFunc
)
{
for
_
,
handler
:=
range
reporter
.
handlers
{
function
(
handler
)
}
}
// AddHandler ads the given ReportHandler to the reporter
func
(
reporter
*
Reporter
)
AddHandler
(
handler
ReportHandler
)
{
handler
.
Init
(
reporter
.
verbose
)
reporter
.
handlers
=
append
(
reporter
.
handlers
,
handler
)
}
// Start is called after program initialization has completed, but before any
// tests are run
func
(
reporter
*
Reporter
)
Start
(
tests
int
)
{
reporter
.
report
(
func
(
handler
ReportHandler
)
{
handler
.
Start
(
tests
)
})
}
// Finish is called when all tests have completed and the program is about to
// exit
func
(
reporter
*
Reporter
)
Finish
(
tests
int
,
passed
int
,
failed
int
)
{
reporter
.
report
(
func
(
handler
ReportHandler
)
{
handler
.
Finish
(
tests
,
passed
,
failed
)
})
}
// TestStart is called just before a test starts running
func
(
reporter
*
Reporter
)
TestStart
(
test
test
.
Test
)
{
reporter
.
report
(
func
(
handler
ReportHandler
)
{
handler
.
TestStart
(
test
)
})
}
// TestFinish is called when a test has finished running
func
(
reporter
*
Reporter
)
TestFinish
(
test
test
.
Test
,
res
test
.
Result
)
{
reporter
.
report
(
func
(
handler
ReportHandler
)
{
handler
.
TestFinish
(
test
,
res
)
})
}
// LoadTestsFailed should be called when there was a problem loading multiple
// tests
func
(
reporter
*
Reporter
)
LoadTestsFailed
(
err
error
)
{
reporter
.
report
(
func
(
handler
ReportHandler
)
{
handler
.
LoadTestsFailed
(
err
)
})
}
// LoadTestFailed should be called when there was a problem loading a test
func
(
reporter
*
Reporter
)
LoadTestFailed
(
path
string
,
err
error
)
{
reporter
.
report
(
func
(
handler
ReportHandler
)
{
handler
.
LoadTestFailed
(
path
,
err
)
})
}