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

Introduce more solid no_std testing #199

Merged
merged 3 commits into from
Jan 17, 2024

Conversation

tadeohepperle
Copy link
Contributor

The no_std tests we had before, did not enforce that our dependencies are all no_std. E.g. any dependency could use the standard library and still our no_std tests would succeed.

We now circumvent this by defining a custom panic handler and a global allocator such that any dependencies that make use of the standard library will fail to compile, because in that case there would be more than one global allocator and panic handler. Inspiration was taken from serde's no_std testing (Thanks for the hint @niklasad1).

Testing in no_std is a bit difficult, but one approach I take here is just running a main function, that returns Aborted (core dumped) with a non-zero exit code if a panic is encountered (e.g. in an untrue assert). This can run in the CI to make sure the code runs and not only compiles in a no_std environment.

@@ -11,8 +11,13 @@ license = "Apache-2.0"

[dependencies]
scale-info = { path = "../..", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2", features = ["full"] }
Copy link
Member

Choose a reason for hiding this comment

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

does it work with scale = { package = "parity-scale-codec", version = "2", default-features = false }?

Or why was it removed?

Copy link
Contributor Author

@tadeohepperle tadeohepperle Jan 17, 2024

Choose a reason for hiding this comment

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

I just removed it from the dependencies because it was not used before and is not needed.
Edit: I now added scale and bitvec as dependencies and make use of them in the no-std test, to check that scale-info works with them.

@tadeohepperle tadeohepperle merged commit 46b1b8f into master Jan 17, 2024
2 checks passed
@tadeohepperle tadeohepperle deleted the tadeohepperle/better-no-std-tests branch January 17, 2024 12:38
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