From 40d0dad6e48ccd28a52f14592ac50bb3e62ab581 Mon Sep 17 00:00:00 2001 From: Christos Hadjiaslanis Date: Tue, 28 May 2024 16:47:09 +0100 Subject: [PATCH] Readme tests ignore bash blocks ending with `ignore` (#2069) --- linera-service/src/util.rs | 51 +++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/linera-service/src/util.rs b/linera-service/src/util.rs index de61a822f666..fc6609a1bdae 100644 --- a/linera-service/src/util.rs +++ b/linera-service/src/util.rs @@ -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() { @@ -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) +}