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

defmt-test: #[cfg(test)] the #[defmt_test::tests] module #604

Merged
merged 5 commits into from
Oct 19, 2021
Merged

Conversation

japaric
Copy link
Member

@japaric japaric commented Oct 6, 2021

it recently came to my attention that one can use defmt-test for "unit testing" by using it in src/lib.rs (although this is pretty limited at the moment because one can only use the defmt_test::tests once in a library crate)

if one does use defmt_test like that then they may run into the issue that running the test files in tests fails with this cryptic linker message:

  = note: rust-lld: error: duplicate symbol: main

the issue is that the code generated by defmt_test::tests (which includes a function with unmangled name main) is not conditionally compiled but we do want that to be #[cfg(test)]-ed because it contains test code.

r? @jonas-schievink

@japaric
Copy link
Member Author

japaric commented Oct 6, 2021

argh, our defmt-test snapshot test is unusual because is a bin/*.rs file and not a proper test/*.rs file which does get compiled with --cfg test when you do cargo test. this will require xtask changes to land. turning into a draft PR for now

@japaric japaric marked this pull request as draft October 6, 2021 12:52
@japaric japaric requested review from jonas-schievink and removed request for jonas-schievink October 15, 2021 13:29
@japaric japaric marked this pull request as ready for review October 15, 2021 13:29
Copy link
Member

@Urhengulas Urhengulas left a comment

Choose a reason for hiding this comment

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

Looks good to me. firmware/qemu/tests/defmt-test.out.new and firmware/qemu/tests/defmt-test.release.out.new probably should be removed?

@japaric
Copy link
Member Author

japaric commented Oct 19, 2021

Looks good to me. firmware/qemu/tests/defmt-test.out.new and firmware/qemu/tests/defmt-test.release.out.new probably should be removed?

good catch! done and added a gitignore to prevent that in the future

bors r=Urhengulas

@bors
Copy link
Contributor

bors bot commented Oct 19, 2021

Build succeeded:

@bors bors bot merged commit 0efd040 into main Oct 19, 2021
@bors bors bot deleted the cfg-test branch October 19, 2021 15:03
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.

3 participants