github.com/leanovate/gopter@v0.2.9/formated_reporter_test.go (about)

     1  package gopter
     2  
     3  import (
     4  	"bytes"
     5  	"errors"
     6  	"testing"
     7  	"time"
     8  )
     9  
    10  func TestConsoleReporter(t *testing.T) {
    11  	var buffer bytes.Buffer
    12  	reporter := &FormatedReporter{
    13  		verbose: false,
    14  		width:   75,
    15  		output:  &buffer,
    16  	}
    17  
    18  	reporter.ReportTestResult("test property", &TestResult{Status: TestPassed, Succeeded: 50})
    19  	if buffer.String() != "+ test property: OK, passed 50 tests.\n" {
    20  		t.Errorf("Invalid output: %#v", buffer.String())
    21  	}
    22  	buffer.Reset()
    23  
    24  	reporter.ReportTestResult("test property", &TestResult{
    25  		Status:    TestFailed,
    26  		Succeeded: 50,
    27  		Args: PropArgs([]*PropArg{{
    28  			Arg:         "0",
    29  			ArgFormatted: "0",
    30  		}}),
    31  	})
    32  	if buffer.String() != "! test property: Falsified after 50 passed tests.\nARG_0: 0\n" {
    33  		t.Errorf("Invalid output: %#v", buffer.String())
    34  	}
    35  	buffer.Reset()
    36  
    37  	reporter.ReportTestResult("test property", &TestResult{
    38  		Status:    TestProved,
    39  		Succeeded: 50,
    40  		Args: PropArgs([]*PropArg{{
    41  			Arg:             "0",
    42  			ArgFormatted:     "0",
    43  			Label:           "somehing",
    44  			OrigArg:         "10",
    45  			OrigArgFormatted: "10",
    46  			Shrinks:         6,
    47  		}}),
    48  	})
    49  	if buffer.String() != "+ test property: OK, proved property.\nsomehing: 0\nsomehing_ORIGINAL (6 shrinks): 10\n" {
    50  		t.Errorf("Invalid output: %#v", buffer.String())
    51  	}
    52  	buffer.Reset()
    53  
    54  	reporter.ReportTestResult("test property", &TestResult{
    55  		Status:    TestExhausted,
    56  		Succeeded: 50,
    57  		Discarded: 40,
    58  	})
    59  	if buffer.String() != "! test property: Gave up after only 50 passed tests. 40 tests were\n   discarded.\n" {
    60  		t.Errorf("Invalid output: %#v", buffer.String())
    61  	}
    62  	buffer.Reset()
    63  
    64  	reporter.ReportTestResult("test property", &TestResult{
    65  		Status:    TestError,
    66  		Error:     errors.New("Poop"),
    67  		Succeeded: 50,
    68  		Args: PropArgs([]*PropArg{{
    69  			Arg: "0",
    70  			ArgFormatted: "0",
    71  		}}),
    72  	})
    73  	if buffer.String() != "! test property: Error on property evaluation after 50 passed tests: Poop\nARG_0: 0\n" {
    74  		t.Errorf("Invalid output: %#v", buffer.String())
    75  	}
    76  	buffer.Reset()
    77  
    78  	reporter.verbose = true
    79  	reporter.ReportTestResult("test property", &TestResult{Status: TestPassed, Succeeded: 50, Time: time.Minute})
    80  	if buffer.String() != "+ test property: OK, passed 50 tests.\nElapsed time: 1m0s\n" {
    81  		t.Errorf("Invalid output: %#v", buffer.String())
    82  	}
    83  	buffer.Reset()
    84  }