test

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Parses and interprets the CodeQL betterjson test output format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogResults

func LogResults(results []TestResult) (passed, failed int)

LogResults emits one PASS/FAIL slog line per result and returns the counts.

func RunUnitTests

func RunUnitTests(base, lang, codeqlArgs string, reportOutput *string, numThreads int) error

RunUnitTests resolves and runs all CodeQL unit tests for the given language under base, reporting a summary via slog. A TestReport is written to disk only when reportOutput is non-nil:

  • reportOutput == nil → no report written
  • *reportOutput == "" → <base>/target/test/test-report-<timestamp>.json
  • *reportOutput != "" → the caller-supplied path

func WriteReport

func WriteReport(path string, r *TestReport) error

WriteReport writes r to path as indented JSON, creating parent directories as needed.

Types

type Event

type Event struct {
	Type             string    `json:"type"`
	Test             string    `json:"test,omitempty"`
	TestDirectory    string    `json:"testDirectory,omitempty"`
	DatasetDirectory string    `json:"datasetDirectory,omitempty"`
	Pass             bool      `json:"pass,omitempty"`
	Messages         []Message `json:"messages,omitempty"`
	CompilationMs    int       `json:"compilationMs,omitempty"`
	EvaluationMs     int       `json:"evaluationMs,omitempty"`
	Expected         string    `json:"expected,omitempty"`
	FailureMessage   string    `json:"failureMessage,omitempty"`
}

Event represents a single event from the CodeQL betterjson output format.

func Parse

func Parse(data []byte) ([]Event, error)

Parse decodes the betterjson array from raw bytes.

type Message

type Message struct {
	Message  string `json:"message,omitempty"`
	Severity string `json:"severity,omitempty"`
}

Message is an inline diagnostic message attached to a testCompleted event.

type ReportMetadata

type ReportMetadata struct {
	Timestamp  time.Time `json:"timestamp"`
	Language   string    `json:"language"`
	NumThreads int       `json:"numThreads"`
}

type ReportSummary

type ReportSummary struct {
	Total      int   `json:"total"`
	Passed     int   `json:"passed"`
	Failed     int   `json:"failed"`
	DurationMs int64 `json:"durationMs"`
}

type Summary

type Summary struct {
	Total  int
	Passed int
	Failed int
}

Summary accumulates pass/fail counts across all events.

func LogEvents

func LogEvents(events []Event) (Summary, error)

LogEvents processes events and emits structured log lines. It returns a summary and any test failures as an error.

type TestMessage

type TestMessage struct {
	Severity string `json:"severity,omitempty"`
	Message  string `json:"message,omitempty"`
}

type TestReport

type TestReport struct {
	Metadata ReportMetadata `json:"metadata"`
	Summary  ReportSummary  `json:"summary"`
	Results  []TestResult   `json:"results"`
}

TestReport is the qlt-owned artifact produced by RunUnitTests. It is stable within qlt and decoupled from codeql's CLI output format.

type TestResult

type TestResult struct {
	Name          string        `json:"name"`
	Path          string        `json:"path"`
	Pass          bool          `json:"pass"`
	CompilationMs int           `json:"compilationMs"`
	EvaluationMs  int           `json:"evaluationMs"`
	Expected      string        `json:"expected,omitempty"`
	Messages      []TestMessage `json:"messages,omitempty"`
}

func ParseResults

func ParseResults(data []byte) ([]TestResult, error)

ParseResults decodes codeql's --format=json output into qlt TestResult values.

Jump to

Keyboard shortcuts

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