Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #206

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
33 changes: 33 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ use self::{
config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE},
};

#[cfg(test)]
#[macro_use]
extern crate ctor;

Comment on lines +54 to +57
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not needed.

fn main() -> glib::ExitCode {
tracing_subscriber::fmt::init();

Expand All @@ -70,3 +74,32 @@ fn main() -> glib::ExitCode {
let app = Application::new();
app.run()
}

#[cfg(test)]
mod test {
use ctor;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as this

use std::{env, process::Command};

// Run once before tests are executed.
#[ctor]
Copy link
Owner

@SeaDve SeaDve Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[ctor]
#[ctor::ctor]

or

use ctor::ctor;

#[ctor]
fn setup_schema() {
    ...
}

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");
}
}
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ test(
cargo_options,
'--',
'--nocapture',
'--test-threads=1',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still required, even though gtk tests already run single threaded?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't add it if it wasn't needed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure why this is still needed

],
env: [
'RUST_BACKTRACE=1',
'GSETTINGS_SCHEMA_DIR=@0@/data'.format(meson.project_build_root()),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed too since it is set on setup_schema.

cargo_env
],
timeout: 300, # give cargo more time
Expand Down
28 changes: 0 additions & 28 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down