chunkedfile

package
v0.0.0-...-32f3451 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2019 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package chunkedfile provides utilities for testing that source code errors are reported in the appropriate places.

A chunked file consists of several chunks of input text separated by "---" lines. Each chunk is an input to the program under test, such as an evaluator. Lines containing "###" are interpreted as expectations of failure: the following text is a Go string literal denoting a regular expression that should match the failure message.

Example:

x = 1 / 0 ### "division by zero"
---
x = 1
print(x + "") ### "int + string not supported"

A client test feeds each chunk of text into the program under test, then calls chunk.GotError for each error that actually occurred. Any discrepancy between the actual and expected errors is reported using the client's reporter, which is typically a testing.T.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	Source string
	// contains filtered or unexported fields
}

A Chunk is a portion of a source file. It contains a set of expected errors.

func Read

func Read(filename string, report Reporter) (chunks []Chunk)

Read parses a chunked file and returns its chunks. It reports failures using the reporter.

Error messages of the form "file.star:line:col: ..." are prefixed by a newline so that the Go source position added by (*testing.T).Errorf appears on a separate line so as not to confused editors.

func (*Chunk) Done

func (chunk *Chunk) Done()

Done should be called by the client to indicate that the chunk has no more errors. Done reports expected errors that did not occur to the chunk's reporter.

func (*Chunk) GotError

func (chunk *Chunk) GotError(linenum int, msg string)

GotError should be called by the client to report an error at a particular line. GotError reports unexpected errors to the chunk's reporter.

type Reporter

type Reporter interface {
	Errorf(format string, args ...interface{})
}

Reporter is implemented by *testing.T.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL