Search results

There are no results.

std.test.Plain

type pub Plain[T: mut + Write]

A test reporter that prints results in a simple text based format.

Static methods

new

Show source code
Hide source code
fn pub static new(out: T, colors: Bool) -> Plain[T] {
  Plain(out: out, tests: 0, failed: [], colors: colors)
}
fn pub static new(out: T: mut, colors: Bool) -> Plain[T: mut]

Returns a new reporter that writes to the given output stream.

Instance methods

failed

Show source code
Hide source code
fn pub mut failed(test: Test) {
  @tests += 1
  @failed.push(test)
  @out.write_string(red('F')).get
  @out.flush.get
}
fn pub mut failed(test: Test)

Reports a test that failed.

finished

Show source code
Hide source code
fn pub move finished(duration: Duration, seed: Int) -> Bool {
  if @failed.size > 0 {
    @out.print('\n\nFailures:').get

    @failed.iter.each_with_index(fn (test_index, test) {
      test.failures.iter.each_with_index(fn (failure_index, fail) {
        let num = '${test_index + failure_index + 1}.'
        let indent = ' '.repeat(num.chars.count)

        @out
          .print(
            '
${num} Test: ${test.name}
${indent} Line: ${fail.path}:${fail.line}

${indent}   ${green('expected:')} ${fail.expected}
${indent}        ${red('got:')} ${fail.got}',
          )
          .get
      })
    })
  }

  let decimals = 4
  let dur = if duration.to_secs >= 1.0 {
    '${duration.to_secs.round(decimals)} seconds'
  } else {
    '${duration.to_millis} milliseconds'
  }
  let failed = @failed.iter.reduce(0, fn (sum, test) {
    sum + test.failures.size
  })
  let failures = if failed > 0 {
    red('${failed} failures')
  } else {
    green('0 failures')
  }

  @out
    .print(
      '\nFinished running ${@tests} tests in ${dur}, ${failures}, seed: ${seed}',
    )
    .get

  @failed.empty?
}
fn pub move finished(duration: Duration, seed: Int) -> Bool

Presents a summary of the test suite upon completion.

The duration argument is set to the total execution time.

The seed argument is the seed used to sort the tests in a random order.

If any tests failed, this method must return false.

passed

Show source code
Hide source code
fn pub mut passed(test: Test) {
  @tests += 1
  @out.write_string(green('.')).get
  @out.flush.get
}
fn pub mut passed(test: Test)

Reports a test that passed.

Implemented traits

std.test.

Reporter

impl Reporter for Plain