Comments (18)
no_std
+ alloc
support is available in 0.7.0 via #48
from proptest.
Possibly a dumb question (as I have no no_std
experience), but is it not possible to set a project up so that the main build is no_std
but tests have the stdlib?
I'm not sure about the possibility of supporting running without heap allocation. There's certainly a subset of the API that could work there, but I'm not sure how useful it'd be.
As for core
+ alloc
, off hand it does seem fairly viable. There's three main things I can think of that would be excluded:
- Obviously anything in
arbitrary/_std
that doesn't have acore
/alloc
component. - Failure case persistence.
- Handling panics.
The last one seems like a possibly big deal, since it means that proptest can't really do its job on a test that can fail in any way other than returning a failure code normally. But I guess it could still be useful.
In any case, thanks for being willing to assist with this!
from proptest.
Thank you for the encouragement, @AltSysrq .
Yep, it is often possible to arrange a project such that the tests are run with access to the standard library (e.g. whilst running on a local linux/windows/osx dev machine), even though the main project is geared for an embedded use case.
However, this is not always the case -- sometimes the capabilities that need to be exercised are only truly available when being run in a context without access to the standard library at all. For example, when running on an esoteric device with custom (sometimes black-box) features and no prayer of a full stdlib in sight.
That sort of "in-vivo" testing is what I'm hoping to cover with this effort.
I think persistence can be handled conventionally enough by being made optional -- perhaps factoring it into a trait with a few implementations (noop, filesystem, manual piping, etc), the present filesystem-based variant of which could be made std-only.
As for panics, you're right that we'd be pushed into a returned-failure-signifying style. There is an alternative available, which utest uses, that overrides panic!
in order to flip some global static bits that the test runner probes. However, I'm not keen on spooky action at a distance or fragile single-package-level macro overloads. I'd rather give the return-value based approach a shot first, since it seems more Rustic how.
from proptest.
Related issue rust-embedded/wg#47
from proptest.
@ZackPierce can you add an example or more documentation on setting up proptest in a #![no_std] environment. I don't want to disrail this bug for support but addingproptest = {version="0.7", features = ["alloc", "nightly"]}
to my Cargo.toml doesn't work because the dependencies are still wanting to use std.
-Jon
from proptest.
@jparris A couple pointers to get you started:
-
You additionally need
default-features=false
to opt out of thestd
default feature. -
Only version 0.8.4 (the latest as of writing) is compatible with the latest nightly rust build.
I think there may be a bit more fiddling necessary for actually writing the tests, and unfortunately I don't have any examples handy.
from proptest.
Definitely an example is needed for how to no_std the crate.
I also attempted to use it:
proptest = { version = "0.8", defatult-features = false, features = [] }
but then it pulled in many std using things. There should just be an example of every dependency you have to list out with default-features off
from proptest.
[dev-dependencies.proptest]
version = "0.8"
default-features = false
features = ["alloc", "unstable"]
This works for me, assuming I'm testing it correctly. I will add documenting this to my to do list for the next release.
from proptest.
When using that configuration, I get a problem with the transitive lazy_static dependency:
Compiling num-traits v0.2.6
Compiling rand_core v0.3.0
Compiling lazy_static v1.2.0
Compiling gba-proc-macro v0.5.0
error[E0463]: can't find crate for `std`
--> C:\Users\Daniel\.cargo\registry\src\github.com-1ecc6299db9ec823\lazy_static-1.2.0\src\inline_lazy.rs:9:1
|
9 | extern crate std;
| ^^^^^^^^^^^^^^^^^ can't find crate
|
= note: the `thumbv4-none-agb-15848137922264977313` target may not be installed
error: aborting due to previous error
from proptest.
Oh, we have a separate nightly
feature you also need for lazy_static
to work until #112 is released.
Do you know of a way to ensure nothing brings std
in short of compiling for a target that doesn't have std
? Clearly the way I was testing that (a #![no_std]
bin crate) doesn't work.
from proptest.
I don't.
In my particularly strange use case, I don't need proptest to run on the device, I just need it for tests that run on the local machine. However, [dev-dependences] is for both tests and examples, so if I want my examples to target the device I can't have proptest as a dev-dependency :/
from proptest.
@AltSysrq to test that no_std
works you can use the fact that Cortex-M targets ship only with core
and use cargo check --target thumbv7em-none-eabihf
since checking only requires getting the target with rustup
, and not an actual ARM machine
from proptest.
@AltSysrq It fails to compile in my case as well. This is my configuration:
[dev-dependencies.proptest]
version = "0.8"
default-features = false
features = ["alloc", "unstable"]
and the error:
error[E0277]: the trait bound `str: proptest::strategy::Strategy` is not satisfied
--> tests/bytesrepr_test.rs:3:1
|
3 | / proptest! {
4 | | #[test]
5 | | fn test_addition(a in 0..10, b in 0..10) {
6 | | prop_assert!(a + b <= 18);
... |
13 | | }
14 | | }
| |_^ the trait `proptest::strategy::Strategy` is not implemented for `str`
|
= note: required because of the requirements on the impl of `proptest::strategy::Strategy` for `&str`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
from proptest.
@goral09 as mentioned previously you also need the nightly
feature for now, so it should be:
[dev-dependencies.proptest]
version = "0.8"
default-features = false
features = ["alloc", "unstable", "nightly"]
from proptest.
Thanks @nivkner but this doesn't solve my problem. Still getting the same errors.
from proptest.
@nivkner Thanks for that cargo test
suggestion. I believe 0.9.0 should work for you.
from proptest.
@goral09 I'm not entirely sure what's going on in your case. The error message itself suggests you're trying to use a regex-based String
strategy, which is only supported on std
. Is there such a usage between lines 6 and 13?
from proptest.
Also, there's now documentation on using no_std
with proptest.
from proptest.
Related Issues (20)
- First-class support for async functions
- The type 'EasyCashIdentity.EntityLayer.Concrete.AppUser' cannot be used as type parameter
- rust-analyzer doesn't like the derive(Arbitrary) generated code for enums HOT 1
- Zero Examples of `impl Arbitrary` ? HOT 3
- Finite state machines HOT 1
- proptest_derive triggers non-local impl nightly warning HOT 1
- Update "shrinks to" comment on the same seed failures HOT 1
- Panic on empty ranges during strategy creation HOT 3
- Don't require `Arbitrary::Parameters` to implement `Default` HOT 4
- Recursive `arbitrary` calls HOT 3
- Change verbosity of shrink disabled and persisted failure messages HOT 3
- Provide access to state for (debug) printing transitions HOT 5
- feat: add option to interrupt test runner HOT 2
- derive macro for Arbitrary is hard to find HOT 4
- Attribute macro #[property_test] available in docs, but undocumented and behind undocumented feature HOT 1
- Lift MSRV to 1.70 to relax dependency on trybuild
- RangeInclusive of floats containing one element panics
- Improve logging for state machine testing
- The ` state_machine_echo_server` example does not compile HOT 2
- Proptest logging
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proptest.