project

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package project provides a tool-independent interface for working with various TTCN-3 project layouts and configurations. The interface is intended to be uniform across all project layouts. Supported layouts will be extended over time.

Here is a simple example, opening a project configuration:

conf, err := project.Open("/path/to/project")
if err != nil {
	log.Fatal(err)
}

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSources = errors.New("no sources")
	ErrNotFound  = errors.New("not found")
)
View Source
var (
	ManifestFile = "package.yml"
	IndexFile    = "ttcn3_suites.json"
)

Functions

func Build added in v0.16.2

func Build(c *Config) error

Build builds a project.

func EncodingFromURI added in v0.16.2

func EncodingFromURI(uri string) (string, error)

Encoding returns the ASN.1 encoding for a given URI. Current implementation always returns "per", unless the URI contains the string "rrc"

func Files

func Files(c *Config) ([]string, error)

Files returns the list of TTCN-3 source files. Genereated files are excluded for now, but might be added in the future.

func NameFromURI added in v0.16.2

func NameFromURI(uri string) (string, error)

NameFromURI derives a TTCN-3 compatible name from a path or URI.

Types

type Config added in v0.16.2

type Config struct {
	// The Manifest pulls in most of the project configuration.
	Manifest `json:",inline"`

	// ManifestFile is the path to the manifest file.
	ManifestFile string `json:"manifest_file"`

	// Root is the root directory of the project. Usually this is the
	// directory of the manifest file.
	Root string

	// SourceDir is the directory containing source files, data files or
	// additional configuration files. SourceDir and Root are usually
	// identical, unless manifest was generated into a dedicated build
	// directory.
	SourceDir string `json:"source_dir"`

	// EnvFile is the path to the environment file. The content of the
	// environment file will overwrite variables defined in the manifest.
	// Default:
	//
	// 	${NTT_CACHE}/ntt.env
	EnvFile string `json:"env_file"`

	// ResultsFile is the path to the results file.
	ResultsFile string `json:"results_file"`

	K3 struct {
		k3.Instance `json:",inline"`

		// T3XF is the path to the T3XF file.
		T3XF string `json:"t3xf"`
	}
	// contains filtered or unexported fields
}

Config describes a single project configuration. It aggregates various sources, such as manifest files, parameters files, environment files, ...

func NewConfig added in v0.16.2

func NewConfig(opts ...ConfigOption) (*Config, error)

func Open

func Open(args ...string) (*Config, error)

Open returns the best possible configuration using the given arguments.

Without any arguments Open will open the current working directory, unless environment variable NTT_SOURCE_DIR is set.

If you pass a manifest file as single argument, Open will use it directly.

If you pass a directory as single argument, Open will first look for a package.yml and use it.

If no package.yml is found Open will look for TTCN-3 source files. It will look recursively if directory contains typical project root files (i.e. build.sh, testcases-folder, ...). Open will also recursively load TTCN-3 source files from typical import-directories (i.e ../common).

type ConfigOption added in v0.16.2

type ConfigOption func(*Config) error

func AutomaticEnv added in v0.16.2

func AutomaticEnv() ConfigOption

AutomaticEnv let environment variables with NTT_ prefix overwrite configuration. Currently supported are: NTT_NAME, NTT_SOURCES, NTT_IMPORTS, NTT_PARAMETERS_FILE, NTT_HOOKS_FILE, NTT_LINT_FILE, NTT_TIMEOUT.

func AutomaticRoot added in v0.16.2

func AutomaticRoot(root string) ConfigOption

AutomaticRoot sets the root directory and automatically sets the source and imports directories.

If the root directory contains a package.yml, sources and imports are set from the manifest exclusively.

AutomaticRoot will load TTCN-3 source files recursively, if the root directory contains typical project root files (e.g. build.sh, testcases/, ...).

Additionally AutomaticRoot finds common import directories relative to the root folder (i.e ../library or ../common) and recursively adds all folders containing TTCN-3 source files.

func WithDefaults added in v0.16.2

func WithDefaults() ConfigOption

WithDefaults initializes Root, SourceDir, Name, ParametersFile and HooksFile.

func WithImports added in v0.16.2

func WithImports(dirs ...string) ConfigOption

WithImports sets the imports of the project.

func WithIndex added in v0.16.2

func WithIndex(file string) ConfigOption

WithIndex uses hints from given index file to configure source directories.

func WithK3 added in v0.16.2

func WithK3() ConfigOption

func WithManifest added in v0.16.2

func WithManifest(file string) ConfigOption

WithManifest reads a manifest file (package.yml).

expand variable references recursively. Environment variables overwrite variables defined in environment files. Variables defined in environment files overwrite variables defined in the manifest. Undefined variables won't be expanded and will return an error.

func WithRoot added in v0.16.2

func WithRoot(root string) ConfigOption

WithRoot sets the root directory of the project.

func WithSourceDir added in v0.16.2

func WithSourceDir(dir string) ConfigOption

WithSourceDir sets the source directory of the project.

func WithSources added in v0.16.2

func WithSources(srcs ...string) ConfigOption

WithSources sets the sources of the project.

type ExecuteCondition added in v0.16.2

type ExecuteCondition struct {
	Presets []string
}

ExecuteCondition specifies conditions for executing a testcase.

type Index added in v0.16.2

type Index struct {
	// SourceDir is the top level source directory.
	SourceDir string `json:"source_dir"`

	// BinaryDir is the top level binary directory.
	BinaryDir string `json:"binary_dir"`

	// Suite is a list of directories to search for project configuration files.
	Suites []Suite `json:"suites"`
}

Index specifies where to look for project configuration files.

type Manifest

type Manifest struct {
	// Name is a short name of the project. It is recommended to use TTCN-3
	// identifiers (A-Za-z0-9_).
	Name string

	Version     string
	Description string
	Author      string
	License     string
	Homepage    string
	Repository  string
	Bugs        string
	Keywords    []string

	// Sources is a list of source files which provide the TTCN-3
	// test-cases.
	Sources []string

	// Imports is list of dependencies, which are required to run TTCN-3
	// test-cases. E.g. common code, adapters, codecs, ...
	Imports []string

	// BeforeBuild is a list of shell commands to be executed before
	// building. An exit code unequal to 0 will cancel any further
	// execution.
	BeforeBuild []string `json:"before_build"`

	// AfterBuild is a list of shell commands to be executed after
	// building. An exit code unequal to 0 will cancel any further
	// execution.
	AfterBuild []string `json:"after_build"`

	// BeforeRun is execute before any tests are run. An exit code unequal
	// to 0 will cancel any further test execution.
	BeforeRun []string `json:"before_run"`

	// AfterRun is executed after all tests are run.
	AfterRun []string `json:"after_run"`

	// BeforeTest is executed before each test. An exit code unequal to 0
	// will prevent test execution.
	BeforeTest []string `json:"before_test"`

	// AfterTest is executed after each test. An exit code unequal to 0
	// will result in an error verdict.
	AfterTest []string `json:"after_test"`

	// Variables is a list of variables that can be used in the
	// configuration files. Environment variables and variables defined in
	// the environment file (ntt.env) will overwrite variables defined in
	// this variables section.
	Variables env.Env

	// Diagnostics is a list of diagnostics flags used by compilator
	Diagnostics []string `json:"diagnostics"`

	// Parameters is an embedded parameters file.
	Parameters `json:",inline"`

	// ParametersFile is the path to the parameters file. Default:
	//
	// 	${NTT_SOURCE_DIR}/${NTT_NAME}.parameters
	ParametersFile string `json:"parameters_file"`

	// HooksFile is the path to the hooks file. Default:
	//
	// 	${NTT_SOURCE_DIR}/${NTT_NAME}.hooks
	HooksFile string `json:"hooks_file"`

	// LintFile is the path to the lint configuration file. Default:
	//
	// ${NTT_SOURCE_DIR}/ntt-lint.yml
	LintFile string `json:"lint_file"`
}

The Manifest file (package.yml).

type Parameters added in v0.16.2

type Parameters struct {
	// Global test configuration
	TestConfig `json:",inline"`

	// Presets provides configuration presets, which can be used for global
	// and test specific configuration.
	Presets map[string]TestConfig

	// Execute provides a list of test specific configuration. Each entry
	// specifies how and when a test should be executed.
	Execute []TestConfig
}

The Parameters file provide runtime configuration for a project (e.g. parameters files)

func (*Parameters) GlobalConfig added in v0.18.0

func (p *Parameters) GlobalConfig(presets ...string) (TestConfig, error)

GlobalCOnfig returns the global test configuration with applied presets

func (*Parameters) TestConfigs added in v0.18.0

func (p *Parameters) TestConfigs(name string, presets ...string) ([]TestConfig, error)

TestConfigs returns the test configurations matching the given name and applied presets.

type Rules added in v0.18.0

type Rules struct {
	// Only execute testcase if the given conditions are met.
	Only *ExecuteCondition `json:",omitempty"`

	// Do not execute testcase if the given conditions are met.
	Except *ExecuteCondition `json:",omitempty"`
}

type Suite added in v0.16.2

type Suite struct {
	// RootDir is the root directory of the project. This is usually where the package.yml is located.
	RootDir string `json:"root_dir"`

	// SourceDir is the directory where the test suite source files are located.
	SourceDir string `json:"source_dir"`

	// Target is an optional build target.
	Target string `json:"target,omitempty"`
}

Suite specifies the root and source directories of a project.

func Discover

func Discover(path string) []Suite

Discover walks towards the file system root and collects known test suite layouts.

Discover returns a list of potential test suite root directories.

type Task added in v0.16.2

type Task interface {
	// Inputs returns the list of input files.
	Inputs() []string

	// Outputs returns the list of output files.
	Outputs() []string

	// Run executes the task.
	Run() error

	// String returns a string representation of the task.
	String() string
}

Task is a build task.

func BuildTasks added in v0.16.2

func BuildTasks(c *Config) ([]Task, error)

BuildTasks returns the build tasks required to generate and build the test executable and its dependencies.

func ImportTasks added in v0.16.2

func ImportTasks(c *Config, uri string) ([]Task, error)

ImportTasks returns the build tasks required to generate and build a given test suite dependency.

type TestConfig added in v0.16.2

type TestConfig struct {
	// A pattern describing a test. Optional testcase parameters are allowed.
	Test string `json:",omitempty"`

	// Presets is a list of preset configurations to be used to execute
	// the test.
	Preset []string `json:",omitempty"`

	// Timeout in seconds.
	Timeout yaml.Duration `json:",omitempty"`

	// Module parameters
	Parameters map[string]string `json:",omitempty"`

	// Rules describe when a configuration should be used.
	Rules `json:",inline"`
}

A TestConfig specifies how and when a testcase should be executed.

func MergeTestConfig added in v0.16.2

func MergeTestConfig(a, b TestConfig) TestConfig

MergeTestConfig merges two test configurations. Scalar values from b override values from a. Maps are merged. Arrays are appended.

Directories

Path Synopsis
internal
k3
Package k3 provides convenience functions for supporting k3 toolchain.
Package k3 provides convenience functions for supporting k3 toolchain.

Jump to

Keyboard shortcuts

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