Skip to content

Commit

Permalink
Select no tests if modified-only returns nothing
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 committed Mar 20, 2024
1 parent b9864b2 commit 48c8a85
Show file tree
Hide file tree
Showing 3 changed files with 24 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
4 changes: 4 additions & 0 deletions tmt/steps/discover/fmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ def assert_git_url(plan_name: Optional[str] = None) -> None:
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
self._tests: list['tmt.Test'] = []
return
self.debug(f"Limit to modified test dirs: {modified}", level=3)
names.extend(modified)
else:
Expand Down

0 comments on commit 48c8a85

Please sign in to comment.