Skip to content

Commit

Permalink
fix(ruby): ensure ruby-build bin exists before trying to use (#2913)
Browse files Browse the repository at this point in the history
Fixes #2817
  • Loading branch information
jdx authored Nov 4, 2024
1 parent 7dc1550 commit bf3c289
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
MISE_TRUSTED_CONFIG_PATHS: ${{ github.workspace }}
MISE_EXPERIMENTAL: 1
RUST_BACKTRACE: 1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.RTX_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
NPM_CONFIG_FUND: false

permissions:
Expand Down
8 changes: 8 additions & 0 deletions e2e/cli/test_current
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

mise i dummy@3 tiny@2
mise use dummy@3

assert "mise current" "dummy 3"
assert "mise current dummy" "3"
assert "mise current tiny" ""
6 changes: 6 additions & 0 deletions e2e/plugins/core/test_ruby_ls_remote
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# Install and build ruby using ruby-build

assert_contains "mise ls-remote ruby@3" "3.0.0"
assert_contains "mise ls-remote ruby@truffleruby-24" "truffleruby-24.0.0"
assert_contains "mise ls-remote ruby@truffleruby+graalvm-24" "truffleruby+graalvm-24.0.0"
37 changes: 0 additions & 37 deletions src/cli/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,40 +121,3 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
3.11.0 3.10.0
"#
);

#[cfg(test)]
mod tests {
use crate::test::reset;
use std::env;
use test_log::test;

#[test]
fn test_current() {
reset();
assert_cli_snapshot!("current", @r###"
tiny 3.1.0
dummy ref:master
"###);
}

#[test]
fn test_current_with_runtimes() {
reset();
assert_cli_snapshot!("current", "tiny", @"3.1.0");
}

#[test]
fn test_current_missing() {
reset();
assert_cli!("uninstall", "--all", "dummy");

env::set_var("MISE_DUMMY_VERSION", "1.1.0");
assert_cli_snapshot!("current", @r###"
dummy 1.1.0
tiny 3.1.0
mise dummy@1.1.0 is specified in MISE_DUMMY_VERSION=1.1.0, but not installed
"###);

env::remove_var("MISE_DUMMY_VERSION");
}
}
26 changes: 1 addition & 25 deletions src/plugins/core/ruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl RubyPlugin {
}
fn update_ruby_build(&self) -> Result<()> {
let _lock = self.lock_build_tool();
if self.ruby_build_path().exists() {
if self.ruby_build_bin().exists() {
let cur = self.ruby_build_version()?;
let latest = self.latest_ruby_build_version();
match (cur, latest) {
Expand Down Expand Up @@ -435,30 +435,6 @@ mod tests {
use indoc::indoc;
use pretty_assertions::assert_eq;

#[test]
fn test_list_versions_matching() {
reset();
let plugin = RubyPlugin::new();
assert!(
!plugin.list_versions_matching("3").unwrap().is_empty(),
"versions for 3 should not be empty"
);
assert!(
!plugin
.list_versions_matching("truffleruby-24")
.unwrap()
.is_empty(),
"versions for truffleruby-24 should not be empty"
);
assert!(
!plugin
.list_versions_matching("truffleruby+graalvm-24")
.unwrap()
.is_empty(),
"versions for truffleruby+graalvm-24 should not be empty"
);
}

#[test]
fn test_parse_gemfile() {
reset();
Expand Down
5 changes: 4 additions & 1 deletion src/versions_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::{backend, http, registry};
use url::Url;

pub fn list_versions(ba: &BackendArg) -> eyre::Result<Option<Vec<String>>> {
if !SETTINGS.use_versions_host || ba.short.contains(':') {
if !SETTINGS.use_versions_host
|| ba.short.contains(':')
|| !REGISTRY.contains_key(ba.short.as_str())
{
return Ok(None);
}
// ensure that we're using a default shorthand plugin
Expand Down

0 comments on commit bf3c289

Please sign in to comment.