蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

离线校验 Windows RubyInstaller 向导选项、Path/PATHEXT 拼接与 ruby -v 解析

PYTHONWindows x64、CPython 3.12.14 离线 Ruby 3.x 语义验证器(本机未安装原生 MRI Ruby 解释器)。explore-installation-windows.py
explore-installation-windows.py100 行
"""Offline Ruby 3.x semantic verification lab for Chapter 05 (installation-windows)."""
import json
import re

VERSION = "CPython 3.12.14 offline Ruby 3.x semantic verifier (MRI ruby absent)"


def case_windows_rubyinstaller_download_and_wizard():
    urls = {
        "official": "https://rubyinstaller.org/downloads/",
        "cn_mirror": "https://rubyinstaller.cn/",
    }
    wizard_options = {"add_to_path": True, "associate_rb_rbw": True, "install_msys2_devkit": True}
    expected = {"has_official": True, "has_cn_mirror": True, "path_checked": True}
    actual = {
        "has_official": "rubyinstaller.org" in urls["official"],
        "has_cn_mirror": "rubyinstaller.cn" in urls["cn_mirror"],
        "path_checked": wizard_options["add_to_path"],
    }
    return {
        "name": "windows_rubyinstaller_download_and_wizard",
        "summary": "核对 Windows RubyInstaller 下载渠道及向导中勾选 Add Ruby executables to your PATH 的关键选项",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_windows_path_and_pathext_configuration():
    path_entries = [r"C:\Windows\System32", r"C:\Windows"]
    ruby_bin = r"C:\Ruby33-x64\bin"
    if ruby_bin not in path_entries:
        path_entries.append(ruby_bin)
    pathext = [".COM", ".EXE", ".BAT", ".CMD"]
    for ext in (".RB", ".RBW"):
        if ext not in pathext:
            pathext.append(ext)
    expected = {
        "path_str": r"C:\Windows\System32;C:\Windows;C:\Ruby33-x64\bin",
        "pathext_has_rb": True,
        "pathext_has_rbw": True,
    }
    actual = {
        "path_str": ";".join(path_entries),
        "pathext_has_rb": ".RB" in pathext,
        "pathext_has_rbw": ".RBW" in pathext,
    }
    return {
        "name": "windows_path_and_pathext_configuration",
        "summary": "验证 Windows 环境变量 Path 追加 bin 目录及 PATHEXT 追加 .RB 与 .RBW 的分号拼接格式",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_legacy_win9x_vs_nt_env_config():
    win9x_line = r'set PATH="D:\Ruby\bin;%PATH%"'
    nt_flow = ["控制面板/系统属性", "环境变量", "编辑系统变量 Path", "编辑系统变量 PATHEXT"]
    expected = {"win9x_uses_autoexec": True, "nt_steps": 4}
    actual = {"win9x_uses_autoexec": win9x_line.startswith("set PATH="), "nt_steps": len(nt_flow)}
    return {
        "name": "legacy_win9x_vs_nt_env_config",
        "summary": "区分历史 Windows 9x(autoexec.bat)与 Windows NT/现代 Windows 系统环境变量配置流程",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_windows_cli_version_verification():
    samples = [
        "ruby 2.2.3p173 (2015-08-18 revision 51636) [x64-mingw32]",
        "ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x64-mingw-ucrt]",
    ]
    parsed = [re.match(r"^ruby\s+(\d+\.\d+\.\d+)", s).group(1) for s in samples]
    expected = {"parsed_versions": ["2.2.3", "3.3.6"], "all_valid": True}
    actual = {"parsed_versions": parsed, "all_valid": len(parsed) == 2}
    return {
        "name": "windows_cli_version_verification",
        "summary": "校验 ruby -v 输出格式解析,对照历史 2.2.3 与现代 3.3.x UCRT 工具链版本标识",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = [
        case_windows_rubyinstaller_download_and_wizard(),
        case_windows_path_and_pathext_configuration(),
        case_legacy_win9x_vs_nt_env_config(),
        case_windows_cli_version_verification(),
    ]
    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14 离线 Ruby 3.x 语义验证器(本机未安装原生 MRI Ruby 解释器)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14 离线 Ruby 3.x 语义验证器(本机未安装原生 MRI Ruby 解释器)。

入口文件:projects/ruby-installation-windows-lab/explore-installation-windows.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-installation-windows.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14 离线 Ruby 3.x 语义验证器(本机未安装原生 MRI Ruby 解释器)。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Ruby

课程关联工程包(登记关联45章) · 含当前章节或实例 · mbskycom202612a2434.zip

下载课程关联工程包:Ruby

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2457.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习