diff --git a/.ci/test-cover b/.ci/test-cover index d0ebca9..693658a 100755 --- a/.ci/test-cover +++ b/.ci/test-cover @@ -15,7 +15,7 @@ grcov "${DESTDIR}" \ --ignore '**/clang-sys*/**' \ --ignore "$HOME/.cargo/**" \ --ignore-not-existing \ - --ignore 'tests/**' \ + --ignore '**/tests/**' \ --ignore 'build.rs' \ --excl-start '#(\[cfg\(test\)\]|\[test\])' \ --llvm \ diff --git a/tests/corpus/v1/howto.json b/corpus/v1/howto.json similarity index 100% rename from tests/corpus/v1/howto.json rename to corpus/v1/howto.json diff --git a/tests/corpus/v1/howto2.json b/corpus/v1/howto2.json similarity index 100% rename from tests/corpus/v1/howto2.json rename to corpus/v1/howto2.json diff --git a/tests/corpus/v1/widget.json b/corpus/v1/widget.json similarity index 100% rename from tests/corpus/v1/widget.json rename to corpus/v1/widget.json diff --git a/tests/corpus/v2/minimal.json b/corpus/v2/minimal.json similarity index 100% rename from tests/corpus/v2/minimal.json rename to corpus/v2/minimal.json diff --git a/tests/corpus/v2/pg_partman.json b/corpus/v2/pg_partman.json similarity index 100% rename from tests/corpus/v2/pg_partman.json rename to corpus/v2/pg_partman.json diff --git a/tests/corpus/v2/postgresml.json b/corpus/v2/postgresml.json similarity index 100% rename from tests/corpus/v2/postgresml.json rename to corpus/v2/postgresml.json diff --git a/tests/corpus/v2/typical-c.json b/corpus/v2/typical-c.json similarity index 100% rename from tests/corpus/v2/typical-c.json rename to corpus/v2/typical-c.json diff --git a/tests/corpus/v2/typical-pgrx.json b/corpus/v2/typical-pgrx.json similarity index 100% rename from tests/corpus/v2/typical-pgrx.json rename to corpus/v2/typical-pgrx.json diff --git a/tests/corpus/v2/typical-sql.json b/corpus/v2/typical-sql.json similarity index 100% rename from tests/corpus/v2/typical-sql.json rename to corpus/v2/typical-sql.json diff --git a/src/lib.rs b/src/lib.rs index c3df338..4bc6826 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,8 +41,8 @@ assert!(validator.validate(&meta).is_ok()); */ -#[doc(hidden)] -pub mod compiler; - mod valid; pub use valid::{ValidationError, Validator}; + +#[cfg(test)] +mod tests; diff --git a/tests/common/mod.rs b/src/tests/common.rs similarity index 98% rename from tests/common/mod.rs rename to src/tests/common.rs index c77a3b4..a7edbe3 100644 --- a/tests/common/mod.rs +++ b/src/tests/common.rs @@ -1,4 +1,3 @@ -use pgxn_meta::compiler; use std::{ collections::HashMap, error::Error, @@ -6,6 +5,7 @@ use std::{ path::Path, }; +use crate::valid::compiler; use boon::{Compiler, Schemas}; use serde_json::{json, Value}; use wax::Glob; @@ -27,7 +27,7 @@ pub const VALID_SEMVERS: &[&str] = &[ "1.0.0-alpha.1", "1.0.0-alpha0.valid", "1.0.0-alpha.0valid", - "1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay", + "1.0.0-alpha-a.b-c-something-long+build.1-aef.1-its-okay", "1.0.0-rc.1+build.1", "2.0.0-rc.1+build.123", "1.2.3-beta", @@ -83,7 +83,7 @@ pub const INVALID_SEMVERS: &[&str] = &[ "1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788", "1.2-RC-SNAPSHOT", "-1.0.3-gamma+b7718", - "+justmeta", + "+just-meta", "9.8.7+meta+meta", "9.8.7-whatever+meta+meta", "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12", diff --git a/src/tests/mod.rs b/src/tests/mod.rs new file mode 100644 index 0000000..7f11b1e --- /dev/null +++ b/src/tests/mod.rs @@ -0,0 +1,3 @@ +mod common; +mod v1; +mod v2; diff --git a/tests/v1_schema_test.rs b/src/tests/v1.rs similarity index 99% rename from tests/v1_schema_test.rs rename to src/tests/v1.rs index 07a8ae8..df1b3e4 100644 --- a/tests/v1_schema_test.rs +++ b/src/tests/v1.rs @@ -4,8 +4,7 @@ use boon::Schemas; use serde_json::{json, Map, Value}; // importing common module. -mod common; -use common::*; +use super::common::*; const SCHEMA_VERSION: u8 = 1; diff --git a/tests/v2_schema_test.rs b/src/tests/v2.rs similarity index 99% rename from tests/v2_schema_test.rs rename to src/tests/v2.rs index 7be7813..f18ac34 100644 --- a/tests/v2_schema_test.rs +++ b/src/tests/v2.rs @@ -4,8 +4,7 @@ use boon::Schemas; use serde_json::{json, Map, Value}; // importing common module. -mod common; -use common::*; +use super::common::*; const SCHEMA_VERSION: u8 = 2; diff --git a/src/compiler/mod.rs b/src/valid/compiler/mod.rs similarity index 98% rename from src/compiler/mod.rs rename to src/valid/compiler/mod.rs index 5e982a4..533ddba 100644 --- a/src/compiler/mod.rs +++ b/src/valid/compiler/mod.rs @@ -17,7 +17,7 @@ pub fn new() -> Compiler { let schema: Value = serde_json::from_str(str).unwrap(); let id = &schema["$id"] .as_str() - .ok_or(super::valid::ValidationError::UnknownID) + .ok_or(super::ValidationError::UnknownID) .unwrap(); compiler.add_resource(id, schema.to_owned()).unwrap(); } @@ -161,7 +161,6 @@ mod tests { let idx = compiler.compile(&id, &mut schemas)?; let path = Path::new(env!("CARGO_MANIFEST_DIR")) - .join("tests") .join("corpus") .join(tc.0) .join(tc.1); diff --git a/src/valid/mod.rs b/src/valid/mod.rs index eb9fb4f..f63bc73 100644 --- a/src/valid/mod.rs +++ b/src/valid/mod.rs @@ -4,6 +4,13 @@ use std::{error::Error, fmt}; use boon::{Compiler, Schemas}; use serde_json::Value; +// Export compiler publicly only for tests. +#[cfg(test)] +pub mod compiler; + +#[cfg(not(test))] +mod compiler; + /// PGXN Meta validator. pub struct Validator { compiler: Compiler, @@ -46,7 +53,7 @@ impl Validator { /// `dir`. pub fn new() -> Validator { Validator { - compiler: super::compiler::new(), + compiler: compiler::new(), schemas: Schemas::new(), } } @@ -99,7 +106,7 @@ mod tests { let mut validator = Validator::default(); for v_dir in ["v1", "v2"] { - let dir: PathBuf = [env!("CARGO_MANIFEST_DIR"), "tests", "corpus", v_dir] + let dir: PathBuf = [env!("CARGO_MANIFEST_DIR"), "corpus", v_dir] .iter() .collect(); let glob = Glob::new("*.json")?; @@ -122,7 +129,6 @@ mod tests { for tc in [("v1", "widget.json"), ("v2", "typical-sql.json")] { let path = Path::new(env!("CARGO_MANIFEST_DIR")) - .join("tests") .join("corpus") .join(tc.0) .join(tc.1);