Skip to content

Commit 7f6b20a

Browse files
committed
Support #[itest(skip)]
1 parent fb656e3 commit 7f6b20a

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

godot-macros/src/itest.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
66

7-
use crate::util::bail;
7+
use crate::util::{bail, KvParser};
8+
use crate::ParseResult;
89
use proc_macro2::TokenStream;
910
use quote::quote;
10-
use venial::{Declaration, Error};
11+
use venial::Declaration;
1112

12-
pub fn transform(input_decl: Declaration) -> Result<TokenStream, Error> {
13+
pub fn transform(input_decl: Declaration) -> ParseResult<TokenStream> {
1314
let func = match input_decl {
1415
Declaration::Function(f) => f,
1516
_ => return bail("#[itest] can only be applied to functions", &input_decl),
@@ -27,10 +28,21 @@ pub fn transform(input_decl: Declaration) -> Result<TokenStream, Error> {
2728
);
2829
}
2930

31+
let mut attr = KvParser::parse_required(&func.attributes, "itest", &func.name)?;
32+
let skipped = attr.handle_alone("skip")?;
33+
let focused = attr.handle_alone("focus")?;
34+
attr.finish()?;
35+
36+
if skipped && focused {
37+
return bail(
38+
"#[itest]: keys `skip` and `focus` are mutually exclusive",
39+
func.name,
40+
);
41+
}
42+
3043
let test_name = &func.name;
3144
let test_name_str = func.name.to_string();
3245
let body = &func.body;
33-
let skipped = false;
3446

3547
Ok(quote! {
3648
pub fn #test_name() {

godot-macros/src/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ impl KvParser {
170170
// Useless allocation, but there seems to be no join() on map iterators. Anyway, this is slow/error path.
171171
let keys = self.map.keys().cloned().collect::<Vec<_>>().join(", ");
172172

173+
let s = if self.map.len() > 1 { "s" } else { "" }; // plural
173174
return bail(
174175
format!(
175-
"#[{attr}]: unrecognized keys: {keys}",
176+
"#[{attr}]: unrecognized key{s}: {keys}",
176177
attr = self.attr_name
177178
),
178179
self.span,

itest/rust/src/runner.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ impl IntegrationTests {
9494
let gdscript_time = gdscript_time.as_secs_f32();
9595
let total_time = rust_time + gdscript_time;
9696

97-
println!("\nTest result: {outcome}. {passed} passed; {failed} failed.");
97+
let extra = if skipped > 0 {
98+
format!(", {skipped} skipped")
99+
} else {
100+
"".to_string()
101+
};
102+
103+
println!("\nTest result: {outcome}. {passed} passed; {failed} failed{extra}.");
98104
println!(" Time: {total_time:.2}s. (Rust {rust_time:.2}s, GDScript {gdscript_time:.2}s)");
99105
all_passed
100106
}
@@ -191,7 +197,7 @@ impl std::fmt::Display for TestOutcome {
191197
let (col, outcome) = match self {
192198
TestOutcome::Passed => (FMT_GREEN, "ok"),
193199
TestOutcome::Failed => (FMT_RED, "FAILED"),
194-
TestOutcome::Skipped => (FMT_YELLOW, "ignored"),
200+
TestOutcome::Skipped => (FMT_YELLOW, "skipped"),
195201
};
196202

197203
write!(f, "{col}{outcome}{end}")

0 commit comments

Comments
 (0)