Skip to content

Commit a1afa5e

Browse files
authored
Merge pull request #254 from oli-obk/examples
Usage instructions and basic usage example
2 parents e935347 + 2dd47df commit a1afa5e

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* examples and usage instructions
13+
1214
### Fixed
1315

1416
### Changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1-
A stable version of compiletest-rs
1+
A test runner that builds tests with rustc or cargo (or any other compiler
2+
with some configuration effort) and compares the output of the compiler with
3+
a file that you check into git. This allows you to test how your libraries
4+
show up to your users when the library is used wrongly and emits errors.
25

3-
## Magic behavior
6+
## Usage
7+
8+
See [examples directory](examples) for how to use this in your own crate.
9+
To be able to use it with `cargo test`, you need to put
10+
11+
```toml
12+
[[test]]
13+
name = "your_test_file"
14+
harness = false
15+
```
16+
17+
into your `Cargo.toml`, otherwise `cargo test` will only look for `#[test]`s and
18+
not run your `fn main()` that actually executes `ui_test`
19+
20+
## Implicit (and possibly surprising) behavior
421

522
* Tests are run in order of their filenames (files first, then recursing into folders).
623
So if you have any slow tests, prepend them with a small integral number to make them get run first, taking advantage of parallelism as much as possible (instead of waiting for the slow tests at the end).
724
* `cargo test --test your_test_name -- --help` lists the commands you can specify for filtering, blessing and making your tests less verbose.
825
* Since `cargo test` on its own runs all tests, using `cargo test -- --check` will not work on its own, but `cargo test -- --quiet` and `cargo test -- some_test_name` will work just fine, as the CLI matches.
926
* if there is a `.stdin` file with the same filename as your test, it will be piped as standard input to your program.
1027

11-
## Supported magic comment annotations
28+
## Supported comment annotations
1229

1330
If your test tests for failure, you need to add a `//~` annotation where the error is happening
1431
to ensure that the test will always keep failing at the annotated line. These comments can take two forms:

examples/rustc_basic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use ui_test::{run_tests, Config};
2+
3+
fn main() -> ui_test::color_eyre::Result<()> {
4+
// Compile all `.rs` files in the given directory (relative to your
5+
// Cargo.toml) and compare their output against the corresponding
6+
// `.stderr` files.
7+
run_tests(Config::rustc("examples_tests/rustc_basic"))
8+
}

examples_tests/rustc_basic/hello.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
println("hello world")
3+
//~^ ERROR: expected function, found macro `println`
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0423]: expected function, found macro `println`
2+
--> examples_tests/rustc_basic/hello.rs:2:5
3+
|
4+
2 | println("hello world")
5+
| ^^^^^^^ not a function
6+
|
7+
help: use `!` to invoke the macro
8+
|
9+
2 | println!("hello world")
10+
| +
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0423`.

0 commit comments

Comments
 (0)