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

Feature suggestion: testability #34

Open
Amomum opened this issue May 19, 2020 · 4 comments
Open

Feature suggestion: testability #34

Amomum opened this issue May 19, 2020 · 4 comments

Comments

@Amomum
Copy link

Amomum commented May 19, 2020

Since all of the assertions right now will cause compilation failure, it's hard to write unit tests that check them.

For instance, if I'm writing a library and I want check that my preconditions are asserted correctly.

On the top of my head I would suggest some kind of option (may be detecting #[cfg(test)]?) that changes all compile-time assertions to run-time assertions; than it would be possible to catch panics and test them at runtime.

@jhpratt
Copy link

jhpratt commented Sep 10, 2020

Isn't this just assert!()?

@Amomum
Copy link
Author

Amomum commented Sep 10, 2020

@jhpratt

Isn't this just assert!()?

No, that's not what I mean. Normal asserts are for runtime checks, but const_asserts are for compile-time checks. If I use const_assert, how can I check if it's correctly written?

Well, I can try to compile it with incorrect code and see that it doesn't compile - that is okay for simple cases that can be tested by hand. But what if my const condition is complex? And what if I want to test it in CI? How shall I do that? Detecting compilation failure is not very pretty imho.

@nvzqz
Copy link
Owner

nvzqz commented Sep 10, 2020

Sorry for my silence on this issue.

I'd rather limit the complexity of this crate and not add the option to turn compile errors into runtime errors. If you want to create a PR with code that does this, then I'll review it and could be convinced.

There's not a lot of great ways to test compile errors outside of doing ```compile_fail doc tests, like what this crate does. I thought I saw a crate that wraps this, but I can't seem to find it.

Regarding prettiness of errors, once panic! or assert! becomes usable in const, I can greatly improve some of the error reporting of these assertions.

@Amomum
Copy link
Author

Amomum commented Sep 10, 2020

@nvzqz fair enough. Unfortunately I almost certainly won't be able to make such a PR any time soon, my rust skills are almost nil (and I was speaking from C++ land).

So feel free to put this issue on hold or closing it.

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

No branches or pull requests

3 participants