Open thoughtpolice opened 2 weeks ago
Oh, apparently I need both CARGO_MANIFEST_DIR
and INSTA_WORKSPACE_RULE
for my tests to work. So my Buck2 rule for building insta tests looks like this (roughly):
rust_test(
name = 'qq-cli-tests',
srcs = glob(['**/*.rs']),
deps = COMMON_DEPS,
env = {
'CARGO_MANIFEST_DIR': '.',
'INSTA_WORKSPACE_ROOT': '.',
}
)
Thanks for the issue.
If we checked INSTA_WORKSPACE_ROOT
before CARGO_MANIFEST_DIR
, would that solve everything here? I haven't worked with rust without cargo so I don't have much context on the standard approach for figuring things out such as the root of the workspace...
I am evaluating insta with a project that uses Buck2 (and also a very happy user using it with Cargo as part of Jujutsu). When using a project with Buck2, Cargo is not used, and so tests for example are run "manually" by the build system itself after compilation with
--cfg=test
Currently, I'm using inline snapshots, with a test like this:
By default, when I compile this with
buck2 build
, I get an error like so:Buck2 executes all tests from the root of the project, so luckily I can set
CARGO_MANIFEST_DIR=.
during the compilation of these tests which solves the problem. But it's a bit ugly I think.While using Code Search to browse the source code to figure out how the macro worked, it looks like
INSTA_WORKSPACE_ROOT
also has a similar function. It would at least be more explanatory when I writeINSTA_WORKSPACE_ROOT=.
in the source code why it exists. However, it seems like it only works when you usecargo insta
.Alternatively, some other more general form or utility for
assert_snapshot!()
to work in the presence of non-Cargo systems would be nice.