From e86e3fb82d7383234c9c64d213b92c84d5c41bb5 Mon Sep 17 00:00:00 2001 From: fox0 <15684995+fox0@users.noreply.github.com> Date: Sat, 26 Oct 2024 18:53:16 +0700 Subject: [PATCH] misc: Use compile-time macro env! --- misc/Cargo.toml | 4 +++- misc/test.rs | 12 +++++------- misc/tests/false/mod.rs | 2 +- misc/tests/test/mod.rs | 2 +- misc/tests/true/mod.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/misc/Cargo.toml b/misc/Cargo.toml index 933758dde..5c01e72b7 100644 --- a/misc/Cargo.toml +++ b/misc/Cargo.toml @@ -8,11 +8,13 @@ edition.workspace = true rust-version.workspace = true [dependencies] -plib = { path = "../plib" } clap.workspace = true libc.workspace = true gettext-rs.workspace = true +[dev-dependencies] +plib = { path = "../plib" } + [lints] workspace = true diff --git a/misc/test.rs b/misc/test.rs index 88c22c778..1e91ded83 100644 --- a/misc/test.rs +++ b/misc/test.rs @@ -11,13 +11,11 @@ // - fix and test unary ops // -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use plib::PROJECT_NAME; -use std::os::unix::fs::FileTypeExt; -use std::os::unix::fs::MetadataExt; -use std::os::unix::fs::PermissionsExt; +use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt}; use std::path::Path; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + /// Unary operators #[allow(clippy::upper_case_acronyms)] #[derive(PartialEq)] @@ -281,8 +279,8 @@ fn eval_binary(s1: &str, op_str: &str, s2: &str) -> bool { fn main() -> Result<(), Box> { setlocale(LocaleCategory::LcAll, ""); - textdomain(PROJECT_NAME)?; - bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?; + textdomain(env!("PROJECT_NAME"))?; + bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?; let mut args: Vec = std::env::args().collect(); diff --git a/misc/tests/false/mod.rs b/misc/tests/false/mod.rs index e94d0f1ee..694ded2f3 100644 --- a/misc/tests/false/mod.rs +++ b/misc/tests/false/mod.rs @@ -7,7 +7,7 @@ // SPDX-License-Identifier: MIT // -use plib::{run_test, TestPlan}; +use plib::testing::{run_test, TestPlan}; fn truefalse_test(cmd: &str, expected_exit_code: i32) { run_test(TestPlan { diff --git a/misc/tests/test/mod.rs b/misc/tests/test/mod.rs index cf802d1d7..3006e1d28 100644 --- a/misc/tests/test/mod.rs +++ b/misc/tests/test/mod.rs @@ -8,7 +8,7 @@ // SPDX-License-Identifier: MIT // -use plib::{run_test, TestPlan}; +use plib::testing::{run_test, TestPlan}; fn test_test(args: &[&str], expected_code: i32) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/misc/tests/true/mod.rs b/misc/tests/true/mod.rs index 44ddabcd0..9d6972bb1 100644 --- a/misc/tests/true/mod.rs +++ b/misc/tests/true/mod.rs @@ -7,7 +7,7 @@ // SPDX-License-Identifier: MIT // -use plib::{run_test, TestPlan}; +use plib::testing::{run_test, TestPlan}; fn truefalse_test(cmd: &str, expected_exit_code: i32) { run_test(TestPlan {