projects/aports·blob master · refs

147 lines · 4.0 KiB

1Patch-Source: https://github.com/SeaDve/Kooha/pull/206
2--
3diff --git a/Cargo.lock b/Cargo.lock
4index 0153b46..36076b3 100644
5--- a/Cargo.lock
6+++ b/Cargo.lock
7@@ -148,6 +148,16 @@ version = "0.8.4"
8 source = "registry+https://github.com/rust-lang/crates.io-index"
9 checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
10
11+[[package]]
12+name = "ctor"
13+version = "0.2.5"
14+source = "registry+https://github.com/rust-lang/crates.io-index"
15+checksum = "37e366bff8cd32dd8754b0991fb66b279dc48f598c3a18914852a6673deef583"
16+dependencies = [
17+ "quote",
18+ "syn 2.0.37",
19+]
20+
21 [[package]]
22 name = "deluxe"
23 version = "0.5.0"
24@@ -944,6 +954,7 @@ name = "kooha"
25 version = "2.2.4"
26 dependencies = [
27 "anyhow",
28+ "ctor",
29 "futures-channel",
30 "futures-util",
31 "gdk4-wayland",
32diff --git a/Cargo.toml b/Cargo.toml
33index 4c52b5f..1afda95 100644
34--- a/Cargo.toml
35+++ b/Cargo.toml
36@@ -29,3 +29,6 @@ futures-util = { version = "0.3", default-features = false }
37 gsettings-macro = "0.1.15"
38 pulse = { package = "libpulse-binding", version = "2.26.0" }
39 pulse_glib = { package = "libpulse-glib-binding", version = "2.25.1" }
40+
41+[dev-dependencies]
42+ctor = "0.2.5"
43diff --git a/src/main.rs b/src/main.rs
44index c05eef0..a8b4778 100644
45--- a/src/main.rs
46+++ b/src/main.rs
47@@ -51,6 +51,10 @@ use self::{
48 config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE},
49 };
50
51+#[cfg(test)]
52+#[macro_use]
53+extern crate ctor;
54+
55 fn main() -> glib::ExitCode {
56 tracing_subscriber::fmt::init();
57
58@@ -70,3 +74,32 @@ fn main() -> glib::ExitCode {
59 let app = Application::new();
60 app.run()
61 }
62+
63+#[cfg(test)]
64+mod test {
65+ use ctor;
66+ use std::{env, process::Command};
67+
68+ // Run once before tests are executed.
69+ #[ctor]
70+ fn setup_schema() {
71+ let schema_dir = &env::var("GSETTINGS_SCHEMA_DIR")
72+ .unwrap_or(concat!(env!("CARGO_MANIFEST_DIR"), "/data").into());
73+
74+ let output = Command::new("glib-compile-schemas")
75+ .arg(schema_dir)
76+ .output()
77+ .unwrap();
78+
79+ if !output.status.success() {
80+ panic!(
81+ "Failed to compile GSchema for tests; stdout: {}; stderr: {}",
82+ String::from_utf8_lossy(&output.stdout),
83+ String::from_utf8_lossy(&output.stderr)
84+ );
85+ }
86+
87+ env::set_var("GSETTINGS_SCHEMA_DIR", schema_dir);
88+ env::set_var("GSETTINGS_BACKEND", "memory");
89+ }
90+}
91diff --git a/src/meson.build b/src/meson.build
92index 002cc1f..ae0fde1 100644
93--- a/src/meson.build
94+++ b/src/meson.build
95@@ -59,9 +59,11 @@ test(
96 cargo_options,
97 '--',
98 '--nocapture',
99+ '--test-threads=1',
100 ],
101 env: [
102 'RUST_BACKTRACE=1',
103+ 'GSETTINGS_SCHEMA_DIR=@0@/data'.format(meson.project_build_root()),
104 cargo_env
105 ],
106 timeout: 300, # give cargo more time
107diff --git a/src/settings.rs b/src/settings.rs
108index 8582a8a..4d1c2bf 100644
109--- a/src/settings.rs
110+++ b/src/settings.rs
111@@ -150,36 +150,8 @@ impl Settings {
112 mod tests {
113 use super::*;
114
115- use std::{env, process::Command, sync::Once};
116-
117- fn setup_schema() {
118- static INIT: Once = Once::new();
119-
120- INIT.call_once(|| {
121- let schema_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/data");
122-
123- let output = Command::new("glib-compile-schemas")
124- .arg(schema_dir)
125- .output()
126- .unwrap();
127-
128- if !output.status.success() {
129- panic!(
130- "Failed to compile GSchema for tests; stdout: {}; stderr: {}",
131- String::from_utf8_lossy(&output.stdout),
132- String::from_utf8_lossy(&output.stderr)
133- );
134- }
135-
136- env::set_var("GSETTINGS_SCHEMA_DIR", schema_dir);
137- env::set_var("GSETTINGS_BACKEND", "memory");
138- });
139- }
140-
141 #[test]
142 fn default_profile() {
143- setup_schema();
144-
145 assert!(Settings::default().profile().is_some());
146 assert!(Settings::default().profile().unwrap().supports_audio());
147 }