Skip to content

Migrate Rust installation to bash with comprehensive testing#23

Merged
ooloth merged 7 commits intomainfrom
feature/rust-installation
Jul 11, 2025
Merged

Migrate Rust installation to bash with comprehensive testing#23
ooloth merged 7 commits intomainfrom
feature/rust-installation

Conversation

@ooloth
Copy link
Owner

@ooloth ooloth commented Jul 11, 2025

💪 What

  • Files Created:
    • lib/rust-utils.bash - Rust utility functions (3 functions, 4 tests)
    • bin/install/rust.bash - Bash replacement for rust.zsh
    • test/install/test-rust-utils.bats - 4 utility function tests
    • test/install/test-rust-installation.bats - 3 integration tests
  • Test Coverage: 7 comprehensive tests covering all functionality
  • Quality: 7/7 tests passing, zero shellcheck warnings

🤔 Why

  • Bash Migration: Continues migration from custom zsh to industry-standard bash + shellcheck + bats
  • Professional Tooling: Enables shellcheck linting and bats testing for Rust installation
  • Shared Utilities: Extracts reusable Rust logic for future use in update scripts
  • Better Error Handling: Uses bash strict mode and structured error handling

👀 Usage

Run Rust installation:

./bin/install/rust.bash

Features:

  • Detects existing Rust installation (skips if present)
  • Sets custom CARGO_HOME and RUSTUP_HOME paths
  • Downloads and runs rustup installer
  • Uses proper security flags for curl download

👩‍🔬 How to validate

Run utility tests:

bats test/install/test-rust-utils.bats

Run integration tests:

bats test/install/test-rust-installation.bats

Expected output (7 tests total):

# Utility tests
1..4
ok 1 rust_installed returns false when rustup not found
ok 2 rust_installed returns true when rustup is found
ok 3 setup_rust_environment sets CARGO_HOME and RUSTUP_HOME
ok 4 install_rust_toolchain uses curl to download rustup installer

# Integration tests
1..3
ok 1 rust.bash exists and is executable
ok 2 rust.bash skips installation when rust is already installed
ok 3 rust.bash installs rust when not present

Verify shellcheck compliance:

shellcheck lib/rust-utils.bash bin/install/rust.bash

Test manually:

# Test with existing rust (if you have it)
./bin/install/rust.bash  # Should skip

# Test in clean environment
export PATH="/usr/bin:/bin"  # Remove rust from PATH
./bin/install/rust.bash     # Should install

Architecture

Three-Tier Pattern:

  1. Core Utilities (lib/rust-utils.bash): Pure logic, shellcheck compliant, fully tested
  2. Installation Script (bin/install/rust.bash): Orchestrates utilities, professional tooling
  3. Future Interactive Tools: Will use shared utilities for rich user experience

Functions Provided:

  • rust_installed() - Detects rustup command availability
  • setup_rust_environment() - Sets CARGO_HOME and RUSTUP_HOME
  • install_rust_toolchain() - Downloads and runs rustup installer

🔗 Related links

Implementation Details

TDD Approach:

  • 7 test cases following strict TDD: red → green → refactor → commit
  • Comprehensive mocking for isolated testing
  • Both unit tests (utilities) and integration tests (full script)
  • Behavioral testing focus - tests what code does, not how

Key Features:

  • Detection Logic: Uses command -v rustup for reliable detection
  • Custom Paths: Sets .config/cargo and .config/rustup instead of defaults
  • Security: Uses proper TLS and protocol restrictions for curl
  • Error Handling: Strict mode + graceful failure handling
  • Modularity: Shared utilities enable code reuse

Migration Benefits:

  • Better Development Tools: shellcheck + bats instead of custom zsh framework
  • Industry Standards: Follows bash best practices and conventions
  • Easier Maintenance: Standard testing and linting tools
  • Code Sharing: Utilities can be reused in update scripts

@ooloth ooloth marked this pull request as ready for review July 11, 2025 23:55
@ooloth ooloth merged commit c078460 into main Jul 11, 2025
1 check passed
@ooloth ooloth deleted the feature/rust-installation branch July 11, 2025 23:57
ooloth added a commit that referenced this pull request Jul 12, 2025
Updates the bash migration plan to clearly explain the parallel
development approach:

- Building setup.bash system alongside existing setup.zsh (not replacing)
- Both systems can coexist indefinitely until cutover decision
- Zero disruption to existing workflows during development
- Clear boundaries between bash infrastructure and zsh user experience

Also updated status to reflect recent merged PRs:
- PR #22: setup.bash entry point
- PR #23: Rust installation migration
- PR #24: Node.js installation migration
- PR #25: Neovim installation migration (in review)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant