diff --git a/changelog.d/20240102_174335_GitHub_Actions_mkcws-tests.ron b/changelog.d/20240102_174335_GitHub_Actions_mkcws-tests.ron new file mode 100644 index 00000000..8b464e2e --- /dev/null +++ b/changelog.d/20240102_174335_GitHub_Actions_mkcws-tests.ron @@ -0,0 +1,8 @@ +( + references: {}, + changes: { + "Added": [ + "mkcws: unit tests", + ], + }, +) diff --git a/src/utilities.rs b/src/utilities.rs index e1b3e03a..ee0e513b 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -46,9 +46,20 @@ impl Mkcws { self.output_file.truncate(Box::new( "{ \"folders\" : [ { \"path\" : \"".to_string() + &format!("{}", self.directory.display()) - + "\", }, ], \"settings\" : [], }\n", + + "\" } ] }\n", )) } + + /// Create a new instance. + pub fn new(directory: T, output_file: Option) -> Self + where + std::path::PathBuf: From, + { + Self { + directory: std::path::PathBuf::from(directory), + output_file: output_file.map(Into::into), + } + } } /// Extract Markdown code from Rust documentation comments. diff --git a/tests/utilities.rs b/tests/utilities.rs index 304a5443..e9a6074b 100644 --- a/tests/utilities.rs +++ b/tests/utilities.rs @@ -159,4 +159,21 @@ make_test!(@rs2md @twice rs2md_both_inner_and_outer -> true, true ); +#[cfg(feature = "mkcws")] +#[test] +fn mkcws() { + use aeruginous::ReadFile; + + assert!(aeruginous::Mkcws::new(".", Some("cwd.code-workspace")) + .main() + .is_ok()); + + assert_eq!( + "cwd.code-workspace".read().unwrap(), + "{ \"folders\" : [ { \"path\" : \".\" } ] }\n" + ); + + std::fs::remove_file("cwd.code-workspace").unwrap(); +} + /******************************************************************************/