aports/community/kooha/fix-tests.patch
2023-11-16 08:58:48 +00:00

148 lines
4.0 KiB
Diff

Patch-Source: https://github.com/SeaDve/Kooha/pull/206
--
diff --git a/Cargo.lock b/Cargo.lock
index 0153b46..36076b3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -148,6 +148,16 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
+[[package]]
+name = "ctor"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "37e366bff8cd32dd8754b0991fb66b279dc48f598c3a18914852a6673deef583"
+dependencies = [
+ "quote",
+ "syn 2.0.37",
+]
+
[[package]]
name = "deluxe"
version = "0.5.0"
@@ -944,6 +954,7 @@ name = "kooha"
version = "2.2.4"
dependencies = [
"anyhow",
+ "ctor",
"futures-channel",
"futures-util",
"gdk4-wayland",
diff --git a/Cargo.toml b/Cargo.toml
index 4c52b5f..1afda95 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,3 +29,6 @@ futures-util = { version = "0.3", default-features = false }
gsettings-macro = "0.1.15"
pulse = { package = "libpulse-binding", version = "2.26.0" }
pulse_glib = { package = "libpulse-glib-binding", version = "2.25.1" }
+
+[dev-dependencies]
+ctor = "0.2.5"
diff --git a/src/main.rs b/src/main.rs
index c05eef0..a8b4778 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -51,6 +51,10 @@ use self::{
config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE},
};
+#[cfg(test)]
+#[macro_use]
+extern crate ctor;
+
fn main() -> glib::ExitCode {
tracing_subscriber::fmt::init();
@@ -70,3 +74,32 @@ fn main() -> glib::ExitCode {
let app = Application::new();
app.run()
}
+
+#[cfg(test)]
+mod test {
+ use ctor;
+ use std::{env, process::Command};
+
+ // Run once before tests are executed.
+ #[ctor]
+ fn setup_schema() {
+ let schema_dir = &env::var("GSETTINGS_SCHEMA_DIR")
+ .unwrap_or(concat!(env!("CARGO_MANIFEST_DIR"), "/data").into());
+
+ let output = Command::new("glib-compile-schemas")
+ .arg(schema_dir)
+ .output()
+ .unwrap();
+
+ if !output.status.success() {
+ panic!(
+ "Failed to compile GSchema for tests; stdout: {}; stderr: {}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ }
+
+ env::set_var("GSETTINGS_SCHEMA_DIR", schema_dir);
+ env::set_var("GSETTINGS_BACKEND", "memory");
+ }
+}
diff --git a/src/meson.build b/src/meson.build
index 002cc1f..ae0fde1 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -59,9 +59,11 @@ test(
cargo_options,
'--',
'--nocapture',
+ '--test-threads=1',
],
env: [
'RUST_BACKTRACE=1',
+ 'GSETTINGS_SCHEMA_DIR=@0@/data'.format(meson.project_build_root()),
cargo_env
],
timeout: 300, # give cargo more time
diff --git a/src/settings.rs b/src/settings.rs
index 8582a8a..4d1c2bf 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -150,36 +150,8 @@ impl Settings {
mod tests {
use super::*;
- use std::{env, process::Command, sync::Once};
-
- fn setup_schema() {
- static INIT: Once = Once::new();
-
- INIT.call_once(|| {
- let schema_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/data");
-
- let output = Command::new("glib-compile-schemas")
- .arg(schema_dir)
- .output()
- .unwrap();
-
- if !output.status.success() {
- panic!(
- "Failed to compile GSchema for tests; stdout: {}; stderr: {}",
- String::from_utf8_lossy(&output.stdout),
- String::from_utf8_lossy(&output.stderr)
- );
- }
-
- env::set_var("GSETTINGS_SCHEMA_DIR", schema_dir);
- env::set_var("GSETTINGS_BACKEND", "memory");
- });
- }
-
#[test]
fn default_profile() {
- setup_schema();
-
assert!(Settings::default().profile().is_some());
assert!(Settings::default().profile().unwrap().supports_audio());
}