Skip to content

Commit

Permalink
Readme tests ignore bash blocks ending with ignore (#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
christos-h authored May 28, 2024
1 parent de04d31 commit 40d0dad
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions linera-service/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,27 @@ impl QuotedBashAndGraphQlScript {

while let Some(line) = lines.next() {
let line = line?;
if line.starts_with("```bash") {
let mut quote = String::new();
while let Some(line) = lines.next() {
let line = line?;
if line.starts_with("```") {
break;
}
quote += &line;
quote += "\n";

if line.contains("linera service") {
quote += "sleep 3";
if line.starts_with("```bash") {
if line.ends_with("ignore") {
continue;
} else {
let mut quote = String::new();
while let Some(line) = lines.next() {
let line = line?;
if line.starts_with("```") {
break;
}
quote += &line;
quote += "\n";

if line.contains("linera service") {
quote += "sleep 3";
quote += "\n";
}
}
result.push(quote);
}
result.push(quote);
} else if let Some(uri) = line.strip_prefix("```gql,uri=") {
let mut quote = String::new();
while let Some(line) = lines.next() {
Expand Down Expand Up @@ -161,3 +166,25 @@ fn test_parse_version_message() {
let s = "";
assert_eq!(parse_version_message(s), "");
}

#[test]
fn test_ignore() {
let readme = r#"
first line
```bash
some bash
```
second line
```bash
some other bash
```
third line
```bash,ignore
this will be ignored
```
"#;
let cursor = std::io::Cursor::new(readme);
let parsed = QuotedBashAndGraphQlScript::read_bash_and_gql_quotes(cursor, None).unwrap();
let expected = vec!["some bash\n".to_string(), "some other bash\n".to_string()];
assert_eq!(parsed, expected)
}

0 comments on commit 40d0dad

Please sign in to comment.