mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 06:02:33 +00:00
CI baseline: platform temp dir mode check without a bool-literal guard and its test reads file_path; window Linux-only helpers lose the test cfg; update's settle_for_tests and migration trials; prepress group_item replaces unreachable; svg font path to ui-contract
This commit is contained in:
+18
-12
@@ -121,18 +121,24 @@ fn check_plain(name: &str) -> std::io::Result<()> {
|
||||
/// `is_symlink()` is never true.
|
||||
// cadcraft: crates/ui-egui/src/control.rs:609 is_private_shot_dir
|
||||
pub fn is_private_dir(meta: &Metadata) -> bool {
|
||||
if !meta.is_dir() || meta.file_type().is_symlink() {
|
||||
return false;
|
||||
}
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt as _;
|
||||
meta.permissions().mode() & 0o077 == 0
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
true
|
||||
}
|
||||
// A real directory, so nothing is followed, whose mode grants group and other nothing; the
|
||||
// mode comes off this same snapshot, never a second stat.
|
||||
meta.is_dir() && !meta.file_type().is_symlink() && has_private_mode(meta)
|
||||
}
|
||||
|
||||
/// The Unix half of [`is_private_dir`]: `meta`'s mode has no group or other permission bit. It
|
||||
/// reads the mode off the same snapshot the caller was given, so it never stats another file.
|
||||
#[cfg(unix)]
|
||||
fn has_private_mode(meta: &Metadata) -> bool {
|
||||
use std::os::unix::fs::PermissionsExt as _;
|
||||
meta.permissions().mode() & 0o077 == 0
|
||||
}
|
||||
|
||||
/// Without Unix mode bits, the documented fallback accepts a real directory once the caller has
|
||||
/// rejected files and symlinks; this does not inspect or make a claim about platform ACLs.
|
||||
#[cfg(not(unix))]
|
||||
fn has_private_mode(_meta: &Metadata) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Temporary folders the app owns until it is done with them: print previews open in the system
|
||||
|
||||
@@ -11,6 +11,9 @@ fn private_dir_is_owner_only_and_removed_on_drop() {
|
||||
let path = dir.path().to_path_buf();
|
||||
assert!(is_private_dir(&std::fs::symlink_metadata(&path).unwrap()));
|
||||
let (file_path, _file) = dir.create("a.txt").unwrap();
|
||||
assert_eq!(file_path.file_name(), Some(std::ffi::OsStr::new("a.txt")), "the created path is the plain name, as asked");
|
||||
assert_eq!(file_path.parent(), Some(path.as_path()), "the file is created inside the private folder");
|
||||
assert!(std::fs::symlink_metadata(&file_path).is_ok(), "the file exists on disk on every platform");
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt as _;
|
||||
|
||||
@@ -24,7 +24,11 @@ fn solid(r: Rect, tints: &[(InkId, f32)]) -> Item {
|
||||
}
|
||||
|
||||
fn group(opacity: f32, children: Vec<Item>) -> Item {
|
||||
Item::Group(GroupItem {
|
||||
Item::Group(group_item(opacity, children))
|
||||
}
|
||||
|
||||
fn group_item(opacity: f32, children: Vec<Item>) -> GroupItem {
|
||||
GroupItem {
|
||||
opacity,
|
||||
blend: BlendMode::Normal,
|
||||
isolated: false,
|
||||
@@ -34,7 +38,7 @@ fn group(opacity: f32, children: Vec<Item>) -> Item {
|
||||
mask: None,
|
||||
actual_text: None,
|
||||
children,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn page(inks: InkSet, items: Vec<Item>) -> DisplayList {
|
||||
@@ -91,7 +95,7 @@ fn an_even_odd_clip_keeps_its_hole_written_or_flattened() {
|
||||
// Two nested squares drawn in the same direction: filled even-odd, the inner one is a hole.
|
||||
let mut ring = Rect::new(0.0, 0.0, 100.0, 100.0).to_path(0.1);
|
||||
ring.extend(Rect::new(25.0, 25.0, 75.0, 75.0).to_path(0.1));
|
||||
let Item::Group(half_black) = group(0.5, vec![solid(Rect::new(0.0, 0.0, 100.0, 100.0), &[(K, 1.0)])]) else { unreachable!() };
|
||||
let half_black = group_item(0.5, vec![solid(Rect::new(0.0, 0.0, 100.0, 100.0), &[(K, 1.0)])]);
|
||||
let clipped = Item::Group(GroupItem { clip: Some(ring), clip_rule: FillRule::EvenOdd, ..half_black });
|
||||
let list = page(InkSet::new(), vec![solid(Rect::new(0.0, 0.0, 100.0, 100.0), &[(C, 1.0)]), clipped]);
|
||||
for written in [pdf(&list), flat_pdf(&list)] {
|
||||
|
||||
@@ -321,7 +321,7 @@ fn elements_usvg_leaves_out_are_listed() {
|
||||
fn local_text_is_placed_and_bounded_in_its_parents_frame() {
|
||||
let mut options = usvg::Options::default();
|
||||
let fonts = options.fontdb_mut();
|
||||
fonts.load_font_data(include_bytes!("../../../ui/tests/fonts/NotoSans-test.ttf").to_vec());
|
||||
fonts.load_font_data(include_bytes!("../../../ui-contract/tests/fonts/NotoSans-test.ttf").to_vec());
|
||||
let family = fonts.faces().next().unwrap().families[0].0.clone();
|
||||
let svg = format!(
|
||||
r#"<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><g id="move" transform="translate(50 0)"><text id="t" x="5" y="20" font-family="{family}" font-size="10">Hi</text></g></svg>"#
|
||||
|
||||
@@ -223,8 +223,9 @@ pub(crate) fn oci_ref_available(reference: &str, expected: &version::Version, li
|
||||
}
|
||||
|
||||
#[cfg(all(test, target_os = "linux", feature = "oci_migration"))]
|
||||
#[allow(clippy::unwrap_used, reason = "tests fail by panicking")]
|
||||
mod migration_tests {
|
||||
use super::*;
|
||||
use super::{oci_ref_available, version};
|
||||
use craft_ui::testing::trial;
|
||||
|
||||
#[trial]
|
||||
|
||||
@@ -1068,7 +1068,7 @@ fn prompt_id() -> craft_ui::dialog::DialogId {
|
||||
dialog_id("updateDialog.prompt")
|
||||
}
|
||||
|
||||
#[cfg(feature = "screen-testing")]
|
||||
#[cfg(any(test, feature = "screen-testing"))]
|
||||
impl Updater {
|
||||
/// Waits for the running check's answer on its channel (its thread always sends one, or ends
|
||||
/// and closes the channel), then hands it to `tick` as a pass would; then does the same for
|
||||
|
||||
@@ -67,11 +67,11 @@ pub fn theme_svgs<const N: usize>(theme: &str, icons: [&str; N]) -> [Option<Vec<
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", test))]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
|
||||
/// Compositors and window managers that tile, matched against the `XDG_CURRENT_DESKTOP` entries.
|
||||
const TILING: &[&str] = &["sway", "hyprland", "i3", "niri", "river", "bspwm", "awesome", "dwl", "qtile", "herbstluftwm", "leftwm", "xmonad", "dwm"];
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", test))]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
|
||||
/// The desktop kind from the first of its variables that is set (`XDG_CURRENT_DESKTOP`,
|
||||
/// `XDG_SESSION_DESKTOP`, `DESKTOP_SESSION`). `ubuntu:GNOME` and `Budgie:GNOME` count as GNOME.
|
||||
/// craft-platform's `is_gnome_session` (appearance.rs) repeats these rules; change both together.
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
|
||||
use crate::desktop::DesktopKind;
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", test))]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
|
||||
/// The value of `key` in `[section]` of an INI-style file (GTK's `settings.ini`, KDE's `kwinrc`).
|
||||
pub(crate) fn ini_value(text: &str, section: &str, key: &str) -> Option<String> {
|
||||
let mut inside = false;
|
||||
@@ -25,7 +25,7 @@ pub(crate) fn ini_value(text: &str, section: &str, key: &str) -> Option<String>
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", test))]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
|
||||
/// KWin's button order (`[org.kde.kdecoration2]` `ButtonsOnLeft` / `ButtonsOnRight`, one letter a
|
||||
/// button: `I` minimize, `A` maximize, `X` close) as a GTK layout string. Missing keys keep KWin's
|
||||
/// defaults: the window menu on the left, minimize, maximize and close on the right.
|
||||
@@ -46,7 +46,7 @@ pub(crate) fn kwin_layout(kwinrc: &str) -> String {
|
||||
format!("{}:{}", side("ButtonsOnLeft", "MS"), side("ButtonsOnRight", "HIAX"))
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", test))]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
|
||||
/// The `gtk-decoration-layout` and `gtk-theme-name` of a GTK 3 `settings.ini`.
|
||||
pub(crate) fn gtk_settings(settings_ini: &str) -> (Option<String>, Option<String>) {
|
||||
(ini_value(settings_ini, "Settings", "gtk-decoration-layout"), ini_value(settings_ini, "Settings", "gtk-theme-name"))
|
||||
@@ -219,7 +219,7 @@ pub(crate) fn read_gtk_theme(var: &dyn Fn(&str) -> Option<String>) -> Option<Str
|
||||
from_env.or_else(|| read_config(var, "gtk-3.0/settings.ini").and_then(|ini| gtk_settings(&ini).1))
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", test))]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
|
||||
/// The icon theme name for `kind`'s own setting (`kdeglobals` `[Icons] Theme` on KDE, GTK's
|
||||
/// `gtk-icon-theme-name` elsewhere), else the desktop's default theme.
|
||||
pub(crate) fn icon_theme(kind: DesktopKind, kdeglobals: &str, settings_ini: &str) -> String {
|
||||
|
||||
Reference in New Issue
Block a user