mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Show +YJIT in version string and RUBY_DESCRIPTION
There might be code out there that expect `ruby -v` to print only one line. Since MJIT shows +JIT in `ruby -v` and RUBY_DESCRIPTION, let's show +YJIT. The crash report doesn't show anything about MJIT, so adjust the test. The "test_ruby_version" test was unaware of RUBY_YJIT_ENABLE and so was failing when the variable is set and inherited into the children processes it spawns. Explicitly unset the variable in the test.
This commit is contained in:
parent
13261f00fb
commit
efed45966b
4 changed files with 51 additions and 11 deletions
|
@ -8,6 +8,7 @@ class TestBugReporter < Test::Unit::TestCase
|
|||
|
||||
description = RUBY_DESCRIPTION
|
||||
description = description.sub(/\+JIT /, '') if defined?(RubyVM::JIT) && RubyVM::JIT.enabled?
|
||||
description = description.sub(/\+YJIT /, '') if defined?(YJIT.enabled?) && YJIT.enabled?
|
||||
expected_stderr = [
|
||||
:*,
|
||||
/\[BUG\]\sSegmentation\sfault.*\n/,
|
||||
|
|
|
@ -10,6 +10,8 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
NO_JIT_DESCRIPTION =
|
||||
if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # checking -DMJIT_FORCE_ENABLE
|
||||
RUBY_DESCRIPTION.sub(/\+JIT /, '')
|
||||
elsif defined?(YJIT.enabled?) && YJIT.enabled?
|
||||
RUBY_DESCRIPTION.sub(/\+YJIT /, '')
|
||||
else
|
||||
RUBY_DESCRIPTION
|
||||
end
|
||||
|
@ -140,10 +142,12 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
private_constant :VERSION_PATTERN_WITH_JIT
|
||||
|
||||
def test_verbose
|
||||
assert_in_out_err(["-vve", ""]) do |r, e|
|
||||
assert_in_out_err([{'RUBY_YJIT_ENABLE' => nil}, "-vve", ""]) do |r, e|
|
||||
assert_match(VERSION_PATTERN, r[0])
|
||||
if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? && !mjit_force_enabled? # checking -DMJIT_FORCE_ENABLE
|
||||
assert_equal(NO_JIT_DESCRIPTION, r[0])
|
||||
elsif defined?(YJIT.enabled?) && YJIT.enabled?
|
||||
assert_equal(NO_JIT_DESCRIPTION, r[0])
|
||||
else
|
||||
assert_equal(RUBY_DESCRIPTION, r[0])
|
||||
end
|
||||
|
@ -203,10 +207,13 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_version
|
||||
assert_in_out_err(%w(--version)) do |r, e|
|
||||
env = {'RUBY_YJIT_ENABLE' => nil} # unset in children
|
||||
assert_in_out_err([env, '--version']) do |r, e|
|
||||
assert_match(VERSION_PATTERN, r[0])
|
||||
if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # checking -DMJIT_FORCE_ENABLE
|
||||
assert_equal(EnvUtil.invoke_ruby(['-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
|
||||
elsif defined?(YJIT.enabled?) && YJIT.enabled?
|
||||
assert_equal(NO_JIT_DESCRIPTION, r[0])
|
||||
else
|
||||
assert_equal(RUBY_DESCRIPTION, r[0])
|
||||
end
|
||||
|
@ -220,7 +227,7 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
%w(--version --enable=jit --disable=jit),
|
||||
%w(--version --enable-jit --disable-jit),
|
||||
].each do |args|
|
||||
assert_in_out_err(args) do |r, e|
|
||||
assert_in_out_err([env] + args) do |r, e|
|
||||
assert_match(VERSION_PATTERN, r[0])
|
||||
assert_match(NO_JIT_DESCRIPTION, r[0])
|
||||
assert_equal([], e)
|
||||
|
@ -229,16 +236,16 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
|
||||
if JITSupport.supported?
|
||||
[
|
||||
%w(--version --disable-yjit --jit),
|
||||
%w(--version --disable-yjit --enable=jit),
|
||||
%w(--version --disable-yjit --enable-jit),
|
||||
%w(--version --jit),
|
||||
%w(--version --enable=jit),
|
||||
%w(--version --enable-jit),
|
||||
].each do |args|
|
||||
assert_in_out_err(args) do |r, e|
|
||||
assert_in_out_err([env] + args) do |r, e|
|
||||
assert_match(VERSION_PATTERN_WITH_JIT, r[0])
|
||||
if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # checking -DMJIT_FORCE_ENABLE
|
||||
assert_equal(RUBY_DESCRIPTION, r[0])
|
||||
else
|
||||
assert_equal(EnvUtil.invoke_ruby(['--disable-yjit', '--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
|
||||
assert_equal(EnvUtil.invoke_ruby([env, '--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
|
||||
end
|
||||
assert_equal([], e)
|
||||
end
|
||||
|
|
|
@ -8,6 +8,34 @@ return unless YJIT.enabled?
|
|||
# Tests for YJIT with assertions on compilation and side exits
|
||||
# insipired by the MJIT tests in test/ruby/test_jit.rb
|
||||
class TestYJIT < Test::Unit::TestCase
|
||||
def test_yjit_in_ruby_description
|
||||
assert_includes(RUBY_DESCRIPTION, '+YJIT')
|
||||
end
|
||||
|
||||
def test_yjit_in_version
|
||||
[
|
||||
%w(--version --yjit),
|
||||
%w(--version --disable-yjit --yjit),
|
||||
%w(--version --disable-yjit --enable-yjit),
|
||||
%w(--version --disable-yjit --enable=yjit),
|
||||
%w(--version --disable=yjit --yjit),
|
||||
%w(--version --disable=yjit --enable-yjit),
|
||||
%w(--version --disable=yjit --enable=yjit),
|
||||
].each do |version_args|
|
||||
assert_in_out_err(version_args) do |stdout, stderr|
|
||||
assert_equal([RUBY_DESCRIPTION], stdout)
|
||||
assert_equal([], stderr)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_enable_from_env_var
|
||||
yjit_child_env = {'RUBY_YJIT_ENABLE' => '1'}
|
||||
assert_in_out_err([yjit_child_env, '--version'], '', [RUBY_DESCRIPTION])
|
||||
assert_in_out_err([yjit_child_env, '-e puts RUBY_DESCRIPTION'], '', [RUBY_DESCRIPTION])
|
||||
assert_in_out_err([yjit_child_env, '-e p YJIT.enabled?'], '', ['true'])
|
||||
end
|
||||
|
||||
def test_compile_getclassvariable
|
||||
script = 'class Foo; @@foo = 1; def self.foo; @@foo; end; end; Foo.foo'
|
||||
assert_compiles(script, insns: %i[getclassvariable], result: 1)
|
||||
|
|
10
version.c
10
version.c
|
@ -43,6 +43,7 @@ const char ruby_platform[] = RUBY_PLATFORM;
|
|||
const int ruby_patchlevel = RUBY_PATCHLEVEL;
|
||||
const char ruby_description[] = RUBY_DESCRIPTION_WITH("");
|
||||
static const char ruby_description_with_jit[] = RUBY_DESCRIPTION_WITH(" +JIT");
|
||||
static const char ruby_description_with_yjit[] = RUBY_DESCRIPTION_WITH(" +YJIT");
|
||||
const char ruby_copyright[] = RUBY_COPYRIGHT;
|
||||
const char ruby_engine[] = "ruby";
|
||||
|
||||
|
@ -105,6 +106,9 @@ Init_ruby_description(void)
|
|||
if (MJIT_OPTS_ON) {
|
||||
description = MKSTR(description_with_jit);
|
||||
}
|
||||
else if (rb_yjit_enabled_p()) {
|
||||
description = MKSTR(description_with_yjit);
|
||||
}
|
||||
else {
|
||||
description = MKSTR(description);
|
||||
}
|
||||
|
@ -121,13 +125,13 @@ ruby_show_version(void)
|
|||
if (MJIT_OPTS_ON) {
|
||||
PRINT(description_with_jit);
|
||||
}
|
||||
else if (rb_yjit_enabled_p()) {
|
||||
PRINT(description_with_yjit);
|
||||
}
|
||||
else {
|
||||
PRINT(description);
|
||||
}
|
||||
|
||||
if (rb_yjit_enabled_p()) {
|
||||
fputs("YJIT is enabled\n", stdout);
|
||||
}
|
||||
#ifdef RUBY_LAST_COMMIT_TITLE
|
||||
fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue