Skip to content

testsuite: Run tests in temporary system directories #9717

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

Merged
merged 1 commit into from
Feb 28, 2024

Conversation

mpickering
Copy link
Collaborator

  1. Working directory is not contaminated with results of the testsuite. Tests can be written in a more liberal way (creating/writing files etc).
  2. The tests are more hermetic.. for example it was basically impossible to write a test which run outside of a project context.
  3. The overall path lengths will be much shorter, which has been a consistent issue on windows. We can remove hacks like withShorterPathForNewBuildStore.

Fixes #9711

Please read Github PR Conventions and then fill in one of these two templates.


Template Β: This PR does not modify cabal behaviour (documentation, tests, refactoring, etc.)

Include the following checklist in your PR:

  • Patches conform to the coding conventions.
  • Is this a PR that fixes CI? If so, it will need to be backported to older cabal release branches (ask maintainers for directions).

@philderbeast
Copy link
Collaborator

I like to be able to run cabal-test-suite locally but not all tests work this way on master and on this branch;

$ cabal run cabal-testsuite:cabal-tests -- --with-cabal=./dist-newstyle/build/x86_64-linux/ghc-9.8.1/cabal-install-3.11.0.0/x/cabal/build/cabal/cabal cabal-testsuite/PackageTests/CopyHie/setup.test.hs
...
- setup.test.hs: /home/<USERNAME>/.../cabal/cabal-testsuite/PackageTests/CopyHie/setup.dist/usr/lib/x86_64-linux-ghc-9.8.1/hie-local-0.1.0.0/extra-compilation-artifacts/hie/HieLocal.hie should exist
+ setup.test.hs: /tmp/cabal-testsuite-156428/setup.dist/usr/lib/x86_64-linux-ghc-9.8.1/hie-local-0.1.0.0/extra-compilation-artifacts/hie/HieLocal.hie should exist

Putting the tests into a temporary directory is definitely an improvement, if only because it puts the tests into a clean room away from whatever junk may be lying around in my working directory.

@alt-romes alt-romes force-pushed the wip/system-testsuite branch 2 times, most recently from 891a8c6 to 8214596 Compare February 19, 2024 15:07
Comment on lines 400 to 411
-- This requires the test repository to be a Git checkout, because
-- we use the Git metadata to figure out what files to copy into the
-- hermetic copy.
--
-- Also see 'withSourceCopyDir'.
withSourceCopy :: TestM a -> TestM a
withSourceCopy m = do
env <- getTestEnv
initWorkDir
let curdir = testSourceDir env
dest = testSourceCopyDir env
r <- getSourceFiles
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably add a warning or error here if there are no tracked source files. Otherwise, it may be confusing to a user who forgot to track files that their tests do not get run as expected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea, I have added the check.

Copy link
Collaborator

@alt-romes alt-romes left a comment

Choose a reason for hiding this comment

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

@mpickering this looks good to me, but it seems we should add an additional error or warning if there are no tracked files for a test (see above comment).

Thanks!

@mpickering mpickering force-pushed the wip/system-testsuite branch 2 times, most recently from f410cdb to 016d60a Compare February 20, 2024 16:26
@mpickering
Copy link
Collaborator Author

Does another Cabal developer wish to approve this before I merge it? It does slightly change the test workflow when adding new tests.

cc @philderbeast @ulysses4ever

Copy link
Collaborator

@ulysses4ever ulysses4ever left a comment

Choose a reason for hiding this comment

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

Terrific improvement! Minor comments above.

@mpickering mpickering force-pushed the wip/system-testsuite branch 2 times, most recently from 552f817 to a6b878d Compare February 25, 2024 19:39
@mpickering mpickering added the merge me Tell Mergify Bot to merge label Feb 26, 2024
@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Feb 28, 2024
1. Working directory is not contaminated with results of the testsuite.
   Tests can be written in a more liberal way (creating/writing files
   etc).
2. The tests are more hermetic.. for example it was basically impossible
   to write a test which run outside of a project context.
3. The overall path lengths will be much shorter, which has been a
   consistent issue on windows. We can remove hacks like
   `withShorterPathForNewBuildStore`.

Fixes haskell#9711
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge me Tell Mergify Bot to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

withSourceCopy is not very hermetic
5 participants