Skip to content

Commit

Permalink
Merge pull request #705 from moosq/master
Browse files Browse the repository at this point in the history
Merge branch 'master' of gitlabe1.ext.net.nokia.com:k3/ntt
  • Loading branch information
moosq authored Oct 10, 2023
2 parents bd93cad + 0a69f72 commit 5e6aaa8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
14 changes: 13 additions & 1 deletion cmake/FindNTT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})

Expand Down Expand Up @@ -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}")
Expand Down
20 changes: 10 additions & 10 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand All @@ -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") }
Expand All @@ -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 {
Expand All @@ -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") }
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
8 changes: 8 additions & 0 deletions project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5e6aaa8

Please sign in to comment.