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

Use a consistent approach for organising test fixture files #681

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Sep 21, 2023

Previously test fixtures were located under a mixture of:

  • <crate>/fixtures/
  • <crate>/test-fixtures/

Now for consistency they are all located under:
<crate>/tests/fixtures/

This matches the pattern already used by the Python CNB, Procfile CNB etc.

GUS-W-14161083.

Previously test fixtures were located under a mixture of:
* `<crate>/fixtures/`
* `<crate>/test-fixtures/`

Now  for consistency they are all located under:
`<crate>/tests/fixtures/`

This matches the pattern already used by the Python CNB, Procfile CNB etc.
.gitignore Show resolved Hide resolved
@edmorley edmorley marked this pull request as ready for review September 21, 2023 11:27
@edmorley edmorley requested a review from a team as a code owner September 21, 2023 11:27
Copy link
Member

@Malax Malax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for consistency, I'm not sure about the location though. Cargo will try to compile code it finds in tests, even when in subdirectories below tests. If we ever had a test fixture that Cargo would detect as test code (imagine a test fixture that is an app written in Rust) this location will give us trouble.

@edmorley
Copy link
Member Author

Cargo will try to compile code it finds in tests, even when in subdirectories below tests

That doesn't seem to be the case, when I tried an experiment just now?

With this PR there is already Rust code under one of the tests/fixtures/ directories, so I added a #[test] annotation to a random function, added a typo to that function, ran cargo test in the libcnb workspace root, and I didn't get a test failure (which suggests the fixture wasn't accidentally picked up).

My understanding of Cargo's automatic target discovery (https://doc.rust-lang.org/cargo/reference/cargo-targets.html#target-auto-discovery and https://doc.rust-lang.org/cargo/guide/project-layout.html) is that it only looks for modules (or lib/bin targets) within the top-level tests/ directory. These modules then need to import any nested modules for the nested modules to be picked up. (This is the only reason the "run all integration tests in a single binary" strategy works iirc.)

@Malax
Copy link
Member

Malax commented Sep 21, 2023

I tried adding a main.rs with a compile error into tests/fixtures and the tests didn't compile anymore, i.e. cargo test. It would be picked up because it's called main, I assume the same would be true for lib.rs any maybe bin/foo.rs too?

Edit: it seems only main.rs directly in test/fixtures causes issues.

@edmorley
Copy link
Member Author

edmorley commented Sep 21, 2023

Edit: it seems only main.rs directly in test/fixtures causes issues.

Yeah anything nested in a further subdirectory isn't picked up. There are already some main.rs files nested further (eg in the test buildpack fixtures).

Since all of our fixtures will be in their own directory, and not loose in the fixtures/ directory (plus the failure mode is pretty clear; it's not hard to debug undefined behaviour) I think this is fine :-)

@edmorley edmorley merged commit c194868 into main Sep 21, 2023
8 checks passed
@edmorley edmorley deleted the edmorley/consistent-fixture-paths branch September 21, 2023 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants