analysistest

package
v0.3.5-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package analysistest contains utility functions for testing the analysis tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AstFiles

func AstFiles(pkgs []*packages.Package) []*ast.File

AstFiles returns all the ast files in pkgs.

func LoadTest

func LoadTest(
	fsys ReadFileDirFS,
	dir string,
	extraFiles []string,
	options LoadTestOptions) result.Result[loadprogram.State]

LoadTest loads the program in the directory dir, looking for a main.go and a config.yaml. If additional files are specified as extraFiles, the program will be loaded using those files too.

LoadTest is a wrapper over loadprogram.NewState that sets all the config options and config file to load the program.

NOTE If the Analysis function runs without error but no analysis entrypoints are detected, that may mean that the config's code id's package names do not patch the package name of the SSA program. Try changing the package name to the test directory name to fix the issue.

func MapComments

func MapComments(fs []*ast.File, fmap func(*ast.Comment))

MapComments runs fmap on every comment in fs.

Types

type AnnotationID

type AnnotationID struct {
	// ID is the value of an annotation id.
	// e.g. @Source(id)
	//              ^^
	ID string
	// Meta is the identifier of the second portion of an annotation id.
	// This represents an annotation id metadata, usually for trace information.
	// e.g. @Source(id call:example1->call:helper)
	//                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
	// Meta can be empty.
	// e.g. @Source(id)
	Meta string
	// Pos is the position of the annotation.
	Pos LPos
}

AnnotationID represents an identifier in an annotation.

func (AnnotationID) String

func (id AnnotationID) String() string

type LPos

type LPos struct {
	// Filename is the file name of the position
	Filename string
	// Line is the line number in the file
	Line int
}

LPos is a line position

func NewLPos

func NewLPos(pos token.Position) LPos

NewLPos constructs an LPos from pos.

func RemoveColumn

func RemoveColumn(pos token.Position) LPos

RemoveColumn transforms a token.Position into a LPos by removing the column information

func (LPos) String

func (p LPos) String() string

type LoadTestOptions

type LoadTestOptions struct {
	// Whether to apply the rewriting steps before analyzing the program
	ApplyRewrite bool
	// Which platform
	Platform string
}

LoadTestOptions groups the options of the LoadTest function together.

type ReadFileDirFS

type ReadFileDirFS interface {
	fs.ReadDirFS
	fs.ReadFileFS
}

ReadFileDirFS represents a filesystem that can read both directories and files.

type TargetToSources

type TargetToSources map[AnnotationID]map[AnnotationID]bool

TargetToSources is a mapping from a target annotation (e.g. ex in @Sink(ex, ex2)) to a source annotation (e.g. ex in @Source(ex, ex2)).

func (TargetToSources) HasMetadata

func (t TargetToSources) HasMetadata() bool

HasMetadata returns true if the TargetToSources mapping contains metadata

Jump to

Keyboard shortcuts

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