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 NoSuchVariableError
- type ParseInfo
- type Suite
- func (suite *Suite) AddEnvFiles(files ...string)
- func (suite *Suite) AddImports(folders ...string)
- 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) File(path string) *fs.File
- func (suite *Suite) Files() ([]string, error)
- func (suite *Suite) FindAllFiles() []string
- func (suite *Suite) FindModule(name string) (string, error)
- func (suite *Suite) Getenv(key 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() ([]*fs.File, error)
- func (suite *Suite) IsOwned(uri string) bool
- func (suite *Suite) LatestResults() (*results.DB, error)
- func (suite *Suite) Name() (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() *fs.File
- func (suite *Suite) SetName(name string)
- func (suite *Suite) SetRoot(folder string)
- func (suite *Suite) Sources() ([]*fs.File, 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 NoSuchVariableError ¶
type NoSuchVariableError struct {
Name string
}
func (*NoSuchVariableError) Error ¶
func (e *NoSuchVariableError) Error() string
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) AddEnvFiles ¶
AddEnvFiles adds the TOML formatted files to the list of environment files to look for variables.
func (*Suite) AddImports ¶
AddImports appends folders.. to the known imports list.
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) File ¶
File returns a new file struct for reading.
Environment variable NTT_CACHE will be used to find path, if path is a single file-name without leading directory.
func (*Suite) Files ¶
Files returns all .ttcn3 available. It will not return generated .ttcn3 files. On error Files will return an error.
func (*Suite) FindAllFiles ¶ added in v0.7.0
FindAllFiles returns all .ttcn3 files including auxiliary files from k3 installation
func (*Suite) FindModule ¶
FindModule tries to find a .ttcn3 based on its module name.
func (*Suite) Getenv ¶
Getenv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present. Getenv will return an error object for critical errors, like IO or syntax errors in env files.
Getenv looks for the key in the process environment first. If not found, it searches for key in all env files and finally it tries the variables-section in the manifest, if any.
If key starts with "NTT" and could not be found, Getenv will replace the prefix with "K3" to help with migrating old scripts. For example, when looking for "NTT_FOO" following lookups will happen:
os.Getenv("NTT_FOO") os.Getenv("K3_FOO") suite.lookupEnvFile("$PWD/ntt.env", "NTT_FOO") suite.lookupEnvFile("$PWD/ntt.env", "K3_FOO") suite.lookupEnvFile("$PWD/k3.env", "NTT_FOO") suite.lookupEnvFile("$PWD/k3.env", "K3_FOO")
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) 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.