-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from CosmWasm/chipshort/docs-tests-template
Docs Test Changes
- Loading branch information
Showing
4 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use cosmwasm_std::*; | ||
use cosmwasm_schema::cw_serde; | ||
|
||
#[cw_serde] | ||
struct ExecuteMsg {} | ||
|
||
#[entry_point] | ||
pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> StdResult<Response> { | ||
// this weird construction allows us to return a StdResult<Response> or () in the code | ||
// it tricks the compiler into infering the correct generics | ||
trait ValidReturn {} | ||
impl ValidReturn for StdResult<Response<Empty>> {} | ||
impl ValidReturn for () {} | ||
fn assert_valid_return(_: &impl ValidReturn) {} | ||
|
||
let ret = { {{code}} }; | ||
assert_valid_return(&ret); | ||
|
||
Ok(Response::default()) | ||
} | ||
|
||
#[test] | ||
fn doctest() { | ||
use cosmwasm_std::testing::*; | ||
let mut deps = mock_dependencies(); | ||
let env = mock_env(); | ||
let info = mock_info("sender", &[]); | ||
let msg = ExecuteMsg {}; | ||
|
||
let res = execute(deps.as_mut(), env, info, msg).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
set -o errexit -o nounset -o pipefail | ||
|
||
( | ||
cd docs-test-gen && \ | ||
rm -rf ./tests && \ | ||
cargo run && | ||
cargo test | ||
) |