use std::path::PathBuf;
#[allow(unused_variables)]
pub fn setup_(m: *const crate::ported::zsh_h::module) -> i32 { 0 }
#[allow(unused_variables)]
pub fn features_(m: *const crate::ported::zsh_h::module, features: &mut Vec<String>) -> i32 { 1 }
#[allow(unused_variables)]
pub fn enables_(m: *const crate::ported::zsh_h::module, enables: &mut Option<Vec<i32>>) -> i32 { 0 }
pub fn check_dotfile(dotdir: &str, fname: &str) -> i32 { let mut p = PathBuf::from(dotdir); p.push(fname); if p.exists() { 0 } else { -1 } }
#[allow(unused_variables)]
pub fn boot_(m: *const crate::ported::zsh_h::module) -> i32 { let mut dotdir: String = crate::ported::params::getsparam("ZDOTDIR")
.unwrap_or_default();
let spaths: Vec<String> = std::env::var("ZSH_SITESCRIPT_DIR").ok()
.into_iter()
.chain(std::env::var("ZSH_SCRIPT_DIR").ok())
.chain(std::iter::once("/etc/zsh".to_string()))
.collect();
if !crate::ported::zsh_h::EMULATION(crate::ported::zsh_h::EMULATE_ZSH) {
return 0; }
if dotdir.is_empty() {
dotdir = crate::ported::params::getsparam("HOME") .unwrap_or_default();
if dotdir.is_empty() {
return 0; }
}
if check_dotfile(&dotdir, ".zshenv") == 0 || check_dotfile(&dotdir, ".zprofile") == 0 || check_dotfile(&dotdir, ".zshrc") == 0 || check_dotfile(&dotdir, ".zlogin") == 0 { return 0; }
for sp in &spaths { let buf = format!("{}/newuser", sp); if crate::ported::init::source(&buf) != SOURCE_NOT_FOUND { break; }
}
0 }
#[allow(unused_variables)]
pub fn cleanup_(m: *const crate::ported::zsh_h::module) -> i32 { 0 }
#[allow(unused_variables)]
pub fn finish_(m: *const crate::ported::zsh_h::module) -> i32 { 0 }
const SOURCE_NOT_FOUND: i32 = 1;
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
#[test]
fn check_dotfile_returns_zero_when_file_exists() {
let tmp = std::env::temp_dir();
let p = tmp.join("zshrs_test_dotfile_exists");
fs::write(&p, "").expect("write tmp");
assert_eq!(check_dotfile(tmp.to_str().unwrap(), "zshrs_test_dotfile_exists"), 0);
let _ = fs::remove_file(&p);
}
#[test]
fn check_dotfile_returns_minus_one_when_missing() {
let tmp = std::env::temp_dir();
assert_eq!(check_dotfile(tmp.to_str().unwrap(), "zshrs_test_definitely_nothere_xyz"), -1);
}
#[test]
fn module_entry_points_return_zero() {
assert_eq!(setup_(std::ptr::null()), 0);
assert_eq!(cleanup_(std::ptr::null()), 0);
assert_eq!(finish_(std::ptr::null()), 0);
}
}