zshrs 0.11.18

The first compiled Unix shell — bytecode VM, worker pool, AOP intercept, Rkyv caching
Documentation
//! `patchlevel.h` port — upstream zsh patch-level identifier.
//!
//! Port of `Src/patchlevel.h`. The C header defines a single
//! preprocessor constant `ZSH_PATCHLEVEL` that names the upstream
//! source revision the rest of the tree was built from. It's read
//! by `init.c` to populate the `$ZSH_PATCHLEVEL` shell parameter
//! and by the `zsh --version` startup-banner code.
//!
//! C source: 1 `#define`, 0 structs/enums/ported.

/// Port of `#define ZSH_PATCHLEVEL` from `Src/patchlevel.h:1`.
///
/// The upstream source-revision tag the C tree was generated from.
/// Format follows the convention `zsh-MAJOR.MINOR.PATCH-test-N-gHASH`
/// (where the trailing `-N-gHASH` is appended by `git describe`
/// during the upstream release process).
///
/// zshrs reads this constant verbatim from the upstream snapshot in
/// `src/zsh/Src/patchlevel.h` so the `$ZSH_PATCHLEVEL` shell
/// parameter (params.rs:1690) reports the same value zsh would on
/// the same source tree.
pub const ZSH_PATCHLEVEL: &str = "zsh-5.9-465-g6b9704e"; // c:1

/// Port of `#define ZSH_VERSION` (generated by `Src/Makemod:544`).
///
/// C body: `echo '#define ZSH_VERSION "'$(VERSION)'"' > $@`
/// — the build glue writes `VERSION` from `Config/version.mk` into
/// a generated header that init.c reads. zshrs holds the same value
/// as a Rust `const` since the build is cargo-driven, not make-driven.
/// Read by `params.rs::createparamtable` (c:966 — `setsparam("ZSH_VERSION", ZSH_VERSION)`)
/// and by the `--version` startup banner.
pub const ZSH_VERSION: &str = "5.9.0.3-test"; // Config/version.mk:VERSION

#[cfg(test)]
mod tests {
    use super::*;

    /// `$ZSH_PATCHLEVEL` is read at params.rs:1690 — pin both the
    /// snapshot value and its `zsh-MAJOR.MINOR-N-gHASH` shape. If
    /// upstream tags drop the `-g<hash>` suffix this fails — that's
    /// the git-describe contract zsh's version-reporting code relies
    /// on.
    #[test]
    fn patchlevel_value_and_git_describe_shape() {
        let _g = crate::test_util::global_state_lock();
        assert_eq!(ZSH_PATCHLEVEL, "zsh-5.9-465-g6b9704e");
        assert!(
            ZSH_PATCHLEVEL.contains("-g"),
            "git-describe `-g<hash>` suffix is load-bearing"
        );
    }

    /// `$ZSH_VERSION` is read at params.rs `createparamtable` (c:966)
    /// and by the `--version` startup banner (Src/init.c:436). Pin
    /// the upstream Config/version.mk VERSION value so version-aware
    /// scripts (e.g. `[[ $ZSH_VERSION = 5.9.* ]]`) keep working when
    /// the snapshot rolls forward.
    #[test]
    fn zsh_version_matches_upstream_config_version() {
        let _g = crate::test_util::global_state_lock();
        assert_eq!(ZSH_VERSION, "5.9.0.3-test");
        // Shape: MAJOR.MINOR[.PATCH[.SUB][-tag]]
        let major = ZSH_VERSION.split('.').next().unwrap_or("");
        assert!(
            major.chars().all(|c| c.is_ascii_digit()) && !major.is_empty(),
            "ZSH_VERSION must start with numeric MAJOR (got {ZSH_VERSION:?})"
        );
    }

    // ─── zsh-corpus pins for version constants ──────────────────────

    /// `ZSH_PATCHLEVEL` is non-empty.
    #[test]
    fn patchlevel_corpus_nonempty() {
        assert!(!ZSH_PATCHLEVEL.is_empty());
    }

    /// `ZSH_PATCHLEVEL` starts with "zsh-" prefix.
    #[test]
    fn patchlevel_corpus_zsh_prefix() {
        assert!(ZSH_PATCHLEVEL.starts_with("zsh-"),
            "patchlevel must start with `zsh-`, got {ZSH_PATCHLEVEL:?}");
    }

    /// `ZSH_VERSION` follows MAJOR.MINOR format with at least one dot.
    #[test]
    fn patchlevel_corpus_version_has_dot() {
        assert!(ZSH_VERSION.contains('.'),
            "ZSH_VERSION must contain a dot (MAJOR.MINOR), got {ZSH_VERSION:?}");
    }

    /// `ZSH_VERSION` MAJOR is "5" (current zsh series).
    #[test]
    fn patchlevel_corpus_version_major_is_five() {
        let major = ZSH_VERSION.split('.').next().unwrap();
        assert_eq!(major, "5", "current zsh is in the 5.x series");
    }

    /// `ZSH_VERSION` MINOR is parseable as integer.
    #[test]
    fn patchlevel_corpus_version_minor_parses() {
        let parts: Vec<&str> = ZSH_VERSION.split('.').collect();
        assert!(parts.len() >= 2, "must have MAJOR.MINOR");
        let minor: Result<i32, _> = parts[1].parse();
        assert!(minor.is_ok(), "MINOR must parse: {parts:?}");
    }

    /// Constants are distinct (patchlevel != version since patchlevel
    /// has the `-N-gHASH` tail).
    #[test]
    fn patchlevel_corpus_patchlevel_differs_from_version() {
        assert_ne!(ZSH_PATCHLEVEL, ZSH_VERSION);
    }
}