From e9f93b7b030205401f9995f40fda2dcb3164d57b Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Sun, 25 Feb 2024 16:04:00 +0000 Subject: [PATCH 1/3] `env` needs to be imported. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ffd6033..e65a8eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ //! [`compiletest_rs`](https://crates.io/crates/compiletest_rs), looks as follows: //! //! ```rust,ignore -//! use std::{fs::read_to_string, path::PathBuf, process::Command}; +//! use std::{env, fs::read_to_string, path::PathBuf, process::Command}; //! //! use lang_tester::LangTester; //! use tempfile::TempDir; From 3e8567ba0d0d47d1c463be3a12dcdcb016925d7a Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Sun, 25 Feb 2024 16:04:33 +0000 Subject: [PATCH 2/3] Be a little clearer as to which comment is which. --- src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e65a8eb..3546919 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,8 +14,6 @@ //! use lang_tester::LangTester; //! use tempfile::TempDir; //! -//! static COMMENT_PREFIX: &str = "//"; -//! //! fn main() { //! // We use rustc to compile files into a binary: we store those binary files //! // into `tempdir`. This may not be necessary for other languages. @@ -24,7 +22,7 @@ //! .test_dir("examples/rust_lang_tester/lang_tests") //! // Only use files named `*.rs` as test files. //! .test_path_filter(|p| p.extension().and_then(|x| x.to_str()) == Some("rs")) -//! // Treat lines beginning with "#" as comments. +//! // Treat lines beginning with "#" inside a test as comments. //! .comment_prefix("#") //! // Extract the first sequence of commented line(s) as the tests. //! .test_extract(|p| { @@ -32,9 +30,9 @@ //! .unwrap() //! .lines() //! // Skip non-commented lines at the start of the file. -//! .skip_while(|l| !l.starts_with(COMMENT_PREFIX)) +//! .skip_while(|l| !l.starts_with("//")) //! // Extract consecutive commented lines. -//! .take_while(|l| l.starts_with(COMMENT_PREFIX)) +//! .take_while(|l| l.starts_with("//")) //! .map(|l| &l[COMMENT_PREFIX.len()..]) //! .collect::>() //! .join("\n") From 9c5c958a468440feaef5c5b1835f34de803bbf23 Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Sun, 25 Feb 2024 16:05:51 +0000 Subject: [PATCH 3/3] Sync README example code with `lib.rs`. --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9dfefdf..de62158 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,11 @@ For example, a Rust language tester, loosely in the spirit of [`compiletest_rs`](https://crates.io/crates/compiletest_rs), looks as follows: ```rust -use std::{fs::read_to_string, path::PathBuf, process::Command}; +use std::{env, fs::read_to_string, path::PathBuf, process::Command}; use lang_tester::LangTester; use tempfile::TempDir; -static COMMENT_PREFIX: &str = "//"; - fn main() { // We use rustc to compile files into a binary: we store those binary files // into `tempdir`. This may not be necessary for other languages. @@ -26,8 +24,8 @@ fn main() { LangTester::new() .test_dir("examples/rust_lang_tester/lang_tests") // Only use files named `*.rs` as test files. - .test_file_filter(|p| p.extension().unwrap().to_str().unwrap() == "rs") - // Treat lines beginning with "#" as comments. + .test_path_filter(|p| p.extension().and_then(|x| x.to_str()) == Some("rs")) + // Treat lines beginning with "#" inside a test as comments. .comment_prefix("#") // Extract the first sequence of commented line(s) as the tests. .test_extract(|p| { @@ -35,9 +33,9 @@ fn main() { .unwrap() .lines() // Skip non-commented lines at the start of the file. - .skip_while(|l| !l.starts_with(COMMENT_PREFIX)) + .skip_while(|l| !l.starts_with("//")) // Extract consecutive commented lines. - .take_while(|l| l.starts_with(COMMENT_PREFIX)) + .take_while(|l| l.starts_with("//")) .map(|l| &l[COMMENT_PREFIX.len()..]) .collect::>() .join("\n")