diff --git a/cmake/FindNTT.cmake b/cmake/FindNTT.cmake index b7b48bc2..e5b60599 100644 --- a/cmake/FindNTT.cmake +++ b/cmake/FindNTT.cmake @@ -50,6 +50,7 @@ manifest. [PARAMETERS_FILE file] [WORKING_DIRECTORY dir] [TARGETS target1...] + [DIAGNOSTICS flags] ) ``add_ttcn3_suite`` creates a target TGT and test suite manifest @@ -93,6 +94,9 @@ manifest. Add additional target-level dependencies. This is used to assure SUTs are built before a test is executed. + ``DIAGNOSTICS flags`` + Specifies the compiler diagnostics flags + ]====================================================================] if(TTCN3_PROTOBUF_INCLUDED) @@ -134,7 +138,7 @@ file(REMOVE "${CMAKE_BINARY_DIR}/ttcn3_suites.json") function(add_ttcn3_suite TGT) set("ARGS_PREFIX" "") set("ARGS_OPTIONS" "") - set("ARGS_ONE_VALUE" "NAME;TIMEOUT;HOOKS_FILE;PARAMETERS_FILE;WORKING_DIRECTORY") + set("ARGS_ONE_VALUE" "NAME;TIMEOUT;HOOKS_FILE;PARAMETERS_FILE;WORKING_DIRECTORY;DIAGNOSTICS") set("ARGS_MULTI_VALUE" "VARS;SOURCES;DEPENDS;TARGETS") cmake_parse_arguments("${ARGS_PREFIX}" "${ARGS_OPTIONS}" "${ARGS_ONE_VALUE}" "${ARGS_MULTI_VALUE}" ${ARGN}) @@ -215,6 +219,14 @@ function(add_ttcn3_suite TGT) add_dependencies("${TGT}" "${x}") endforeach() + if (_DIAGNOSTICS) + string(REPLACE " " ";" _DIAGNOSTICS ${_DIAGNOSTICS}) + string(APPEND MANIFEST "diagnostics:\n") + foreach(x ${_DIAGNOSTICS}) + string(APPEND MANIFEST " - ${x}\n") + endforeach() + endif() + file(GENERATE OUTPUT "${MANIFEST_FILE}" CONTENT "${MANIFEST}") __ntt_add_db_entry("${CMAKE_BINARY_DIR}/ttcn3_suites.json" "${TGT}" "${_WORKING_DIRECTORY}" "${CMAKE_CURRENT_LIST_DIR}") diff --git a/error.go b/error.go index c90d0262..abadaa62 100644 --- a/error.go +++ b/error.go @@ -19,7 +19,7 @@ type errPattern struct { } func (e errPattern) Error() string { - return fmt.Sprintf("%s: error: %s", syntax.Begin(e.node), e.msg) + return fmt.Sprintf("%s:%s: error: %s", syntax.Filename(e.node), syntax.Begin(e.node), e.msg) } func (e errPattern) IsSilent() bool { return isSilent(e.node, "TemplateDef") } @@ -30,8 +30,8 @@ type errLines struct { } func (e errLines) Error() string { - return fmt.Sprintf("%s: error: %q must not have more than %d lines (%d)", - syntax.Begin(e.node), syntax.Name(e.node), style.MaxLines, e.lines) + return fmt.Sprintf("%s:%s: error: %q must not have more than %d lines (%d)", + syntax.Filename(e.node), syntax.Begin(e.node), syntax.Name(e.node), style.MaxLines, e.lines) } func (e errLines) IsSilent() bool { return isSilent(e.node, "CodeStatistics.TooLong") } @@ -41,8 +41,8 @@ type errBraces struct { } func (e errBraces) Error() string { - return fmt.Sprintf("%s: error: braces must be in the same line or same column", - syntax.Begin(e.right)) + return fmt.Sprintf("%s:%s: error: braces must be in the same line or same column", + syntax.Filename(e.right), syntax.Begin(e.right)) } type errComplexity struct { @@ -51,8 +51,8 @@ type errComplexity struct { } func (e errComplexity) Error() string { - return fmt.Sprintf("%s: error: cyclomatic complexity of %q (%d) must not be higher than %d", - syntax.Begin(e.node), syntax.Name(e.node), e.complexity, style.Complexity.Max) + return fmt.Sprintf("%s:%s: error: cyclomatic complexity of %q (%d) must not be higher than %d", + syntax.Filename(e.node), syntax.Begin(e.node), syntax.Name(e.node), e.complexity, style.Complexity.Max) } func (e errComplexity) IsSilent() bool { return isSilent(e.node, "CodeStatistics.TooComplex") } @@ -62,7 +62,7 @@ type errMissingCaseElse struct { } func (e errMissingCaseElse) Error() string { - return fmt.Sprintf("%s: error: missing case else in select statement", syntax.Begin(e.node)) + return fmt.Sprintf("%s:%s: error: missing case else in select statement", syntax.Filename(e.node), syntax.Begin(e.node)) } type errUsageExceedsLimit struct { @@ -73,8 +73,8 @@ type errUsageExceedsLimit struct { } func (e errUsageExceedsLimit) Error() string { - return fmt.Sprintf("%s: error: %q must not be used more than %d times. %s", - syntax.Begin(e.node), syntax.Name(e.node), e.limit, e.text) + return fmt.Sprintf("%s:%s: error: %q must not be used more than %d times. %s", + syntax.Filename(e.node), syntax.Begin(e.node), syntax.Name(e.node), e.limit, e.text) } type errUnusedModule struct { diff --git a/lint.go b/lint.go index d67be6e9..b3f22200 100644 --- a/lint.go +++ b/lint.go @@ -226,7 +226,6 @@ func lint(cmd *cobra.Command, args []string) error { for _, def := range tree.Modules() { mod := def.Node.(*syntax.Module) - if isWhiteListed(style.Ignore.Modules, syntax.Name(mod.Name)) { continue } @@ -236,6 +235,8 @@ func lint(cmd *cobra.Command, args []string) error { ccID := syntax.Node(mod) caseElse := make(map[syntax.Node]int) + checkNaming(mod, style.Naming.Modules) + checkBraces(mod.LBrace, mod.RBrace) mod.Inspect(func(n syntax.Node) bool { if n == nil { stack = stack[:len(stack)-1] @@ -248,10 +249,6 @@ func lint(cmd *cobra.Command, args []string) error { case *syntax.Ident: checkUsage(n) - case *syntax.Module: - checkNaming(n, style.Naming.Modules) - checkBraces(n.LBrace, n.RBrace) - case *syntax.FuncDecl: ccID = n cc[ccID] = 1 // Intial McCabe value diff --git a/main.go b/main.go index 9cf036c5..68cdfb67 100644 --- a/main.go +++ b/main.go @@ -82,7 +82,7 @@ var ( if path, err := exec.LookPath("k3-" + args[0]); err == nil { return proc.Exec(path, args[1:]...) } - return fmt.Errorf("unknown command: %s", args[0]) + return fmt.Errorf("ntt: unknown command: %s", args[0]) } if err := cmd.Flags().Parse(args); err != nil { diff --git a/project/project.go b/project/project.go index 1a29e88d..d244d28c 100644 --- a/project/project.go +++ b/project/project.go @@ -129,6 +129,9 @@ type Manifest struct { // 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"` diff --git a/project/project_test.go b/project/project_test.go index affdfede..9f55a3e2 100644 --- a/project/project_test.go +++ b/project/project_test.go @@ -281,6 +281,14 @@ func TestWithManifest(t *testing.T) { assert.Nil(t, err) assert.Equal(t, "https://file.txt", c.HooksFile) }) + t.Run("diagnostics", func(t *testing.T) { + c, err := manifest("foo/bar/package.yml", ` + diagnostics: + - -w1 + - --white-list-dir=foo/bar/path`) + assert.Nil(t, err) + assert.Equal(t, []string([]string{"-w1", "--white-list-dir=foo/bar/path"}), c.Diagnostics) + }) t.Run("variables", func(t *testing.T) { c, err := manifest("foo/bar/package.yml", ` variables: