diff --git a/src/config.rs b/src/config.rs index bbd3039..761068e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -148,7 +148,8 @@ impl Config { } pub fn read_file(file_path: impl AsRef) -> Result { - let doc = Document::read_file(file_path)?; + // TODO: error message should contain file path to missing `` + let doc = Document::read_file(&file_path)?; Self::try_from(doc) } } diff --git a/src/config/xml.rs b/src/config/xml.rs index ddd25cb..10c0d67 100644 --- a/src/config/xml.rs +++ b/src/config/xml.rs @@ -33,6 +33,7 @@ impl FromStr for Document { impl Document { pub fn read_file(file_path: impl AsRef) -> Result { let text = read_to_string(file_path.as_ref())?; + let mut doc = Document::from_str(&text)?; doc.file_path = Some(file_path.as_ref().to_path_buf()); doc.resolve_includes() @@ -263,6 +264,12 @@ fn resolve_include_path( return p.canonicalize().map_err(Error::msg); } + error!( + "resolve_include_path: {} {}", + &base_path.as_ref().display(), + &include_path.as_ref().display() + ); + base_path .as_ref() .join(p) diff --git a/tests/config.rs b/tests/config.rs index 4fccf41..83a283f 100644 --- a/tests/config.rs +++ b/tests/config.rs @@ -4,8 +4,8 @@ use busd::config::{Access, Config, Name, Operation, OwnOperation, Policy}; #[test] fn config_read_file_with_includes_ok() { - let got = Config::read_file("./tests/fixture.conf") - .expect("should read and parse ./tests/fixture.conf"); + let got = + Config::read_file("./tests/fixtures/valid.conf").expect("should read and parse XML input"); assert_eq!( got, @@ -49,3 +49,17 @@ fn config_read_file_with_includes_ok() { } ); } + +#[should_panic] +#[test] +fn config_read_file_with_missing_include_err() { + Config::read_file("./tests/fixtures/missing_include.conf") + .expect("should read and parse XML input"); +} + +#[should_panic] +#[test] +fn config_read_file_with_transitive_missing_include_err() { + Config::read_file("./tests/fixtures/transitive_missing_include.conf") + .expect("should read and parse XML input"); +} diff --git a/tests/fixtures/missing_include.conf b/tests/fixtures/missing_include.conf new file mode 100644 index 0000000..67632af --- /dev/null +++ b/tests/fixtures/missing_include.conf @@ -0,0 +1,5 @@ + + + ./missing.conf + diff --git a/tests/fixtures/transitive_missing_include.conf b/tests/fixtures/transitive_missing_include.conf new file mode 100644 index 0000000..a317999 --- /dev/null +++ b/tests/fixtures/transitive_missing_include.conf @@ -0,0 +1,5 @@ + + + ./missing_include.conf + diff --git a/tests/fixture.conf b/tests/fixtures/valid.conf similarity index 74% rename from tests/fixture.conf rename to tests/fixtures/valid.conf index 494b4d0..7a20a08 100644 --- a/tests/fixture.conf +++ b/tests/fixtures/valid.conf @@ -7,6 +7,6 @@ - ./fixture_included.conf - ./fixture_missing.conf + ./valid_included.conf + ./valid_missing.conf diff --git a/tests/fixture_included.conf b/tests/fixtures/valid_included.conf similarity index 100% rename from tests/fixture_included.conf rename to tests/fixtures/valid_included.conf