Skip to content

Commit

Permalink
Select no tests if modified-only returns nothing (#2761)
Browse files Browse the repository at this point in the history
Previously it selected all tests. Now it respects that if nothing is
modified then nothing is selected.

Fix: #2449
  • Loading branch information
lukaszachy authored Mar 20, 2024
1 parent b9864b2 commit 5131014
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
8 changes: 8 additions & 0 deletions tests/discover/data/plans.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ execute:
modified-only: true
modified-ref: 8329db0^

/empty-modified:
discover:
how: fmf
path: ../../..
ref: 8329db0
modified-only: true
modified-ref: 8329db0

/distgit:
summary: Extract distgit sources
discover:
Expand Down
22 changes: 12 additions & 10 deletions tests/discover/modified.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ rlJournalStart
rlPhaseEnd

rlPhaseStartTest 'Command-line'
rlRun 'tmt run -rdv discover --how fmf --ref 8329db0 \
rlRun -s 'tmt run -rdv discover --how fmf --ref 8329db0 \
--modified-only --modified-ref 8329db0^ \
plan -n features/core finish 2>&1 >/dev/null | tee output'
rlAssertGrep 'summary: 1 test selected' output
rlAssertGrep '/tests/core/adjust' output
plan -n features/core finish >/dev/null'
rlAssertGrep 'summary: 1 test selected' "$rlRun_LOG"
rlAssertGrep '/tests/core/adjust' "$rlRun_LOG"
rlPhaseEnd

rlPhaseStartTest 'Plan'
rlRun 'env -C data tmt run -rdv discover \
plan -n fmf/modified finish 2>&1 >/dev/null | tee output'
rlAssertGrep 'summary: 1 test selected' output
rlAssertGrep '/tests/core/adjust' output
rlRun -s 'env -C data tmt run -rdv discover \
plan -n fmf/modified finish >/dev/null'
rlAssertGrep 'summary: 1 test selected' "$rlRun_LOG"
rlAssertGrep '/tests/core/adjust' "$rlRun_LOG"
rlPhaseEnd

rlPhaseStartCleanup
rlRun 'rm -f output' 0 'Remove tmp file'
rlPhaseStartTest 'No changes'
rlRun -s 'env -C data tmt run -rdv discover \
plan -n fmf/empty-modified >/dev/null'
rlAssertGrep 'summary: 0 tests selected' "$rlRun_LOG"
rlPhaseEnd
rlJournalEnd
6 changes: 6 additions & 0 deletions tmt/steps/discover/fmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,19 @@ def assert_git_url(plan_name: Optional[str] = None) -> None:
Command(
'git', 'log', '--format=', '--stat', '--name-only', f"{modified_ref}..HEAD"
), cwd=self.testdir)
self._tests: list['tmt.Test'] = []
if output.stdout:
directories = [os.path.dirname(name) for name in output.stdout.split('\n')]
modified = {f"^/{re.escape(name)}" for name in directories if name}
if not modified:
# Nothing was modified, do not select anything
return
self.debug(f"Limit to modified test dirs: {modified}", level=3)
names.extend(modified)
else:
self.debug(f"No modified directories between '{modified_ref}..HEAD' found.")
# Nothing was modified, do not select anything
return

# Initialize the metadata tree, search for available tests
self.debug(f"Check metadata tree in '{tree_path}'.")
Expand Down

0 comments on commit 5131014

Please sign in to comment.