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

tests: don't have cargo install test tools #216

Closed
wants to merge 2 commits into from
Closed

Conversation

martinvonz
Copy link
Owner

@martinvonz martinvonz commented Apr 20, 2022

I noticed that cargo install --path . will install the new
fake-editor and fake-diff-editor binaries. We don't want that, so
let's move them into a separate crate. The tests still find them
without needing any modification.

Checklist

  • I have made relevant updates to CHANGELOG.md

Copy link
Collaborator

@arxanas arxanas left a comment

Choose a reason for hiding this comment

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

FWIW git-branchless puts helper binaries behind a feature flag which isn't enabled by default:

https://github.com/arxanas/git-branchless/blob/3595f3d151dffb974f7f6fddb500c79ee25a0431/git-branchless-lib/Cargo.toml#L25-L36

Not that it makes a difference either way.

@martinvonz
Copy link
Owner Author

FWIW git-branchless puts helper binaries behind a feature flag which isn't enabled by default:

https://github.com/arxanas/git-branchless/blob/3595f3d151dffb974f7f6fddb500c79ee25a0431/git-branchless-lib/Cargo.toml#L25-L36

What enables the integration-test-bin feature?

@arxanas
Copy link
Collaborator

arxanas commented Apr 20, 2022

@martinvonz Me manually passing --feature integration-test-bin 😊

I guess what we're doing is different. Your binaries are supporting the relevant tests, but my binaries are the tests.

@martinvonz
Copy link
Owner Author

@martinvonz Me manually passing --feature integration-test-bin 😊

I see. I'd really like to avoid having to do that, especially since every developer would need to remember to do the same. Maybe there's just no good solution until rust-lang/cargo#3670 has been fixed. I guess the problem is effectively the same as with using e.g. the git binary in tests. The difference is just that the binary can be built by cargo.

Copy link
Collaborator

@arxanas arxanas left a comment

Choose a reason for hiding this comment

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

Due to a recent build of jj, I'm now a proud owner of the fake-editor and fake-diff-editor binaries on my machine 😊

@martinvonz
Copy link
Owner Author

Due to a recent build of jj, I'm now a proud owner of the fake-editor and fake-diff-editor binaries on my machine 😊

Sorry :( I don't know what the right solution to this problem is. I suppose we will also need a git binary on the path for tests in not too long (for running a git server to testing push/pull with, and to test GC, neither of which libgit2 supports AFAIK). For git, we can look for it on the path and have a $TEST_GIT override like I think git-branchless has. That doesn't work as well for these fake-* binaries, though.

I noticed that `cargo install --path .` will install the new
`fake-editor` and `fake-diff-editor` binaries, which we don't want. It
doesn't seem to work to put them in a separate crate and have a
dev-dependency on it because `cargo` doesn't like dev-dependencies to
binary targets. However, it seems that we can put them in `examples/`
to be able to access them without having `cargo install` install them.
@@ -140,7 +140,7 @@ impl TestEnvironment {

/// Sets up the fake editor to read an edit script from the returned path
pub fn set_up_fake_editor(&mut self) -> PathBuf {
let editor_path = assert_cmd::cargo::cargo_bin("fake-editor");
let editor_path = assert_cmd::cargo::cargo_bin("examples/fake-editor");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting, this really works? How does Cargo know that it needs to build the example before running the test?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yep, it seems that it does (the checks pass). I think you can have regular tests in the files in examples/, so maybe cargo test builds them for that reason. But that's just my guess.

There's an unstable feature that lets us depend on crates with just binary targets (no library). So once that's in stable, we can switch to that setup. Hopefully this solution doesn't break before then :)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Oh, it actually doesn't work :( It works with cargo nextest run, however, which is why I didn't notice that it was broken with regular cargo test. I don't know why the GitHub actions pass.

@ilyagr
Copy link
Collaborator

ilyagr commented Sep 11, 2023

I ran into this when I tried to make jj installable with cargo binstall1.

The approach suggested in rust-lang/cargo#2911 (comment) seems somewhat promising, unless you've tried it already or it seems too hacky.

Footnotes

  1. For my own future reference, the magic incantantion for binstall seems to be --pkg-url="{ repo }/releases/download/v{ version }/jj-v{ version }-{ target }.{ archive-format }". Using jj instead of jj-cli is necessary. It's a bit surprising that I needed to add v before versions.

ilyagr added a commit to ilyagr/jj that referenced this pull request Sep 20, 2023
Among other things, this prevented `jj` from working with
`cargo binstall`.

The trick is taken from
rust-lang/cargo#2911 (comment).

We could now also remove `--bin jj` from the installation commands
in `install-and-setup.md`, but I'm not sure we should. That argument
makes it clear that the binary is `jj`, not `jj-cli`.

Fixes martinvonz#216.
@ilyagr ilyagr closed this in #2277 Sep 20, 2023
ilyagr added a commit that referenced this pull request Sep 20, 2023
Among other things, this prevented `jj` from working with
`cargo binstall`.

The trick is taken from
rust-lang/cargo#2911 (comment).

We could now also remove `--bin jj` from the installation commands
in `install-and-setup.md`, but I'm not sure we should. That argument
makes it clear that the binary is `jj`, not `jj-cli`.

Fixes #216.
Dr-Emann pushed a commit to Dr-Emann/jj that referenced this pull request Sep 21, 2023
Among other things, this prevented `jj` from working with
`cargo binstall`.

The trick is taken from
rust-lang/cargo#2911 (comment).

We could now also remove `--bin jj` from the installation commands
in `install-and-setup.md`, but I'm not sure we should. That argument
makes it clear that the binary is `jj`, not `jj-cli`.

Fixes martinvonz#216.
@martinvonz martinvonz deleted the testing branch August 3, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants