Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Allow escaping : in run names with \: #3536

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/web/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,8 @@ optional arguments:
run-a-1, run-a-2 and run-b-1 then "run-a*" selects the
first two. In case of run names tag labels can also be
used separated by a colon (:) character:
"run_name:tag_name".
"run_name:tag_name". A run name containing a literal
colon (:) must be escaped: "run\:name".
-n NEW_RUNS [NEW_RUNS ...], --newname NEW_RUNS [NEW_RUNS ...]
The 'new' (right) side of the difference: these
analysis runs are compared to the -b/--basename runs.
Expand All @@ -1115,7 +1116,8 @@ optional arguments:
So if you have run-a-1, run-a-2 and run-b-1 then
"run-a*" selects the first two. In case of run names
tag labels can also be used separated by a colon (:)
character: "run_name:tag_name".
character: "run_name:tag_name". A run name containing
a literal colon (:) must be escaped: "run\:name".
-o {plaintext,rows,table,csv,json,html,gerrit,codeclimate} [{plaintext,rows,table,csv,json,html,gerrit,codeclimate} ...], --output {plaintext,rows,table,csv,json,html,gerrit,codeclimate} [{plaintext,rows,table,csv,json,html,gerrit,codeclimate} ...]
The output format(s) to use in showing the data.
- html: multiple html files will be generated in the
Expand Down
8 changes: 6 additions & 2 deletions web/client/codechecker_client/cmd/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ def __register_diff(parser):
"run-a-1, run-a-2 and run-b-1 then \"run-a*\" "
"selects the first two. In case of run names tag "
"labels can also be used separated by a colon "
"(:) character: \"run_name:tag_name\".")
"(:) character: \"run_name:tag_name\". A run "
"name containing a literal colon (:) must be "
"escaped: \"run\\:name\".")

parser.add_argument('-n', '--newname',
type=str,
Expand All @@ -523,7 +525,9 @@ def __register_diff(parser):
"\"run-a*\" selects the first two. In case of "
"run names tag labels can also be used separated "
"by a colon (:) character: "
"\"run_name:tag_name\".")
"\"run_name:tag_name\". A run "
"name containing a literal colon (:) must be "
"escaped: \"run\\:name\".")

__add_filtering_arguments(parser, DEFAULT_FILTER_VALUES, True)

Expand Down
10 changes: 8 additions & 2 deletions web/client/codechecker_client/cmd_line_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,20 @@ def process_run_args(client, run_args_with_tag: Iterable[str]):
"""Process the argument and returns run ids and run tag ids.

The elemnts inside the given run_args_with_tag list has the following
format: <run_name>:<run_tag>
format: `<run_name>:<run_tag>`.
If the run name is containing a literal ':', it should be escaped with a
backslash escape character before the `:`.
"""
# (The documentation comment above means \:, but Python would want to
# understand that as an escape sequence immediately.)

run_ids = []
run_names = []
run_tags = []

for run_arg_with_tag in run_args_with_tag:
run_with_tag = run_arg_with_tag.split(':')
run_with_tag = list(map(lambda n: n.replace(r"\:", ":"),
re.split(r"(?<!\\):", run_arg_with_tag)))
run_name = run_with_tag[0]
run_filter = ttypes.RunFilter(names=[run_name])

Expand Down
12 changes: 11 additions & 1 deletion web/tests/functional/diff_remote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def setup_package():
ret = codechecker.log_and_analyze(codechecker_cfg, test_proj_path_base)
if ret:
sys.exit(1)
print('Analyzing base was successful.')

# Store base results.
codechecker_cfg['reportdir'] = os.path.join(test_proj_path_base,
Expand All @@ -109,7 +110,11 @@ def setup_package():
ret = codechecker.store(codechecker_cfg, test_project_name_base)
if ret:
sys.exit(1)
print('Analyzing base was successful.')

# Store with a literal ':' in the name.
ret = codechecker.store(codechecker_cfg, test_project_name_base + ":base")
if ret:
sys.exit(1)

# New analysis
altered_file = os.path.join(test_proj_path_new, "call_and_message.cpp")
Expand All @@ -133,6 +138,11 @@ def setup_package():
if ret:
sys.exit(1)

# Store with a literal ':' in the name.
ret = codechecker.store(codechecker_cfg, test_project_name_new + ":new")
if ret:
sys.exit(1)

# Analyze multiple times to store results with multiple tags.
codechecker_cfg['reportdir'] = os.path.join(test_proj_path_update,
'reports')
Expand Down
19 changes: 19 additions & 0 deletions web/tests/functional/diff_remote/test_diff_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,25 @@ def test_diff_to_tag(self):
'--resolved', 'json', ["--url", self._url])
self.assertEqual(len(out[0]), 0)

def test_diff_between_literal_colon_in_name(self):
"""Count remote diff compared to a name which contains a literal ':'
but does not refer to a tag.
"""
# Name order matters from __init__ !
base_to_new = get_diff_results([self._test_runs[0].name],
[self._test_runs[1].name],
'--new', 'json', ["--url", self._url])

colon_base_name = self._test_runs[0].name + r"\:base"
colon_new_name = self._test_runs[1].name + r"\:new"

colon_base_to_new = get_diff_results([colon_base_name],
[colon_new_name],
'--new', 'json',
["--url", self._url])

self.assertEqual(len(base_to_new[0]), len(colon_base_to_new[0]))

def test_max_compound_select(self):
"""Test the maximum number of compound select query."""
base_run_id = self._test_runs[0].runId
Expand Down