craftytrickster / mock_me Goto Github PK
View Code? Open in Web Editor NEWMockMe is a tool used to mock dependencies / function calls when running unit (lib) tests in Rust.
License: MIT License
MockMe is a tool used to mock dependencies / function calls when running unit (lib) tests in Rust.
License: MIT License
if the mock_me_context lookup was made to have multi values (perhaps the value can be the name of the test_fn, etc), instead of a single key -> value, perhaps we can avoid the issue of tests clobbering each other.
Repro step:
cargo test --test test
The problem is that test_with_silly_func_1
and test_with_silly_func_2
will both modify the same _mock_me_test_context_instance
. Now imagine the following sequence:
Thread 1 | Thread 2 |
---|---|
_mock_me_test_context_instance.set(replacement_1) |
|
_mock_me_test_context_instance.set(replacement_2) |
|
function_with_fun_id() |
|
_mock_me_test_context_instance.get() |
|
Finds out silly_func becomes replacement_2 |
|
Computes replacement_2(30, 20) |
|
assert_eq!(600, 10) |
|
๐ฅ |
Tested with mock_me = "0.2.2"
on crates.io.
$ rustc -vV
rustc 1.21.0-nightly (e26688824 2017-08-27)
binary: rustc
commit-hash: e2668882406b68739c6ed33d420358d5d710e67b
commit-date: 2017-08-27
host: x86_64-apple-darwin
release: 1.21.0-nightly
LLVM version: 4.0
Perhaps the syn crate has functionality to do so
Currently, we are forcing the programmer that is mocking the function to write the function signature. I would like this to be inferred automatically. I am not sure how this can be done, perhaps scanning the source code itself for the function could be a (somewhat crazy) viable approach.
Currently, I am using very primitive means to extract the values that I would like into the InjectMatch and MockMatch structs. This should be done in a less error prone and more structured way.
Perhaps a consumer may want to specify in which cfgs the mocked replacement is applied.
Currently, in lib.rs, in the mock
and inject
functions, we are inserting to code to enable this crate's functionality. I am purposely using long, uncommon names like _mock_me_test_context_instance
, however, in theory there could be a name collision if the user has an identically named variable. We should figure out a way to make such a collision impossible.
Add ability to lookup which args were passed to mocked function in order to confirm test went through, as well as the ability to see how many times it was called.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.