Skip to content

Commit

Permalink
parser-cov: treat <unknown>: as empty file name
Browse files Browse the repository at this point in the history
The JSON-based output formats do not have problems with empty strings.

Related: https://issues.redhat.com/browse/OSH-496
  • Loading branch information
kdudka committed May 28, 2024
1 parent 52465d9 commit 13e6f04
Show file tree
Hide file tree
Showing 5 changed files with 2,281 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/lib/parser-cov.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,19 @@ EToken ErrFileLexer::readNext()
return T_UNKNOWN;
}

// read file name, event, and msg
evt_.fileName = sm[/* file */ 1];
evt_.event = sm[/* event */ 4];
evt_.msg = sm[/* msg */ 5];
// read file name
evt_.fileName = sm[/* file */ 1];
if (evt_.fileName == "<unknown>")
evt_.fileName.clear();

// parse line number
// parse line/col
evt_.line = parseInt(sm[/* line */ 2]);

// parse column number
evt_.column = parseInt(sm[/* col */ 3]);

// read event and msg
evt_.event = sm[/* event */ 4];
evt_.msg = sm[/* msg */ 5];

return T_EVENT;
}

Expand Down
1 change: 1 addition & 0 deletions tests/csgrep/0127-cov-parser-noloc-args.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--mode=json
346 changes: 346 additions & 0 deletions tests/csgrep/0127-cov-parser-noloc-stdin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,346 @@
Error: SHELLCHECK_WARNING (CWE-252):
./contrib/guide/get_started/00-cleanup.sh:6:1: warning[SC2164]: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Error: SHELLCHECK_WARNING (CWE-277):
./contrib/guide/get_started/12-datadir-create.sh:4:7: warning[SC2174]: When used with -p, -m only applies to the deepest directory.

Error: SHELLCHECK_WARNING:
./contrib/scripts/resetgnome:14:13: note[SC2006]: Use $(...) notation instead of legacy backticked `...`.

Error: SHELLCHECK_WARNING:
./contrib/scripts/resetgnome:15:25: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./contrib/scripts/resetgnome:17:10: note[SC2006]: Use $(...) notation instead of legacy backticked `...`.

Error: SHELLCHECK_WARNING:
./contrib/scripts/resetgnome:18:14: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./contrib/scripts/resetgnome:20:7: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./contrib/scripts/resetgnome:20:44: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./contrib/scripts/resetgnome:20:57: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING (CWE-398):
./contrib/template/.bash_profile:2:25: warning[SC1090]: ShellCheck can't follow non-constant source. Use a directive to specify location.

Error: SHELLCHECK_WARNING:
./contrib/template/.bashrc:21:3: note[SC1091]: Not following: /soft/rko-modules/tcl/init/bash was not specified as input (see shellcheck -x).

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/bar-defaults.sh:3:8: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/bar-loads.sh:3:8: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/bar-switch.sh:3:8: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/common_code.sh:6:6: note[SC2268]: Avoid x-prefix in comparisons as it no longer serves a purpose.

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/common_code.sh:11:6: note[SC2268]: Avoid x-prefix in comparisons as it no longer serves a purpose.

Error: SHELLCHECK_WARNING (CWE-569):
./doc/example/compiler-etc-dependencies/example-sessions/common_code.sh:34:7: warning[SC2124]: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.

Error: SHELLCHECK_WARNING (CWE-563):
./doc/example/compiler-etc-dependencies/example-sessions/common_code.sh:45:2: warning[SC2034]: GCCGNU appears unused. Verify use (or export if used externally).

Error: SHELLCHECK_WARNING (CWE-563):
./doc/example/compiler-etc-dependencies/example-sessions/common_code.sh:60:3: warning[SC2034]: AUTOFLAG appears unused. Verify use (or export if used externally).

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/foo-avail1.sh:3:8: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/foo-avail2.sh:3:8: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/foo-defaults.sh:3:8: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/foo-loads.sh:3:8: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/foo-switch.sh:3:8: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/modavail.sh:3:8: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING:
./doc/example/compiler-etc-dependencies/example-sessions/modversion.sh:3:8: note[SC2086]: Double quote to prevent globbing and word splitting.

Error: SHELLCHECK_WARNING (CWE-569):
./doc/example/compiler-etc-dependencies/example-sessions/ompi-switch.sh.m431:4:7: warning[SC2124]: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.

Error: SHELLCHECK_WARNING (CWE-571):
./doc/example/source-script-in-modulefile/bar-2.1/bar-setup.sh:2:8: warning[SC2155]: Declare and assign separately to avoid masking return values.

Error: SHELLCHECK_WARNING (CWE-670):
./doc/example/source-script-in-modulefile/bar-2.1/bar-setup.sh:2:23: warning[SC2128]: Expanding an array without an index only gives the first element.

Error: SHELLCHECK_WARNING (CWE-571):
./doc/example/source-script-in-modulefile/foo-1.2/foo-setup.sh:3:8: warning[SC2155]: Declare and assign separately to avoid masking return values.

Error: SHELLCHECK_WARNING (CWE-670):
./doc/example/source-script-in-modulefile/foo-1.2/foo-setup.sh:3:23: warning[SC2128]: Expanding an array without an index only gives the first element.

Error: SHELLCHECK_WARNING (CWE-477):
./init/bash.in:27:47: warning[SC2166]: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

Error: SHELLCHECK_WARNING (CWE-569):
./init/bash.in:32:31: warning[SC2089]: Quotes/backslashes will be treated literally. Use an array.

Error: SHELLCHECK_WARNING (CWE-569):
./init/bash.in:41:9: warning[SC2090]: Quotes/backslashes in this variable will not be respected.

Error: SHELLCHECK_WARNING (CWE-569):
./init/bash_completion.in:10:15: error[SC1035]: You are missing a required space here.

Error: SHELLCHECK_WARNING (CWE-477):
./init/bash_completion.in:10:27: warning[SC2166]: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

Error: SHELLCHECK_WARNING (CWE-477):
./init/bash_completion.in:22:20: warning[SC2166]: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:52:25: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:68:27: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:69:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:70:25: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:72:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:74:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:75:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:76:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:89:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:90:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:94:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:96:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-398):
./init/bash_completion.in:105:21: warning[SC2178]: Variable was used as an array but is now assigned a string.

Error: SHELLCHECK_WARNING (CWE-398):
./init/bash_completion.in:106:21: warning[SC2178]: Variable was used as an array but is now assigned a string.

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:108:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:109:33: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-829):
./init/bash_completion.in:116:4: warning[SC2091]: Remove surrounding $() to avoid executing output (or use eval if intentional).

Error: SHELLCHECK_WARNING (CWE-563):
./init/bash_completion.in:118:34: warning[SC2034]: cmds appears unused. Verify use (or export if used externally).

Error: SHELLCHECK_WARNING (CWE-563):
./init/bash_completion.in:118:39: warning[SC2034]: opts appears unused. Verify use (or export if used externally).

Error: SHELLCHECK_WARNING (CWE-140):
./init/bash_completion.in:127:31: warning[SC2207]: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

Error: SHELLCHECK_WARNING (CWE-398):
./init/bash_completion.in:164:25: warning[SC2178]: Variable was used as an array but is now assigned a string.

Error: SHELLCHECK_WARNING (CWE-398):
./init/bash_completion.in:165:25: warning[SC2178]: Variable was used as an array but is now assigned a string.

Error: SHELLCHECK_WARNING (CWE-477):
./init/ksh.in:27:47: warning[SC2166]: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

Error: SHELLCHECK_WARNING (CWE-569):
./init/ksh.in:32:31: warning[SC2089]: Quotes/backslashes will be treated literally. Use an array.

Error: SHELLCHECK_WARNING (CWE-569):
./init/ksh.in:41:9: warning[SC2090]: Quotes/backslashes in this variable will not be respected.

Error: SHELLCHECK_WARNING (CWE-156):
./init/profile.sh.in:10:23: warning[SC2046]: Quote this to prevent word splitting.

Error: SHELLCHECK_WARNING (CWE-398):
./init/profile.sh.in:14:6: warning[SC1090]: ShellCheck can't follow non-constant source. Use a directive to specify location.

Error: SHELLCHECK_WARNING:
./init/profile.sh.in:16:6: note[SC1091]: Not following: @initdir@/sh was not specified as input (see shellcheck -x).

Error: SHELLCHECK_WARNING (CWE-477):
./init/sh.in:27:47: warning[SC2166]: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

Error: SHELLCHECK_WARNING (CWE-569):
./init/sh.in:32:31: warning[SC2089]: Quotes/backslashes will be treated literally. Rewrite using set/"$@" or functions.

Error: SHELLCHECK_WARNING (CWE-569):
./init/sh.in:41:11: warning[SC2090]: Quotes/backslashes in this variable will not be respected.

Error: SHELLCHECK_WARNING:
./init/sh.in:59:14: warning[SC3045]: In POSIX sh, export -f is undefined.

Error: SHELLCHECK_WARNING:
./init/sh.in:60:14: warning[SC3045]: In POSIX sh, export -f is undefined.

Error: SHELLCHECK_WARNING:
./init/sh.in:61:20: warning[SC3045]: In POSIX sh, type -t is undefined.

Error: SHELLCHECK_WARNING:
./init/sh.in:62:17: warning[SC3045]: In POSIX sh, export -f is undefined.

Error: SHELLCHECK_WARNING:
./script/add.modules.in:22:9: note[SC2016]: Expressions don't expand in single quotes, use double quotes for that.

Error: SHELLCHECK_WARNING:
./script/add.modules.in:61:1: note[SC2162]: read without -r will mangle backslashes.

Error: SHELLCHECK_WARNING:
./script/add.modules.in:63:6: note[SC2268]: Avoid x-prefix in comparisons as it no longer serves a purpose.

Error: SHELLCHECK_WARNING:
./script/add.modules.in:102:9: note[SC2268]: Avoid x-prefix in comparisons as it no longer serves a purpose.

Error: SHELLCHECK_WARNING:
./script/add.modules.in:107:10: note[SC2268]: Avoid x-prefix in comparisons as it no longer serves a purpose.

Error: SHELLCHECK_WARNING:
./script/add.modules.in:127:12: note[SC2268]: Avoid x-prefix in comparisons as it no longer serves a purpose.

Error: SHELLCHECK_WARNING:
./script/add.modules.in:148:11: note[SC2268]: Avoid x-prefix in comparisons as it no longer serves a purpose.

Error: SHELLCHECK_WARNING:
./script/add.modules.in:153:10: note[SC2268]: Avoid x-prefix in comparisons as it no longer serves a purpose.

Error: SHELLCHECK_WARNING:
./script/add.modules.in:164:12: note[SC2268]: Avoid x-prefix in comparisons as it no longer serves a purpose.

Error: SHELLCHECK_WARNING (CWE-252):
./script/add.modules.in:190:1: warning[SC2164]: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Error: SHELLCHECK_WARNING (CWE-156):
./script/add.modules.in:199:7: warning[SC2046]: Quote this to prevent word splitting.

Error: SHELLCHECK_WARNING:
./script/add.modules.in:199:7: note[SC2006]: Use $(...) notation instead of legacy backticked `...`.

Error: SHELLCHECK_WARNING:
./script/commit-msg:49:6: note[SC2181]: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

Error: SHELLCHECK_WARNING (CWE-477):
./script/envml:83:15: warning[SC2166]: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

Error: SHELLCHECK_WARNING (CWE-477):
./script/envml:83:31: warning[SC2166]: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

Error: SHELLCHECK_WARNING (CWE-88):
./script/envml:89:12: error[SC2068]: Double quote array expansions to avoid re-splitting elements.

Error: SHELLCHECK_WARNING (CWE-563):
./script/envml:127:17: warning[SC2034]: module appears unused. Verify use (or export if used externally).

Error: SHELLCHECK_WARNING (CWE-156):
./script/mkroot:75:37: warning[SC2046]: Quote this to prevent word splitting.

Error: SHELLCHECK_WARNING:
./script/mkroot:75:37: note[SC2006]: Use $(...) notation instead of legacy backticked `...`.

Error: SHELLCHECK_WARNING:
./script/mkroot:75:38: note[SC2012]: Use find instead of ls to better handle non-alphanumeric filenames.

Error: SHELLCHECK_WARNING (CWE-156):
./script/mkroot:77:38: warning[SC2046]: Quote this to prevent word splitting.

Error: SHELLCHECK_WARNING:
./script/mkroot:77:38: note[SC2006]: Use $(...) notation instead of legacy backticked `...`.

Error: SHELLCHECK_WARNING:
./script/mkroot:77:39: note[SC2012]: Use find instead of ls to better handle non-alphanumeric filenames.

Error: SHELLCHECK_WARNING (CWE-156):
./script/mkroot:88:30: warning[SC2046]: Quote this to prevent word splitting.

Error: SHELLCHECK_WARNING:
./script/mkroot:88:30: note[SC2006]: Use $(...) notation instead of legacy backticked `...`.

Error: SHELLCHECK_WARNING:
./script/mkroot:88:31: note[SC2012]: Use find instead of ls to better handle non-alphanumeric filenames.

Error: SHELLCHECK_WARNING:
./script/mt:35:6: note[SC2181]: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

Error: SHELLCHECK_WARNING (CWE-456):
./script/mt:38:4: warning[SC2209]: Use var=$(command) to assign output (or quote to assign string).

Error: SHELLCHECK_WARNING (CWE-456):
./script/mt:42:1: warning[SC2209]: Use var=$(command) to assign output (or quote to assign string).

Error: SHELLCHECK_WARNING (CWE-88):
./script/mt:63:13: error[SC2068]: Double quote array expansions to avoid re-splitting elements.

Error: SHELLCHECK_WARNING (CWE-88):
./script/mt:63:34: error[SC2068]: Double quote array expansions to avoid re-splitting elements.

Error: SHELLCHECK_WARNING (CWE-140):
./script/mt:70:32: warning[SC2206]: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

Error: SHELLCHECK_WARNING (CWE-140):
./script/mt:70:43: warning[SC2206]: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

Error: SHELLCHECK_WARNING (CWE-140):
./script/mt:72:32: warning[SC2206]: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

Error: SHELLCHECK_WARNING (CWE-140):
./script/mt:72:43: warning[SC2206]: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

Error: SHELLCHECK_WARNING:
./script/mt:83:45: warning[SC2076]: Remove quotes from right-hand side of =~ to match as a regex rather than literally.

Error: SHELLCHECK_WARNING (CWE-140):
./script/mt:84:26: warning[SC2206]: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

Error: SHELLCHECK_WARNING:
./script/pre-commit:45:6: note[SC2181]: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

Error: SHELLCHECK_WARNING:
./script/pre-commit:47:9: note[SC2181]: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

Error: SHELLCHECK_WARNING:
./script/pre-commit:56:6: note[SC2181]: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

Error: SHELLCHECK_WARNING:
./script/pre-commit:80:6: note[SC2181]: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

Error: SHELLCHECK_WARNING:
<unknown>: error[too-many]: 115 occurrences of note[SC2086] exceeded the specified limit 16
./doc/example/compiler-etc-dependencies/example-sessions/ompi-defaults.sh:3:8: note: 99 occurrences of note[SC2086] were discarded because of this

Error: SHELLCHECK_WARNING (CWE-140):
<unknown>: error[too-many]: 29 occurrences of warning[SC2207] exceeded the specified limit 16
./init/bash_completion.in:128:37: note: 13 occurrences of warning[SC2207] were discarded because of this
Loading

0 comments on commit 13e6f04

Please sign in to comment.