Skip to content

Commit af6e4d2

Browse files
authored
Merge pull request #330 from fox0/env
display: Use compile-time macro env!
2 parents a452351 + fff07b1 commit af6e4d2

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[env]
2+
PROJECT_NAME = "posixutils-rs"

display/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ edition.workspace = true
88
rust-version.workspace = true
99

1010
[dependencies]
11-
plib = { path = "../plib" }
1211
clap.workspace = true
1312
gettext-rs.workspace = true
1413

14+
[dev-dependencies]
15+
plib = { path = "../plib" }
16+
1517
[lints]
1618
workspace = true
1719

@@ -22,4 +24,3 @@ path = "./echo.rs"
2224
[[bin]]
2325
name = "printf"
2426
path = "./printf.rs"
25-

display/echo.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//
1515

1616
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
17-
use plib::PROJECT_NAME;
1817
use std::io::{self, Write};
1918

2019
fn translate_str(skip_nl: bool, s: &str) -> String {
@@ -73,8 +72,8 @@ fn translate_str(skip_nl: bool, s: &str) -> String {
7372

7473
fn main() -> Result<(), Box<dyn std::error::Error>> {
7574
setlocale(LocaleCategory::LcAll, "");
76-
textdomain(PROJECT_NAME)?;
77-
bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?;
75+
textdomain(env!("PROJECT_NAME"))?;
76+
bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?;
7877

7978
let mut args: Vec<String> = std::env::args().collect();
8079
args.remove(0);

display/printf.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//
1313

1414
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
15-
use plib::PROJECT_NAME;
1615
use std::io::{self, Write};
1716

1817
// the following structure is a printf format conversion specifier
@@ -322,8 +321,8 @@ fn do_printf(format: &str, args: &[String]) -> io::Result<()> {
322321

323322
fn main() -> Result<(), Box<dyn std::error::Error>> {
324323
setlocale(LocaleCategory::LcAll, "");
325-
textdomain(PROJECT_NAME)?;
326-
bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?;
324+
textdomain(env!("PROJECT_NAME"))?;
325+
bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?;
327326

328327
let args: Vec<String> = std::env::args().collect();
329328

display/tests/echo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// SPDX-License-Identifier: MIT
88
//
99

10-
use plib::{run_test, TestPlan};
10+
use plib::testing::{run_test, TestPlan};
1111

1212
fn echo_test(args: &[&str], expected_output: &str) {
1313
let str_args: Vec<String> = args.iter().map(|s| String::from(*s)).collect();

display/tests/printf/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// SPDX-License-Identifier: MIT
88
//
99

10-
use plib::{run_test, TestPlan};
10+
use plib::testing::{run_test, TestPlan};
1111

1212
#[test]
1313
fn test_basic_string_output() {

0 commit comments

Comments
 (0)