status

package
Version: v0.0.0-...-0d16973 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrBad = errors.New("bad status")

ErrBad occurs when FromString encounters an unknown status string.

Functions

This section is empty.

Types

type Flag

type Flag int

Flag programmatically represents, as a bitwise Flag set, the possible classifications for a subject.

const (
	// FlagFiltered signifies that a subject was filtered out.
	FlagFiltered Flag = 1 << iota
	// FlagFlagged signifies that a subject was 'flagged'.
	FlagFlagged
	// FlagCompileFail signifies a compile failure.
	FlagCompileFail
	// FlagCompileTimeout signifies a compile timeout.
	FlagCompileTimeout
	// FlagRunFail signifies a runtime failure.
	FlagRunFail
	// FlagRunTimeout signifies a runtime timeout.
	FlagRunTimeout

	// FlagFail is the union of all failure flags.
	FlagFail = FlagCompileFail | FlagRunFail
	// FlagTimeout is the union of all timeout flags.
	FlagTimeout = FlagCompileTimeout | FlagRunTimeout
	// FlagBad is the union of all 'bad' flags; it should match the calculation in Status.IsBad.
	FlagBad = FlagFail | FlagTimeout | FlagFlagged
)

func (Flag) MatchesAll

func (f Flag) MatchesAll(expected Flag) bool

MatchesAll tests whether this Flag has all flag bits in expected present.

Where there is only one bit set in expected, MatchesAny equals MatchesAll.

func (Flag) MatchesAny

func (f Flag) MatchesAny(expected Flag) bool

MatchesAny tests whether this Flag has any flag bits in expected present.

Where there is only one bit set in expected, MatchesAny equals MatchesAll.

func (Flag) MatchesStatus

func (f Flag) MatchesStatus(expected Status) bool

MatchesStatus tests whether this Flag matches the expected status. Generally, this is a MatchesAll test for Status.Flag, except that Ok only matches an absence of other flags.

func (Flag) Status

func (f Flag) Status() Status

Status tries to convert this flag into a single status.

type Status

type Status int

Status is the type of completed-run statuses.

const (
	// Unknown represents an unknown status.
	Unknown Status = iota
	// Ok indicates that a run completed successfully without incident.
	Ok
	// Filtered indicates that a run would have failed, but it has been caught by a filter.
	Filtered
	// Flagged indicates that a run completed successfully, but its observation was interesting.
	// Usually this means a counter-example occurred.
	Flagged
	// CompileFail indicates that a run failed because of the compilation failing.
	CompileFail
	// CompileTimeout indicates that a run failed because the compilation timed out.
	CompileTimeout
	// RunFail indicates that a run failed directly.
	RunFail
	// RunTimeout indicates that a run timed out.
	RunTimeout

	// FirstBad refers to the first status that represents an unwanted outcome.
	FirstBad = Flagged
	// Last is the last valid status.
	Last = RunTimeout
)

func FromCompileError

func FromCompileError(err error) (Status, error)

FromCompileError tries to see if err represents a non-fatal issue such as a timeout or process error. If so, it converts that error to a status and returns it alongside nil. Otherwise, it propagates the error forwards.

func FromRunError

func FromRunError(err error) (Status, error)

FromRunError tries to see if err represents a non-fatal issue such as a timeout or process error. If so, it converts that error to a status and returns it alongside nil. Otherwise, it propagates the error forwards.

func FromString

func FromString(s string) (Status, error)

FromString tries to resolve s to a status code.

func (Status) CountsForTiming

func (i Status) CountsForTiming() bool

CountsForTiming is true if this status should be logged in compiler/run timing data.

Any compile or run that is not filtered and executes to completion counts for timing purposes (so, ok or flagged compiles/runs).

func (Status) Flag

func (i Status) Flag() Flag

Flag gets the flag equivalent of this status.

func (Status) IsBad

func (i Status) IsBad() bool

IsBad is true if, and only if, this status is in-bounds, not OK, and not unknown.

func (Status) IsInBounds

func (i Status) IsInBounds() bool

IsInBounds is true if, and only if, this status is in bounds.

func (Status) IsOk

func (i Status) IsOk() bool

IsOk is true if, and only if, this status is StatusOk.

Example

ExampleStatus_IsOk is a runnable example for Status.IsOk.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/subject/status"
)

func main() {
	fmt.Println("is", status.Ok, "ok?", status.Ok.IsOk())
	fmt.Println("is", status.Flagged, "ok?", status.Flagged.IsOk())
	fmt.Println("is", status.CompileFail, "ok?", status.CompileFail.IsOk())

}
Output:

is Ok ok? true
is Flagged ok? false
is CompileFail ok? false

func (Status) MarshalJSON

func (i Status) MarshalJSON() ([]byte, error)

MarshalJSON marshals a Status to JSON via its string representation.

func (Status) MarshalText

func (i Status) MarshalText() ([]byte, error)

MarshalText marshals a Status to text via its string representation.

func (Status) String

func (i Status) String() string

func (*Status) UnmarshalJSON

func (i *Status) UnmarshalJSON(bytes []byte) error

UnmarshalJSON unmarshals a Status from JSON via its string representation.

func (*Status) UnmarshalText

func (i *Status) UnmarshalText(text []byte) error

UnmarshalText unmarshals a Status from text via its string representation.

Jump to

Keyboard shortcuts

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