ntt

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Overview

Package ntt provides test suite configuration. A test suite configuration is everything you need for building or running tests: TTCN-3, C/C++ and ASN.1 source files, codecs adapters, hooks, ...

Please note, the TTCN-3 and ASN.1 specs do not have the notion of packages or even files; only modules in a global scope. This becomes hard to organize and maintain when the number of files grows. Hence this package introduces the concept of packages similar to Go:

A package is a directory containing TTCN-3, ASN.1 or C/C++ source files. A test suite is a special package with an optional manifest (`package.yml`), the main package so to say. This manifest file specifies dependencies to other packages, as well as runtime specific configuration like test_hooks, timeout, module parameters, ... . The name of a package is the base-name of the directory. So choose the name carefully. Here are some hints for good naming: Everything which belongs together should be put together. Package names should describe their purpose, they should be short and easy to understand. Avoid catchall packages like: `utils`, `helpers`, `functions`, ...

You may use environment variables and variables from `ntt.env` at any place, also in `package.yml`. They become expanded when the suite is loaded.

Package YAML

The main package (aka suite) may contain a YAML configuration file `package.yml` to specify dependencies to other package and configure custom runtime configuration. Below keys are supported:

name                 Name of the package. Default is the directory name.

sources              Source files.

imports              Directories the suite depends on.

timeout              Default timeout for tests in seconds.

test_hook            Path to test_hook script. Default is `$NTT_NAME.control`.

parameters_file      Path to module parameters file. Default is `$NTT_NAME.parameters`

All keys can be overwritten by environment variables. For instance, to overwrite `test_hook` just set environment variable `NTT_TEST_HOOK`. Is it not recommended to overwrite list values like `NTT_SOURCES` and `NTT_IMPORTS`, because you might run into quoting issues with white-spaces.

Ad-hoc Packages

It is possible to create a suite just from a directory without any `package.yml`. The Config.Sources will contain the paths of all .ttcn3 sources files in that directory. Alternatively you may specify a list of .ttcn3 files directory. The associated will then be the current working directory.

Like with the configuration file, most values can be overwritten by environment variables.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSyntax           = errors.New("syntax error")
	ErrNoSuchIdentifier = errors.New("no such identifier")
	ErrRedefinition     = errors.New("redefinition")
	ErrNoIdentFound     = errors.New("no identifier found")
)

Functions

This section is empty.

Types

type IdentInfo

type IdentInfo struct {
	Syntax   ast.Node
	Position loc.Position
	Def      *IdentInfo
}

IdentInfo associates an identifier reference and its definition.

type ParseInfo

type ParseInfo struct {

	// Module is the syntax tree of a module. Note, multiple modules in a
	// single file is prohibited.
	Module *ast.Module

	// Err is the error result of last parse.
	Err error

	// FileSet is required decode position tags into file:line:column triplets.
	FileSet *loc.FileSet
	// contains filtered or unexported fields
}

ParseInfo represents a memoized syntax tree of a .ttcn3 file

func (*ParseInfo) ImportedModules added in v0.7.0

func (info *ParseInfo) ImportedModules() []string

func (*ParseInfo) Pos

func (info *ParseInfo) Pos(line int, column int) loc.Pos

Pos encodes a line and column tuple into a offset-based Pos tag. If file nas not been parsed yet, Pos will return loc.NoPos.

func (*ParseInfo) Position

func (info *ParseInfo) Position(pos loc.Pos) loc.Position

Position decodes a Pos tag into a Position. If file has not been parsed before, an empty Position is returned.

type Suite

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

Suite represents a TTCN-3 test suite.

func NewFromArgs

func NewFromArgs(args ...string) (*Suite, error)

NewFromArgs creates a suite from command line arguments. It expects either one directory as argument or a list of regular .ttcn3 files.

Calling NewFromArgs with an empty argument list will create a suite from current working directory or, if set, from NTT_SOURCE_DIR.

func NewFromDirectory

func NewFromDirectory(dir string) (*Suite, error)

NewFromDirectory creates a suite from directory dir. If the directory contains a manifest file (`package.yml`) it will be loaded. You may use the usual environment variables to overwrite configuration. If no source files were specified, NewFromDirectory will assign all .ttcn3 it finds.

NewFromDirectory returns an error if package.yml was not readable or hab syntax errors or if environment variables have incompatible type (e.g. float64 for NTT_TIMEOUT)

func NewFromFiles

func NewFromFiles(files ...string) (*Suite, error)

NewFromFiles creates a suite from a .ttcn3 files list. No root folder will be associated with the suite and `package.yml` will be ignored.

Except for `NTT_SOURCES` You may use the usual environment variables to overwrite default configuration.

Allowing only ttcn3 files is a compromise between keeping ntt tool simple and allowing user to create ad-hoc packages for proto-typing. This constraint might be lifted in the future.

func (*Suite) AddSources

func (suite *Suite) AddSources(files ...string)

AddSources appends files... to the known sources list.

func (*Suite) DefinitionAt added in v0.7.0

func (suite *Suite) DefinitionAt(file string, line int, column int) (*IdentInfo, error)

DefinitionAt parses file and returns IdentInfo about identifier at position line:column.

func (*Suite) Environ

func (suite *Suite) Environ() ([]string, error)

Environ returns a copy of strings representing the environment, in the form "key=value".

func (*Suite) Expand

func (suite *Suite) Expand(v string) (string, error)

Expand expands string v using Suite.Getenv

func (*Suite) Files

func (suite *Suite) Files() ([]string, error)

Files returns all TTCN-3 source files used by Suite.

func (*Suite) FindModule

func (suite *Suite) FindModule(name string) (string, error)

FindModule tries to find a .ttcn3 based on its module name.

func (*Suite) Getenv

func (suite *Suite) Getenv(v string) (string, error)

func (*Suite) Id

func (suite *Suite) Id() (int, error)

Id returns the unique session id (aka NTT_SESSION_ID). This ID is the smallest integer available on this machine.

func (*Suite) IdentifierAt

func (suite *Suite) IdentifierAt(mod *ParseInfo, line int, column int) *ast.Ident

IdentifierAt returns token of identifier at position line:column.

func (*Suite) Imports

func (suite *Suite) Imports() ([]string, error)

Imports returns the list of imported packages required to compile a Suite. The error will be != nil if imports could not be determined correctly. For example, when `package.yml` had syntax errors.

func (*Suite) LatestResults added in v0.6.3

func (suite *Suite) LatestResults() (*results.DB, error)

func (*Suite) Name

func (suite *Suite) Name() (string, error)

Name returns the name of the test suite. Or err != nil if the name could not determined correctly.

Name first checks for environment variable NTT_NAME, then if a name is specified in a manifest. Then if a name was specified explicitly. Next, if suite has a root folder, its base-name will be used. Last resort is the first source .ttcn3 without extension.

func (*Suite) ParametersDir added in v0.9.1

func (suite *Suite) ParametersDir() (string, error)

ParametersDir return the absolute path retrieven from either * parameters_dir field from manifest * suites root path.

func (*Suite) ParametersFile

func (suite *Suite) ParametersFile() (*fs.File, error)

ParametersFile return the File object to the parameter file. If no file was found, it will return nil. If an error occurred, like a parse error, then error is set appropriately.

func (*Suite) Parse

func (suite *Suite) Parse(file string) *ParseInfo

Parse returns the cached TTCN-3 syntax of the file. The actual TTCN-3 parser is called for every unique file exactly once.

func (*Suite) ParseWithAllErrors added in v0.7.0

func (suite *Suite) ParseWithAllErrors(file string) *ParseInfo

func (*Suite) Root

func (suite *Suite) Root() string

func (*Suite) SetName

func (suite *Suite) SetName(name string)

SetName will set the suites name.

func (*Suite) SetRoot

func (suite *Suite) SetRoot(folder string)

SetRoot set the root folder for Suite.

The root folder is the main-package, which may contain a manifest file (`package.yml`)

func (*Suite) Sources

func (suite *Suite) Sources() ([]string, error)

Sources returns the list of sources required to compile a Suite. The error will be != nil if input sources could not be determined correctly. For example, when `package.yml` had syntax errors.

func (*Suite) Tags added in v0.7.0

func (suite *Suite) Tags(file string) (*ParseInfo, []ast.Node)

Tags will return all named nodes (defintions, enums, ...) from a file.

func (*Suite) TestHook

func (suite *Suite) TestHook() (*fs.File, error)

TestHook return the File object to the test hook. If not hook was found, it will return nil. If an error occurred, like a parse error, then error is set appropriately.

func (*Suite) Timeout

func (suite *Suite) Timeout() (float64, error)

Timeout returns the configured timeout of the Suite. If there's no timeout, the function will return 0.

The error will be != nil if timeout could not be determined correctly. For example, when `package.yml` had syntax errors.

func (*Suite) Variables

func (suite *Suite) Variables() (map[string]string, error)

Variables will return a string map containing the variables-sections of the manifest files.

type SyntaxError

type SyntaxError struct {
	Pos, End loc.Position
}

Jump to

Keyboard shortcuts

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