Skip to content

Commit

Permalink
test: update to use prettyplease in snapshots
Browse files Browse the repository at this point in the history
Now there is no need to ignore the snapshot tests in CI.
  • Loading branch information
ifiokjr committed Aug 27, 2024
1 parent cc4dfab commit 6174c96
Show file tree
Hide file tree
Showing 45 changed files with 1,625 additions and 1,587 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ node_modules/
/test-ledger

**/*.pem
lcov.info
lcov.info
codecov.json
11 changes: 5 additions & 6 deletions crates/edgedb_codegen/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn codegen_literals(testname: String, #[case] query: &str) -> Result<()> {
let relative_path = format!("tests/compile/codegen/{testname}.rs");
let descriptor = get_descriptor(query).await?;
let code = generate_rust_from_query(&descriptor, "example", query)?;
let content = rustfmt(&code.to_string()).await?;
let content = prettify(&code.to_string())?;

// Check that the snapshot hasn't changed.
insta::assert_snapshot!(&content);
Expand All @@ -76,7 +76,6 @@ async fn codegen_literals(testname: String, #[case] query: &str) -> Result<()> {
#[case("insert_user")]
#[case("remove_user")]
#[tokio::test]
#[rustversion::attr(not(nightly), ignore = "requires nightly")]
async fn codegen_files(#[case] path: &str) -> Result<()> {
set_snapshot_suffix!("{}", path);

Expand All @@ -85,7 +84,7 @@ async fn codegen_files(#[case] path: &str) -> Result<()> {
let query = tokio::fs::read_to_string(&query_path).await?;
let descriptor = get_descriptor(&query).await?;
let code = generate_rust_from_query(&descriptor, "example", &query)?;
let content = rustfmt(&code.to_string()).await?;
let content = prettify(&code.to_string())?;

// Check that the snapshot hasn't changed.
insta::assert_snapshot!(&content);
Expand All @@ -104,7 +103,7 @@ async fn prepare_compile_test(content: &str, relative_path: &str) -> Result<()>
.is_some_and(|v| ["1", "true"].contains(&v.as_str()));

let path = PathBuf::from(CRATE_DIR).join(relative_path);
let generated = generate_contents(content).await?;
let generated = generate_contents(content)?;

let should_update = match tokio::fs::read_to_string(&path).await {
Ok(current) => current != generated,
Expand All @@ -119,7 +118,7 @@ async fn prepare_compile_test(content: &str, relative_path: &str) -> Result<()>
Ok(())
}

async fn generate_contents(content: &str) -> Result<String> {
fn generate_contents(content: &str) -> Result<String> {
let updated = format!("fn main() {{\n{content}\n}}");
Ok(rustfmt(&updated).await?)
Ok(prettify(&updated)?)
}
42 changes: 21 additions & 21 deletions crates/edgedb_codegen/tests/compile/codegen/case_01_str.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
fn main() {
pub mod example {
use ::edgedb_codegen::exports as e;
#[doc = r" Execute the desired query."]
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
#[doc = r" Compose the query as part of a larger transaction."]
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = String;
#[doc = r" The original query string provided to the macro. Can be reused in your codebase."]
pub const QUERY: &str = "select 'i ❤\u{fe0f} edgedb'";
}
pub mod example {
use ::edgedb_codegen::exports as e;
/// Execute the desired query.
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
/// Compose the query as part of a larger transaction.
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = String;
/// The original query string provided to the macro. Can be reused in your codebase.
pub const QUERY: &str = "select 'i ❤\u{fe0f} edgedb'";
}
}
42 changes: 21 additions & 21 deletions crates/edgedb_codegen/tests/compile/codegen/case_02_bool.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
fn main() {
pub mod example {
use ::edgedb_codegen::exports as e;
#[doc = r" Execute the desired query."]
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
#[doc = r" Compose the query as part of a larger transaction."]
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = bool;
#[doc = r" The original query string provided to the macro. Can be reused in your codebase."]
pub const QUERY: &str = "select true";
}
pub mod example {
use ::edgedb_codegen::exports as e;
/// Execute the desired query.
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
/// Compose the query as part of a larger transaction.
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = bool;
/// The original query string provided to the macro. Can be reused in your codebase.
pub const QUERY: &str = "select true";
}
}
42 changes: 21 additions & 21 deletions crates/edgedb_codegen/tests/compile/codegen/case_03_int64.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
fn main() {
pub mod example {
use ::edgedb_codegen::exports as e;
#[doc = r" Execute the desired query."]
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
#[doc = r" Compose the query as part of a larger transaction."]
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = i64;
#[doc = r" The original query string provided to the macro. Can be reused in your codebase."]
pub const QUERY: &str = "select 3";
}
pub mod example {
use ::edgedb_codegen::exports as e;
/// Execute the desired query.
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
/// Compose the query as part of a larger transaction.
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = i64;
/// The original query string provided to the macro. Can be reused in your codebase.
pub const QUERY: &str = "select 3";
}
}
42 changes: 21 additions & 21 deletions crates/edgedb_codegen/tests/compile/codegen/case_04_float64.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
fn main() {
pub mod example {
use ::edgedb_codegen::exports as e;
#[doc = r" Execute the desired query."]
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
#[doc = r" Compose the query as part of a larger transaction."]
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = f64;
#[doc = r" The original query string provided to the macro. Can be reused in your codebase."]
pub const QUERY: &str = "select 314e-2";
}
pub mod example {
use ::edgedb_codegen::exports as e;
/// Execute the desired query.
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
/// Compose the query as part of a larger transaction.
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = f64;
/// The original query string provided to the macro. Can be reused in your codebase.
pub const QUERY: &str = "select 314e-2";
}
}
42 changes: 21 additions & 21 deletions crates/edgedb_codegen/tests/compile/codegen/case_05_bigint.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
fn main() {
pub mod example {
use ::edgedb_codegen::exports as e;
#[doc = r" Execute the desired query."]
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
#[doc = r" Compose the query as part of a larger transaction."]
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = e::num_bigint::BigInt;
#[doc = r" The original query string provided to the macro. Can be reused in your codebase."]
pub const QUERY: &str = "select 42n";
}
pub mod example {
use ::edgedb_codegen::exports as e;
/// Execute the desired query.
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
/// Compose the query as part of a larger transaction.
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = e::num_bigint::BigInt;
/// The original query string provided to the macro. Can be reused in your codebase.
pub const QUERY: &str = "select 42n";
}
}
42 changes: 21 additions & 21 deletions crates/edgedb_codegen/tests/compile/codegen/case_06_decimal.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
fn main() {
pub mod example {
use ::edgedb_codegen::exports as e;
#[doc = r" Execute the desired query."]
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
#[doc = r" Compose the query as part of a larger transaction."]
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = e::num_bigint::BigInt;
#[doc = r" The original query string provided to the macro. Can be reused in your codebase."]
pub const QUERY: &str = "select 42e+100n";
}
pub mod example {
use ::edgedb_codegen::exports as e;
/// Execute the desired query.
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
/// Compose the query as part of a larger transaction.
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = e::num_bigint::BigInt;
/// The original query string provided to the macro. Can be reused in your codebase.
pub const QUERY: &str = "select 42e+100n";
}
}
42 changes: 21 additions & 21 deletions crates/edgedb_codegen/tests/compile/codegen/case_07_uuid.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
fn main() {
pub mod example {
use ::edgedb_codegen::exports as e;
#[doc = r" Execute the desired query."]
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
#[doc = r" Compose the query as part of a larger transaction."]
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = e::uuid::Uuid;
#[doc = r" The original query string provided to the macro. Can be reused in your codebase."]
pub const QUERY: &str = "select <uuid>'a5ea6360-75bd-4c20-b69c-8f317b0d2857'";
}
pub mod example {
use ::edgedb_codegen::exports as e;
/// Execute the desired query.
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
client.query_required_single(QUERY, &()).await
}
/// Compose the query as part of a larger transaction.
#[cfg(feature = "query")]
pub async fn transaction(
conn: &mut e::edgedb_tokio::Transaction,
) -> core::result::Result<Output, e::edgedb_errors::Error> {
conn.query_required_single(QUERY, &()).await
}
pub type Input = ();
pub type Output = e::uuid::Uuid;
/// The original query string provided to the macro. Can be reused in your codebase.
pub const QUERY: &str = "select <uuid>'a5ea6360-75bd-4c20-b69c-8f317b0d2857'";
}
}
Loading

0 comments on commit 6174c96

Please sign in to comment.