Replace all hardcoded "1.1.0" version strings with env!("CARGO_PKG_VERSION")
in src/, so Cargo.toml is the sole source for the built binary. Tests
intentionally use a separate hardcoded constant in tests/common.rs to act
as a canary — they will fail on a version bump until manually updated.
- src/project/mod.rs: add WEEVIL_VERSION const, wire into Tera context,
generated README, and .weevil-version marker
- tests/common.rs: new file, holds EXPECTED_VERSION for all test crates
- tests/{integration,project_lifecycle,unit/config_tests}.rs: pull from
common instead of env! or inline literals
70 lines
2.1 KiB
Rust
70 lines
2.1 KiB
Rust
// File: tests/config_tests.rs
|
|
// Unit tests for project configuration
|
|
|
|
use weevil::project::ProjectConfig;
|
|
use std::path::PathBuf;
|
|
use tempfile::TempDir;
|
|
use std::fs;
|
|
|
|
#[path = "../common.rs"]
|
|
mod common;
|
|
use common::EXPECTED_VERSION;
|
|
|
|
#[test]
|
|
fn test_config_create_and_save() {
|
|
let temp_dir = TempDir::new().unwrap();
|
|
let sdk_path = PathBuf::from("/mock/sdk/path");
|
|
|
|
let config = ProjectConfig::new("test-robot", sdk_path.clone()).unwrap();
|
|
|
|
assert_eq!(config.project_name, "test-robot");
|
|
assert_eq!(config.ftc_sdk_path, sdk_path);
|
|
assert_eq!(config.weevil_version, EXPECTED_VERSION);
|
|
|
|
// Save and reload
|
|
config.save(temp_dir.path()).unwrap();
|
|
|
|
let loaded = ProjectConfig::load(temp_dir.path()).unwrap();
|
|
assert_eq!(loaded.project_name, config.project_name);
|
|
assert_eq!(loaded.ftc_sdk_path, config.ftc_sdk_path);
|
|
}
|
|
|
|
#[test]
|
|
fn test_config_load_missing_file() {
|
|
let temp_dir = TempDir::new().unwrap();
|
|
let result = ProjectConfig::load(temp_dir.path());
|
|
|
|
assert!(result.is_err());
|
|
assert!(result.unwrap_err().to_string().contains("missing .weevil.toml"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_config_toml_format() {
|
|
let temp_dir = TempDir::new().unwrap();
|
|
let sdk_path = PathBuf::from("/test/sdk");
|
|
|
|
let config = ProjectConfig::new("my-robot", sdk_path).unwrap();
|
|
config.save(temp_dir.path()).unwrap();
|
|
|
|
let content = fs::read_to_string(temp_dir.path().join(".weevil.toml")).unwrap();
|
|
|
|
assert!(content.contains("project_name = \"my-robot\""));
|
|
assert!(content.contains(&format!("weevil_version = \"{}\"", EXPECTED_VERSION)));
|
|
assert!(content.contains("ftc_sdk_path"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_config_update_sdk_path() {
|
|
let temp_dir = TempDir::new().unwrap();
|
|
let old_sdk = PathBuf::from("/old/sdk");
|
|
let new_sdk = PathBuf::from("/new/sdk");
|
|
|
|
let mut config = ProjectConfig::new("test", old_sdk).unwrap();
|
|
|
|
// Note: This will fail in tests because SDK doesn't exist
|
|
// In real usage, the SDK path is validated
|
|
// For now, just test the struct update
|
|
config.ftc_sdk_path = new_sdk.clone();
|
|
|
|
assert_eq!(config.ftc_sdk_path, new_sdk);
|
|
} |