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

Consider running tests **without** src/ changes, to validate that they must **fail** #117

Open
Ocramius opened this issue Jul 25, 2022 · 7 comments
Labels
RFC Request for Comment; proposal for major new feature or changes.

Comments

@Ocramius
Copy link
Member

RFC

Q A
Proposed Version(s) ?
BC Break? No

Goal

We want to verify that the tests accompanying a source change do validate the source change.

Background

This was discussed with @ondrejmirtes in private chat.

When receiving a source change, the accompanying tests must be verified for their quality.

In order to do that, we could:

  1. checkout the changes
  2. reset source(s) (based on composer.json paths) to their pre-patch state
  3. run the tests, expect them to fail

Considerations

  • what to do when only tests are changed?
  • what to do when only sources are changed?
  • what to do when composer.lock changed together with the tests?

Proposal(s)

  1. we will need a CLI utility that verifies this behavior inside the continuous-integration container
  2. we will need to adjust the CI matrix action to generate the appropriate verification job
  3. we only operate on locked dependencies
@Ocramius Ocramius added the RFC Request for Comment; proposal for major new feature or changes. label Jul 25, 2022
@ondrejmirtes
Copy link

Two exceptions I realized that should be applied here:

  1. When the changes in src/ only remove code, it's possible that tests will not fail when the changes are reverted. For example we can remove untested dead code this way.
  2. When the changes in src/ are about code style only, tests will not fail when the changes are reverted.

It should be possible to detect 1) easily (0 added lines, X removed lines), but it's probably not possible to detect 2) reliably.

@staabm
Copy link

staabm commented Oct 29, 2022

  1. could be detected by running the "before-state" of a PR thru a CS tool and the "after-state". when comparing the results both CS differences should be normalized

@rajyan
Copy link

rajyan commented Oct 30, 2022

This seems difficult than it looks.
For example in https://github.com/phpstan/phpstan-src/pull/1934/files
I added a failing test https://github.com/phpstan/phpstan-src/pull/1934/files#r1008005278 and all other test cases were regression tests related to the code that was not covered.

I think the only way to know the intension of the commit is to express whether the test is a "failing test" or a "regression test" in the commit message or something.

so I can think of a CI that

  • Verify test addition/modification commit’s commit message includes some keywords to distinguish the test type
  • Run test with src/ reset and verify the results by test types

@Ocramius
Copy link
Member Author

Note: the composer.json autoload section should be used to determine what to git reset.

@boesing
Copy link
Member

boesing commented Dec 19, 2022

Not 100% sure what this is about. Do we talk about something like:

git diff --staged ${TARGET_BRANCH_REF} src/ > pr.patch
git checkout ${TARGET_BRANCH_REF}
git apply pr.patch
vendor/bin/phpunit

@Xerkus
Copy link
Member

Xerkus commented Dec 19, 2022

more like

git checkout "${GITHUB_REF}"
git checkout "${GITHUB_BASE_REF}" -- $(get_src_paths_from_composer())
vendor/bin/phpunit # fail if this does not fail

@staabm
Copy link

staabm commented Dec 19, 2022

See the linked PR above

phpstan/phpstan-src#2029

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request for Comment; proposal for major new feature or changes.
Projects
None yet
Development

No branches or pull requests

6 participants