pretty

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package pretty provides a pretty-printer for analyses.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ShowCompilers is true if compiler breakdowns should be shown.
	ShowCompilers bool

	// ShowCompilerLogs is true if compiler logs should be shown.
	ShowCompilerLogs bool

	// ShowOk is true if subjects with the 'ok' status should be shown.
	ShowOk bool

	// ShowPlanInfo is true if plan metadata should be shown.
	ShowPlanInfo bool

	// ShowSubjects is true if subject information should be shown.
	ShowSubjects bool

	// ShowMutation is true if mutation testing information should be shown.
	ShowMutation bool
}

Config is the type of pretty-printer configuration.

type Option

type Option func(*Printer)

Option is the type of options for a pretty-printer.

func Options

func Options(os ...Option) Option

Options combines the options os into a single option.

func ShowCompilerLogs

func ShowCompilerLogs(show bool) Option

ShowCompilerLogs sets whether the printer should show compiler metadata, according to show.

func ShowCompilers

func ShowCompilers(show bool) Option

ShowCompilers sets whether the printer should show compiler information, according to show.

func ShowMutation

func ShowMutation(show bool) Option

ShowMutation sets whether the printer should show mutation testing results, according to show.

func ShowOk

func ShowOk(show bool) Option

ShowOk sets whether the printer should show subjects in the 'ok' category, according to show.

func ShowPlanInfo

func ShowPlanInfo(show bool) Option

ShowPlanInfo sets whether the printer should show plan metadata, according to show.

func ShowSubjects

func ShowSubjects(show bool) Option

ShowSubjects sets whether the printer should show subject breakdowns, according to show.

func WriteTo

func WriteTo(w io.Writer) Option

WriteTo sets the printer's output to w.

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

Printer provides the ability to output human-readable summaries of analyses to a writer.

func NewPrinter

func NewPrinter(o ...Option) (*Printer, error)

NewPrinter constructs a pretty-printer using options o.

func (*Printer) OnAnalysis

func (p *Printer) OnAnalysis(a analysis.Analysis)

OnAnalysis writes an unsourced analysis a to this printer; if an error occurs, it tries to rescue.

Example

ExamplePrinter_OnAnalysis is a testable example for Printer.OnAnalysis.

package main

import (
	"context"
	"fmt"

	"github.com/c4-project/c4t/internal/plan"
	"github.com/c4-project/c4t/internal/plan/analysis"
	"github.com/c4-project/c4t/internal/stage/analyser/pretty"
)

func main() {
	p := plan.Mock()
	a, err := analysis.Analyse(context.Background(), p)
	if err != nil {
		fmt.Println("analysis error:", err)
		return
	}
	pw, err := pretty.NewPrinter(pretty.ShowCompilers(true))
	if err != nil {
		fmt.Println("printer init error:", err)
		return
	}
	pw.OnAnalysis(*a)

}
Output:

# Compilers
  ## clang
    - style: gcc
    - arch: x86
    - opt: none
    - mopt: none
    ### Times (sec)
      - compile: Min 200 Avg 200 Max 200
      - run: Min 0 Avg 0 Max 0
    ### Results
      - Ok: 1 subject(s)
  ## gcc
    - style: gcc
    - arch: ppc.64le.power9
    - opt: none
    - mopt: none
    ### Times (sec)
      - compile: Min 200 Avg 200 Max 200
      - run: Min 0 Avg 0 Max 0
    ### Results
      - Flagged: 1 subject(s)
      - CompileFail: 1 subject(s)

func (*Printer) Write

func (p *Printer) Write(a analysis.Analysis) error

Write writes an unsourced analysis a to this writer.

func (*Printer) WriteSourced

func (p *Printer) WriteSourced(a director.CycleAnalysis) error

WriteSourced writes a sourced analysis a to this printer.

type WithConfig

type WithConfig struct {
	// Data is the wrapped data.
	Data interface{}
	// Config is the configuration.
	Config Config
}

WithConfig is the type of things wrapped with pretty-printer config.

func AddConfig

func AddConfig(x interface{}, c Config) WithConfig

AddConfig wraps the item x with the config c.

Jump to

Keyboard shortcuts

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