17 lines
957 B
Markdown
17 lines
957 B
Markdown
# 03 — Programowanie Cross-Platform (Linux, Windows, macOS)
|
|
|
|
## Zakres
|
|
* Abstrakcje ścieżek `Path` i `PathBuf` (nigdy nie sklejaj ścieżek przez `format!("{}/{}", ...)`!)
|
|
* Kompilacja warunkowa: `#[cfg(target_os = "linux")]`, `#[cfg(target_os = "macos")]`, `#[cfg(target_os = "windows")]`
|
|
* Bezpieczna obsługa zmiennych środowiskowych (wstrzykiwanie źródła zamiast globalnego stanu w testach)
|
|
|
|
## Zadania (`src/lib.rs`)
|
|
1. `config_file_path(base_dir: &Path, app_name: &str) -> PathBuf` — zbuduj przenośną ścieżkę `<base_dir>/<app_name>/config.toml` używając `Path::join`.
|
|
2. `current_os_label() -> &'static str` — użyj `#[cfg(target_os = "...")]`, aby zwrócić `"linux"`, `"macos"`, `"windows"` lub `"other"`.
|
|
3. `has_extension(path: &Path, expected: &str) -> bool` — porównaj rozszerzenie pliku bez uwzględniania wielkości liter (ważne na Windows/macOS).
|
|
|
|
## Uruchomienie testów
|
|
```bash
|
|
make test PKG=eng03-cross-platform
|
|
```
|