Unwanted duplicate output of certain steps #272
-
I am really puzzled why this duplicate step output sometimes happens: I am also struggling to find a nice minimal reproducible example. After several hours of testing, trial and error, I managed to narrow it down to this: # wrong_output.feature
Feature: Show Wrong Output
Scenario Outline: Wrapped Serde Errors
When I parse the <json>
Then <json> parsed as <type> results in the error <error>
Examples:
| json | type | error |
| ['s','t'] | Vec<String> | JSON deserialization error: expected value at line 1 column 2 |
| [1,2,3] | Vec<String> | JSON deserialization error: invalid type: integer `1`, expected a string at line 1 column 2 |
Test implementation: use cucumber::{then, when, World as _};
use serde::Deserialize;
use serde_json;
use std::collections::HashMap;
use std::fmt;
#[derive(Debug, Deserialize)]
struct MyStruct(Vec<String>);
#[derive(Debug)]
enum MyError {
Serde(serde_json::error::Error),
}
impl fmt::Display for MyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
MyError::Serde(json_err) => {
write!(f, "JSON deserialization error: {json_err}")
}
}
}
}
impl std::error::Error for MyError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
MyError::Serde(ref serde_err) => Some(serde_err),
}
}
}
#[derive(Debug, cucumber::World)]
#[world(init = Self::new)]
pub struct World {
result: HashMap<String, Result<MyStruct, MyError>>,
}
impl World {
fn new() -> Self {
Self {
result: HashMap::new(),
}
}
}
#[when(regex = r"^I parse the (?P<json>\S+)$")]
fn parse_json(world: &mut World, json: String) {
world.result.insert(
json.clone(),
serde_json::from_str(&json).map_err(MyError::Serde),
);
}
#[then(
regex = r"^(?P<json>\S+) parsed as (?P<type_string>\S+) results in the error (?P<error_string>.+)$"
)]
fn check_error(world: &mut World, json: String, _type_string: String, error_string: String) {
assert_eq!(
world.result.remove(&json).unwrap().unwrap_err().to_string(),
error_string
);
}
#[tokio::main]
async fn main() {
World::cucumber()
.run("tests/features/wrong_output.feature")
.await;
} Can you see what makes the cucumber writer to output the "Then" line twice (once in NoColors mode)? I think it might have something to do with me wrapping the I'm using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Wow, I think it has something to do with the Terminal emulator (on Windows). The screenshot in the OP is from ConEmu64. The two below are from GitBash CMD (it does not happen every time): |
Beta Was this translation helpful? Give feedback.
-
It looks like the problem is line wrapping because terminal width is too small. So we clear only 1 line, when it should be 2 or even more in case of a really long scenario name. I've addressed it in #273 |
Beta Was this translation helpful? Give feedback.
It looks like the problem is line wrapping because terminal width is too small. So we clear only 1 line, when it should be 2 or even more in case of a really long scenario name. I've addressed it in #273