Skip to content

Commit

Permalink
Merge pull request #5 from posborne/no-run-support
Browse files Browse the repository at this point in the history
Add support for no_run info string
  • Loading branch information
brson committed Jun 7, 2016
2 parents c142fa9 + c96cea8 commit a0ce658
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,32 @@ fn main() {
Skeptic will interpret other words in the code block's 'info string'
(which should be separated by comma, `,`, to be
GitHub-compatible). These words change how the test is interpreted:
`ignore`, and `should_panic`.
`ignore`, `no_run`, and `should_panic`.

`ignore` causes the test not to be run during testing, so it will neither pass nor fail.
### `ignore` Info String

The `ignore` info string causes the test to be completely ignored. It will not
be compiled or run during testing. This can be useful if an example is written
in Rust (and you want it highlighted as such) but it is known to be incomplete
(so it cannot compile as-is).

<code>```rust,ignore</code>
```rust,ignore
fn do_amazing_thing() -> i32 {
// TODO: How do I do this?
unimplemented! whatever I'm distracted, oh cookies!
```
<code>```</code>

### `no_run` Info String

The `no_run` info string causes the example code not to be run during testing.
Code marked with `no_run` will however still be compiled. This is useful for
examples/test that may have side effects or dependencies which are not desirable
in a testing situation.

<code>```rust,no_run</code>
```rust,no_run
fn do_amazing_thing() -> i32 {
// TODO: How do I do this?
unimplemented!()
Expand All @@ -102,16 +122,7 @@ fn main() {
```
<code>```</code>

Furthermore, like rustdoc, `ignore`d test cases will not even be
compiled, so may contain compilation errors:

<code>```rust,ignore</code>
```rust,ignore
fn do_amazing_thing() -> i32 {
// TODO: How do I do this?
unimplemented! whatever I'm distracted, oh cookies!
```
<code>```</code>
### `should_panic` Info String

`should_panic` causes the test to only pass if it terminates because
of a `panic!()`.
Expand Down
18 changes: 17 additions & 1 deletion src/skeptic/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct Test {
name: String,
text: Vec<String>,
ignore: bool,
no_run: bool,
should_panic: bool,
}

Expand Down Expand Up @@ -106,6 +107,7 @@ fn extract_tests_from_file(path: &Path) -> Result<DocTest, IoError> {
name: test_name_gen.advance(),
text: buf,
ignore: code_block_info.ignore,
no_run: code_block_info.no_run,
should_panic: code_block_info.should_panic,
});
}
Expand Down Expand Up @@ -182,6 +184,7 @@ fn parse_code_block_info(info: &str) -> CodeBlockInfo {
is_rust: false,
should_panic: false,
ignore: false,
no_run: false,
is_template: false,
};

Expand All @@ -200,6 +203,10 @@ fn parse_code_block_info(info: &str) -> CodeBlockInfo {
info.ignore = true;
seen_rust_tags = true
}
"no_run" => {
info.no_run = true;
seen_rust_tags = true;
}
"skeptic-template" => {
info.is_template = true;
seen_rust_tags = true
Expand All @@ -217,6 +224,7 @@ struct CodeBlockInfo {
is_rust: bool,
should_panic: bool,
ignore: bool,
no_run: bool,
is_template: bool,
}

Expand Down Expand Up @@ -251,7 +259,15 @@ fn create_test_string(config: &Config,
if test.should_panic {
try!(writeln!(s, "#[should_panic]"));
}
try!(writeln!(s, "#[test] fn {}() {{", test.name));

// if we are not running, just generate an unused function to get
// compile checking (but it won't be run without test attribute)
if test.no_run {
try!(writeln!(s, "#[allow(dead_code)] fn {}() {{", test.name));
} else {
try!(writeln!(s, "#[test] fn {}() {{", test.name));
}

try!(writeln!(s,
" let ref s = format!(\"{}\", r####\"{}\"####);",
template,
Expand Down

0 comments on commit a0ce658

Please sign in to comment.