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 ¶
- Variables
- type IdentInfo
- type ParseInfo
- type Suite
- func (suite *Suite) AddSources(files ...string)
- func (suite *Suite) DefinitionAt(file string, line int, column int) (*IdentInfo, error)
- func (suite *Suite) Environ() ([]string, error)
- func (suite *Suite) Expand(v string) (string, error)
- func (suite *Suite) Files() ([]string, error)
- func (suite *Suite) FindModule(name string) (string, error)
- func (suite *Suite) Getenv(v string) (string, error)
- func (suite *Suite) Id() (int, error)
- func (suite *Suite) IdentifierAt(mod *ParseInfo, line int, column int) *ast.Ident
- func (suite *Suite) Imports() ([]string, error)
- func (suite *Suite) LatestResults() (*results.DB, error)
- func (suite *Suite) Name() (string, error)
- func (suite *Suite) ParametersDir() (string, error)
- func (suite *Suite) ParametersFile() (*fs.File, error)
- func (suite *Suite) Parse(file string) *ParseInfo
- func (suite *Suite) ParseWithAllErrors(file string) *ParseInfo
- func (suite *Suite) Root() string
- func (suite *Suite) SetName(name string)
- func (suite *Suite) SetRoot(folder string)
- func (suite *Suite) Sources() ([]string, error)
- func (suite *Suite) Tags(file string) (*ParseInfo, []ast.Node)
- func (suite *Suite) TestHook() (*fs.File, error)
- func (suite *Suite) Timeout() (float64, error)
- func (suite *Suite) Variables() (map[string]string, error)
- type SyntaxError
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
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
type Suite ¶
type Suite struct {
// contains filtered or unexported fields
}
Suite represents a TTCN-3 test suite.
func NewFromArgs ¶
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 ¶
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 ¶
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 ¶
AddSources appends files... to the known sources list.
func (*Suite) DefinitionAt ¶ added in v0.7.0
DefinitionAt parses file and returns IdentInfo about identifier at position line:column.
func (*Suite) Environ ¶
Environ returns a copy of strings representing the environment, in the form "key=value".
func (*Suite) FindModule ¶
FindModule tries to find a .ttcn3 based on its module name.
func (*Suite) Id ¶
Id returns the unique session id (aka NTT_SESSION_ID). This ID is the smallest integer available on this machine.
func (*Suite) IdentifierAt ¶
IdentifierAt returns token of identifier at position line:column.
func (*Suite) Imports ¶
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) Name ¶
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
ParametersDir return the absolute path retrieven from either * parameters_dir field from manifest * suites root path.
func (*Suite) ParametersFile ¶
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 ¶
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) SetRoot ¶
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 ¶
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
Tags will return all named nodes (defintions, enums, ...) from a file.
func (*Suite) TestHook ¶
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.