::xounit
Class TestResultsTextFormatter

Heritage:
::xotcl::Object
Direct Known Subclasses:
::xounit::TestFailuresTextFormatter, ::xounit::TestResultsEmailFormatter, ::xounit::TestResultsWebFormatter, ::xounit::TestRunnerTextUI,

Associated Test:
::xounit::test::TestTestResultsTextFormatter

Class TestResultsTextFormatter
superclass ::xotcl::Object,
TestResultsTextFormatter is a utility class to generate
 human readable results in plan ASCII text. The input
 to the formatting methods should be a list of TestResult
 objects.
Variables
NameDefault ValueClassComment
 
Methods
NameComment
formatResults {results}   Format a list of results and return the formatted string
numberOfErrors {results}   Count the total number of test errors
numberOfFailures {results}   Count the total number of test failures
numberOfPasses {results}   Count the total number of tests that passed
numberOfTests {results}   Count the total number of tests run
printError {anError}   Format a TestError
printFailure {aFailure}   Format a TestFailure
printPass {aPass}   Format a TestPass
printResult {aResult}   Format one TestResult and return the string
printResultSummary {aResult}  
printResults {results}   Format and print a list of results to stdout
printSubResult {aResult}   Format a subtest result
resultsPass {results}   Count the number of results that passed
testSummary {results}   Format a summary of a list of TestResults
   
Methods from ::xotcl::Object
#, ., ?, ?code, ?methods, ?object, abstract, copy, coverageFilter, defaultmethod, extractConfigureArg, filterappend, garbageCollect, get#, getClean#, hasclass, init, methodTag, mixinappend, move, profileFilter, self, setParameterDefaults, shell, tclcmd, traceFilter,
 
Instproc Detail

formatResults

Description:
 Format a list of results and return the formatted string.
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc formatResults {results}  {
   

        set buffer ""

        foreach result $results {

            append buffer [ my printResult $result ]
        }

        append buffer "=================\n"
        append buffer [ my testSummary $results ]

        return $buffer
    
}

numberOfErrors

Description:
 Count the total number of test errors.
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc numberOfErrors {results}  {
   

        set number 0

        foreach result $results {

            incr number [ $result numberOfErrors ]
        }

        return $number
    
}

numberOfFailures

Description:
 Count the total number of test failures.
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc numberOfFailures {results}  {
   

        set number 0

        foreach result $results {

            incr number [ $result numberOfFailures ]
        }

        return $number
    
}

numberOfPasses

Description:
 Count the total number of tests that passed.
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc numberOfPasses {results}  {
   

        set number 0

        foreach result $results {

            incr number [ $result numberOfPasses ]

        }

        return $number

    
}

numberOfTests

Description:
 Count the total number of tests run.
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc numberOfTests {results}  {
   

        set number 0

        foreach result $results {

            incr number [ $result numberOfTests ]
        }

        return $number

    
}

printError

Description:
 Format a TestError
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc printError {anError}  {
   

        return "Error: [ $anError name ] [$anError test]\n[$anError error]\n\n"
    
}

printFailure

Description:
 Format a TestFailure
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc printFailure {aFailure}  {
   

        return "Failure: [ $aFailure name ] [$aFailure test]\n[$aFailure error]\n\n"
    
}

printPass

Description:
 Format a TestPass
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc printPass {aPass}  {
   

        return "Pass: [ $aPass name ] [$aPass test] [$aPass return]\n\n"
    
}

printResult

Description:
 Format one TestResult and return the string.
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc printResult {aResult}  {
   

        set buffer ""

        append buffer [ my printSubResult $aResult ]
        append buffer [ my printResultSummary $aResult ]

        return $buffer 
    
}

printResultSummary

Description:
 
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc printResultSummary {aResult}  {
   

        set buffer ""

        if [ $aResult passed ] {

            append buffer "All Passed: [ $aResult numberOfPasses ]\n"

        } else {

            append buffer "Errors: [ $aResult numberOfErrors ]  "
            append buffer "Failures: [ $aResult numberOfFailures ]  "
            append buffer "Passes: [ $aResult numberOfPasses ]\n"
        }

        return $buffer
    
}

printResults

Description:
 Format and print a list of results to stdout.
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc printResults {results}  {
   
        set text [my formatResults $results]
        puts $text
        flush stdout
        return $text
    
}

printSubResult

Description:
 Format a subtest result.
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc printSubResult {aResult}  {
   

        set buffer ""
        
        append buffer "[ $aResult name ]\n"

        foreach result [ $aResult results ] {

            if [ $result hasclass ::xounit::TestPass ] {

                append buffer [ my printPass $result ]
                continue
            }

            if [ $result hasclass ::xounit::TestFailure ] {

                append buffer [ my printFailure $result ]
                continue
            }

            if [ $result hasclass ::xounit::TestError ] {

                append buffer [ my printError $result ]
                continue
            }

            append buffer [ my printSubResult $result  ]
        }

        return $buffer
    
}

resultsPass

Description:
 Count the number of results that passed.
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc resultsPass {results}  {
   

        set number 0

        foreach result $results {

            if [ $result passed ] { incr number }
        }

        return $number

    
}

testSummary

Description:
 Format a summary of a list of TestResults.
Arguments:
Code:
  ::xounit::TestResultsTextFormatter instproc testSummary {results}  {
   

        set buffer ""

        append buffer "Tests: [ my numberOfTests $results ]\n"
        append buffer "Errors: [ my numberOfErrors $results ]\n"
        append buffer "Failures: [ my numberOfFailures $results ]\n"
        append buffer "Passes: [ my numberOfPasses $results ]\n"

        return $buffer
    
}