Class: Mrubyc::Test::Tool

Inherits:
Thor
  • Object
show all
Defined in:
lib/mrubyc-test.rb

Instance Method Summary collapse

Instance Method Details

#help(arg = nil) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/mrubyc-test.rb', line 150

def help(arg = nil)
  super(arg)
  init_env
  if arg == "test"
    puts
    puts "Default environment variables you can change:"
    puts "  CFLAGS='#{ENV['CFLAGS']}'"
    puts "  LDFLAGS='#{ENV['LDFLAGS']}'"
    puts
  end
  exit if arg
  puts "\e[33m  Note:"
  puts '  It is recommended to use mrubyc-utils as a wrapper of this gem'
  puts '  see https://github.com/hasumikin/mrubyc-utils#wrapper-of-gem-mrubyc-test-and-mrubyc-debugger'
  puts "\e[0m"
end

#initObject



20
21
22
# File 'lib/mrubyc-test.rb', line 20

def init
  Mrubyc::Test::Init.run
end

#test(testfilepath = "") ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/mrubyc-test.rb', line 113

def test(testfilepath = "")
  Mrubyc::Test::Init.init_main_c
  init_env
  config = Mrubyc::Test::Config.read
  method_name_pattern = (%r{\A/(.*)/\Z} =~ options[:name] ? Regexp.new($1) : options[:name])
  test_path = if testfilepath == ""
    File.join(Dir.pwd, config['test_dir'], "*.rb")
  else
    File.join(Dir.pwd, testfilepath)
  end
  mrbc_path = options[:mrbc_path] || config['mrbc_path']
  unless mrbc_path
    mruby_version = File.read('.ruby-version').gsub("\n", '').chomp
    unless mruby_version.index('mruby')
      puts '.ruby-version doesn\'t set `mruby-x.x.x It is recommended to use the latest version of https://github.com/hasumikin/mrubyc-utils`'
      print 'You can specify the version name of mruby [mruby-x.x.x]: '
      mruby_version = STDIN.gets.chomp
    end
    "RBENV_VERSION=#{mruby_version} mrbc"
  end
  exit_code = 0
  Dir.glob(test_path).each_slice(options[:every]) do |test_files|
    prepare(test_files, options[:verbose], method_name_pattern)
    exit_code += make(mrbc_path)
  end
  if exit_code > 0
    puts "\e[31mFinished with error(s)\e[0m"
    exit 1
  end
  puts "\e[32mFinished without error\e[0m"
end

#versionObject



146
147
148
# File 'lib/mrubyc-test.rb', line 146

def version
  puts "mrubyc-test v#{Mrubyc::Test::VERSION}"
end