Skip to content

Commit ca04b4f

Browse files
committed
Add tests
1 parent a9f2ea2 commit ca04b4f

38 files changed

+619
-667
lines changed

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ matrix:
8484
- cargo run --manifest-path ci/remove-dev-dependencies/Cargo.toml */Cargo.toml
8585
- cargo build --manifest-path futures/Cargo.toml --features io-compat
8686

87+
- name: cargo test (async-stream feature)
88+
rust: nightly
89+
script:
90+
- cargo test --manifest-path futures/Cargo.toml --features async-stream,nightly --test async_stream_tests
91+
- cargo clean --manifest-path futures/testcrate/Cargo.toml
92+
- cargo test --manifest-path futures/testcrate/Cargo.toml
93+
8794
- name: cargo build --target=thumbv6m-none-eabi
8895
rust: nightly
8996
install:

futures/testcrate/Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
name = "testcrate"
33
version = "0.1.0"
44
authors = ["Alex Crichton <[email protected]>"]
5+
edition = "2018"
6+
publish = false
57

68
[lib]
79
path = "lib.rs"
810

9-
[dependencies.futures]
10-
features = ["std", "nightly"]
11-
path = ".."
11+
[dependencies]
12+
futures-preview = { path = "..", features = ["async-stream", "nightly"] }
1213

1314
[dev-dependencies]
14-
compiletest_rs = "0.3.7"
15+
compiletest = { version = "0.3.21", package = "compiletest_rs", features = ["stable"] }
1516

1617
[[test]]
1718
name = "ui"

futures/testcrate/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

futures/testcrate/tests/ui.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ fn run_mode(mode: &'static str) {
22
use std::env;
33
use std::path::PathBuf;
44

5-
let mut config = compiletest_rs::Config::default();
5+
let mut config = compiletest::Config::default();
66
config.mode = mode.parse().expect("invalid mode");
77
let mut me = env::current_exe().unwrap();
88
me.pop();
9-
config.target_rustcflags = Some(format!("-L {}", me.display()));
9+
config.target_rustcflags = Some(format!(
10+
"--edition=2018 \
11+
-Z unstable-options \
12+
--extern futures \
13+
-L {}",
14+
me.display()
15+
));
1016
let src = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
1117
config.src_base = src.join(mode);
1218

1319
me.pop();
1420
me.pop();
1521
config.build_base = me.join("tests").join(mode);
16-
compiletest_rs::run_tests(&config);
22+
compiletest::run_tests(&config);
1723
}
1824

1925
fn main() {

futures/testcrate/ui/bad-input-1.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(async_await, futures_api, generators)]
2+
3+
use futures::*;
4+
5+
#[async_stream]
6+
fn foo() -> i32 {
7+
#[for_await]
8+
for i in stream::iter(vec![1, 2]) {
9+
stream_yield!(bar!!());
10+
}
11+
}
12+
13+
fn main() {}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected open delimiter
2+
--> $DIR/bad-input-1.rs:9:27
3+
|
4+
9 | stream_yield!(bar!!());
5+
| ^ expected open delimiter
6+
7+
error: aborting due to previous error
8+

futures/testcrate/ui/bad-input-2.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
#![feature(async_await, futures_api, generators)]
3+
4+
use futures::*;
5+
6+
#[async_stream]
7+
fn foo() -> i32 {
8+
#[for_await(bar)]
9+
for i in stream::iter(vec![1, 2]) {
10+
stream_yield!(i);
11+
}
12+
}
13+
14+
#[async_stream(baz)]
15+
fn bar() -> i32 {
16+
#[for_await]
17+
for i in stream::iter(vec![1, 2]) {
18+
stream_yield!(i);
19+
}
20+
}
21+
22+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: attribute must be of the form `#[for_await]`
2+
--> $DIR/bad-input-2.rs:8:5
3+
|
4+
8 | #[for_await(bar)]
5+
| ^^^^^^^^^^^^^^^^^
6+
7+
error: attribute must be of the form `#[async_stream]`
8+
--> $DIR/bad-input-2.rs:14:1
9+
|
10+
14 | #[async_stream(baz)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
+9-18
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
1-
#![feature(proc_macro, generators)]
1+
#![feature(async_await, futures_api, generators)]
22

3-
#[async]
4-
fn foobar() -> Result<Option<i32>, ()> {
5-
let val = Some(42);
6-
if val.is_none() {
7-
return Ok(None)
8-
}
9-
let val = val.unwrap();
10-
Ok(val)
11-
}
3+
use futures::*;
124

13-
#[async_stream(item = Option<i32>)]
14-
fn foobars() -> Result<(), ()> {
5+
#[async_stream]
6+
fn foobar() -> Option<i32> {
157
let val = Some(42);
168
if val.is_none() {
179
stream_yield!(None);
18-
return Ok(())
10+
return;
1911
}
2012
let val = val.unwrap();
2113
stream_yield!(val);
22-
Ok(())
2314
}
2415

25-
#[async]
26-
fn tuple() -> Result<(i32, i32), ()> {
16+
#[async_stream]
17+
fn tuple() -> (i32, i32) {
2718
if false {
28-
return Ok(3);
19+
stream_yield!(3);
2920
}
30-
Ok((1, 2))
21+
stream_yield!((1, 2))
3122
}
3223

3324
fn main() {}

0 commit comments

Comments
 (0)