Skip to content

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

Merged
bors[bot] merged 5 commits intomainfrom
cfg-test
Oct 19, 2021
Merged

defmt-test: #[cfg(test)] the #[defmt_test::tests] module#604
bors[bot] merged 5 commits intomainfrom
cfg-test

Conversation

@japaric
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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