@@ -34,21 +34,26 @@ def setup_mock_ruby(path)
3434
3535 describe '#parse' do
3636 it 'returns default values when no arguments provided' do
37- parser = ArgumentParser . new
38- args = parser . parse ( [ ] )
39-
40- assert_equal ( { } , args . executables )
41- assert_equal File . expand_path ( "./data" ) , args . out_path
42- assert_nil args . out_override
43- assert_equal "harness" , args . harness
44- assert_equal "" , args . yjit_opts
45- assert_equal [ ] , args . categories
46- assert_equal [ ] , args . name_filters
47- assert_equal false , args . rss
48- assert_equal false , args . graph
49- assert_equal false , args . no_pinning
50- assert_equal false , args . turbo
51- assert_equal false , args . skip_yjit
37+ mock_ruby = '/usr/bin/ruby'
38+ parser = ArgumentParser . new ( ruby_executable : mock_ruby )
39+
40+ # Stub to return false so we get a single 'ruby' executable
41+ parser . stub :have_yjit? , false do
42+ args = parser . parse ( [ ] )
43+
44+ assert_equal ( { 'ruby' => [ mock_ruby ] } , args . executables )
45+ assert_equal File . expand_path ( "./data" ) , args . out_path
46+ assert_nil args . out_override
47+ assert_equal "harness" , args . harness
48+ assert_equal "" , args . yjit_opts
49+ assert_equal [ ] , args . categories
50+ assert_equal [ ] , args . name_filters
51+ assert_equal false , args . rss
52+ assert_equal false , args . graph
53+ assert_equal false , args . no_pinning
54+ assert_equal false , args . turbo
55+ assert_equal false , args . skip_yjit
56+ end
5257 end
5358
5459 describe '-e option' do
@@ -502,5 +507,95 @@ def setup_mock_ruby(path)
502507 assert_equal true , args . rss
503508 end
504509 end
510+
511+ describe 'default executables' do
512+ it 'sets ruby executable when no -e option and no YJIT' do
513+ mock_ruby = '/usr/bin/ruby'
514+
515+ parser = ArgumentParser . new ( ruby_executable : mock_ruby )
516+
517+ parser . stub :have_yjit? , false do
518+ args = parser . parse ( [ ] )
519+
520+ assert_equal 1 , args . executables . size
521+ assert_equal [ mock_ruby ] , args . executables [ 'ruby' ]
522+ end
523+ end
524+
525+ it 'sets interp and yjit executables when no -e option and YJIT available' do
526+ mock_ruby = '/usr/bin/ruby'
527+
528+ parser = ArgumentParser . new ( ruby_executable : mock_ruby )
529+
530+ parser . stub :have_yjit? , true do
531+ args = parser . parse ( [ ] )
532+
533+ assert_equal 2 , args . executables . size
534+ assert_equal [ mock_ruby ] , args . executables [ 'interp' ]
535+ assert_equal [ mock_ruby , '--yjit' ] , args . executables [ 'yjit' ]
536+ end
537+ end
538+
539+ it 'includes yjit_opts in default yjit executable' do
540+ mock_ruby = '/usr/bin/ruby'
541+
542+ parser = ArgumentParser . new ( ruby_executable : mock_ruby )
543+
544+ parser . stub :have_yjit? , true do
545+ args = parser . parse ( [ '--yjit_opts=--yjit-call-threshold=10' ] )
546+
547+ assert_equal 2 , args . executables . size
548+ assert_equal [ mock_ruby ] , args . executables [ 'interp' ]
549+ assert_equal [ mock_ruby , '--yjit' , '--yjit-call-threshold=10' ] , args . executables [ 'yjit' ]
550+ end
551+ end
552+
553+ it 'respects --skip-yjit flag when YJIT is available' do
554+ mock_ruby = '/usr/bin/ruby'
555+
556+ parser = ArgumentParser . new ( ruby_executable : mock_ruby )
557+
558+ parser . stub :have_yjit? , true do
559+ args = parser . parse ( [ '--skip-yjit' ] )
560+
561+ assert_equal 1 , args . executables . size
562+ assert_equal [ mock_ruby ] , args . executables [ 'ruby' ]
563+ end
564+ end
565+
566+ it 'does not set default executables when -e option is provided' do
567+ mock_ruby = '/usr/bin/ruby'
568+
569+ parser = ArgumentParser . new ( ruby_executable : mock_ruby )
570+
571+ parser . stub :have_yjit? , true do
572+ args = parser . parse ( [ '-e' , 'custom::custom-ruby' ] )
573+
574+ assert_equal 1 , args . executables . size
575+ assert_equal [ 'custom-ruby' ] , args . executables [ 'custom' ]
576+ end
577+ end
578+
579+ it 'does not set default executables when --chruby option is provided' do
580+ Dir . mktmpdir do |tmpdir |
581+ @temp_home = tmpdir
582+ rubies_dir = File . join ( tmpdir , '.rubies' )
583+ ruby_path = File . join ( rubies_dir , '3.2.0/bin/ruby' )
584+ setup_mock_ruby ( ruby_path )
585+
586+ ENV [ 'HOME' ] = tmpdir
587+ mock_ruby = '/usr/bin/ruby'
588+
589+ parser = ArgumentParser . new ( ruby_executable : mock_ruby )
590+
591+ parser . stub :have_yjit? , true do
592+ args = parser . parse ( [ '--chruby=test::3.2.0' ] )
593+
594+ assert_equal 1 , args . executables . size
595+ assert_equal ruby_path , args . executables [ 'test' ] . first
596+ end
597+ end
598+ end
599+ end
505600 end
506601end
0 commit comments