-
-
Notifications
You must be signed in to change notification settings - Fork 358
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
Make TestModule#test
run in T.dest
folder by default
#3347
Conversation
TestModule#test
run in T.dest
folder by defaultTestModule#test
run in T.dest
folder by default
I could imaging a dedicated In contrast, to the other |
Again, I think we should not postpone any documentation. It hinders early adoption and testing, also proofreading and incremental fine-tuning. Instead we should make the latest stable release the default version we show in the documentation. For me, the ideal scenario is to only release features that are documented at release time. |
@lefou I've added some docs to this PR covering the different ways of loading resources in tests, both classpath based and file based approaches using environment variables, in Java and Scala I think for this PR let's just stick with the status-quo pass-path-as-environmental-variable approach that we've used in the past. There's definitely more we can do here, but that will take more thought and can come in a follow up |
The reason why I proposed a new In contrast, we could easily make a distinction here, make it easy to do the right thing, and avoid encouraging users to do the not-so-correct thing. |
Going to merge this for now, but let's continue test file discussion in #3362 and see what solution we can find |
This makes `os.pwd` an empty directory: `out/mill-worker-*/sandbox/` for Mill's server mode, `out/mill-no-server/sandbox/` otherwise In general, code outside of tasks should use `millSourcePath`, while code inside of tasks should use `T.dest` or the `PathRef`s given to it by upstream tasks. Accessing project files via `os.pwd` can result in tasks not invalidating when files changed. Like #3347, this does not prevent people intentionally walking the filesystem to work mischieve, but it does help mitigate "accidental" usage of `os.pwd` to access project files. The original `os.pwd` is still made available as `mill.api.WorkspaceRoot.workspaceRoot` outside of tasks, or `T.workspace` inside of tasks, for the occasional scenarios that need it. But at least this adds some partial guardrails against accidentally using `os.pwd` in a way that subverts Mill's expectations, and the APIs that expose the workspace root can be appropriately documented to warn people against doing the wrong thing
Also got rid of `MILL_TEST_DEST_FOLDER` since #3347 makes `os.pwd` sufficient. There are also a few other `MILL_*` things that look like env vars but are actually system properties, so I left them out of this PR
Since #3347 made all test suites run with `pwd` in the test's `.dest` folder by default, we are already guaranteed that different concurrent test suites will not collide, so we do not need the `out/blah/blah` segments to avoid conflicts
This PR makes it such that
TestModule#test
runs subprocesses insideT.dest / "sandbox"
by default, rather thanT.workspace
.This change can be disabled with a flag
def testSandboxWorkingDir = false
, but is a good default to encourage:Before, because tests run with the
pwd
in the repository root, there are no guardrails preventing you from doing the "easy" thing and just reading stuff off of disk rather than having explicit build dependencies.resources/
and read from it, which did the right thing "accidentally" since tests depend on the resource folder, it was easy for people to put stuff in othernot-resources/
folders and have the dependency between the test files and the test task missing.--watch
do not properly pick up changes, andtestCached
does not properly get invalidated.testCached
in https://github.com/com-lihaoyi/mill/pull/3265/files, and we probably want to encourage moretestCached
going forward)With this change, tests run in empty
T.dest / "sandbox"
folders. This means that it is very hard to "accidentally" do the wrong thing:forkEnv
orforkArgs
, which is a pattern we already do in Mill's own build (e.g. here and here).--watch
works andtestCached
properly invalidatesMILL_TEST_RESOURCE_FOLDER
environment variable that contains the resource folders as a semicolon-separated string. In the common case, this is a single path, and can be used in your test code to refer to the resource folder as an alternative to the old practice reading directly fromos.pwd / "src" / "test" / "resources"
or whateverThere is some design leeway here; we could follow bazel, and create symlinks for all referenced
PathRef
s inside the test sandbox folder. Or we could do nothing, and let people pass in the stuff they need manually viaforkEnv
orforkArgs
. I think the proposed approach of providingMILL_TEST_RESOURCE_FOLDER
by default, and letting people provide other things on their own, is a reasonable compromise between these approaches. A full design and implementation of a bazel-style "Runfiles" system is probably more complexity than I am willing bear at this moment. This change is nowhere near the sophistication of the bazel sandbox, but it is a startThis is a binary compatible but semantically breaking change, and should go into 0.12.0. It will also need extensive updates to the documentation, which I'll postpone till later since we don't want those changes to be visible to users until this change has been released