Class: Mesa

Inherits:
Object
  • Object
show all
Defined in:
lib/mesa_test.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mesa_dir: ) ⇒ Mesa

Returns a new instance of Mesa.



344
345
346
347
348
349
350
351
352
353
354
# File 'lib/mesa_test.rb', line 344

def initialize(mesa_dir: ENV['MESA_DIR'])
  @mesa_dir = mesa_dir

  # these get populated by calling #load_test_data
  @test_data = {}
  @test_names = {}
  @test_cases = {}

  # way to output colored text
  @shell = Thor::Shell::Color.new
end

Instance Attribute Details

#mesa_dirObject (readonly)

Returns the value of attribute mesa_dir.



331
332
333
# File 'lib/mesa_test.rb', line 331

def mesa_dir
  @mesa_dir
end

#shellObject (readonly)

Returns the value of attribute shell.



331
332
333
# File 'lib/mesa_test.rb', line 331

def shell
  @shell
end

#test_casesObject (readonly)

Returns the value of attribute test_cases.



331
332
333
# File 'lib/mesa_test.rb', line 331

def test_cases
  @test_cases
end

#test_dataObject (readonly)

Returns the value of attribute test_data.



331
332
333
# File 'lib/mesa_test.rb', line 331

def test_data
  @test_data
end

#test_namesObject (readonly)

Returns the value of attribute test_names.



331
332
333
# File 'lib/mesa_test.rb', line 331

def test_names
  @test_names
end

Class Method Details

.download(version_number: nil, new_mesa_dir: nil) ⇒ Object



333
334
335
336
337
338
339
340
341
342
# File 'lib/mesa_test.rb', line 333

def self.download(version_number: nil, new_mesa_dir: nil)
  new_mesa_dir ||= File.join(ENV['HOME'], 'mesa-test-r' + version_number.to_s)
  success = system("svn co -r #{version_number} "+
                   "svn://svn.code.sf.net/p/mesa/code/trunk #{new_mesa_dir}")
  unless success
    raise MesaDirError, "Encountered a problem in download mesa " +
                        "revision #{version_number}."
  end
  Mesa.new(mesa_dir: new_mesa_dir)
end

Instance Method Details

#check_mod(mod) ⇒ Object

TEST SUITE METHODS

Raises:



395
396
397
398
399
# File 'lib/mesa_test.rb', line 395

def check_mod(mod)
  return if MesaTestCase.modules.include? mod
  raise TestCaseDirError, "Invalid module: #{mod}. Must be one of: " +
    MesaTestCase.modules.join(', ')
end

#cleanObject



365
366
367
368
369
370
371
372
373
374
375
# File 'lib/mesa_test.rb', line 365

def clean
  with_MESA_DIR do
    visit_and_check mesa_dir, MesaDirError, "Encountered a problem in " +
                              "running `clean` in #{mesa_dir}." do
      puts 'MESA_DIR = ' + ENV['MESA_DIR']
      puts './clean'
      system('./clean')
    end
  end
  self
end

#destroyObject



389
390
391
# File 'lib/mesa_test.rb', line 389

def destroy
  FileUtils.rm_rf mesa_dir
end

#each_test_clean(mod: :all) ⇒ Object

based off of ‘$MESA_DIR/star/test_suite/each_test_run_and_diff` from revision 10000



473
474
475
476
477
478
479
480
481
482
# File 'lib/mesa_test.rb', line 473

def each_test_clean(mod: :all)
  if mod == :all
    MesaTestCase.modules.each { |this_mod| each_test_clean mod: this_mod }
  else
    check_mod mod
    test_names[mod].each do |test_name|
      test_cases[mod][test_name].clean
    end
  end
end

#each_test_load_results(mod: :all) ⇒ Object



500
501
502
503
504
505
506
507
508
509
510
# File 'lib/mesa_test.rb', line 500

def each_test_load_results(mod: :all)
  if mod == :all
    MesaTestCase.modules.each do |this_mod|
      each_test_load_results(mod: this_mod)
    end
  else
    test_names[mod].each do |test_name|
      test_cases[mod][test_name].load_results
    end
  end
end

#each_test_run_and_diff(mod: :all, log_results: false) ⇒ Object



484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/mesa_test.rb', line 484

def each_test_run_and_diff(mod: :all, log_results: false)
  each_test_clean(mod: mod)

  if mod == :all
    MesaTestCase.modules.each do |this_mod|
      each_test_run_and_diff(mod: this_mod, log_results: log_results)
    end
  else
    test_names[mod].each do |test_name|
      test_cases[mod][test_name].do_one
      test_cases[mod][test_name].log_results if log_results
    end
    log_summary if log_results
  end
end

#find_test_case(test_case_name: nil, mod: :all) ⇒ Object

can accept a number (in string form) as a name for indexed access



463
464
465
466
467
468
469
# File 'lib/mesa_test.rb', line 463

def find_test_case(test_case_name: nil, mod: :all)
  if /\A[0-9]+\z/ =~ test_case_name
    find_test_case_by_number(test_number: test_case_name.to_i, mod: mod)
  else
    find_test_case_by_name(test_case_name: test_case_name, mod: mod)
  end
end

#installObject



377
378
379
380
381
382
383
384
385
386
387
# File 'lib/mesa_test.rb', line 377

def install
  with_MESA_DIR do
    visit_and_check mesa_dir, MesaDirError, "Encountered a problem in " +
                              "running `install` in #{mesa_dir}." do
      puts 'MESA_DIR = ' + ENV['MESA_DIR']
      puts './install'
      system('./install')
    end
  end
  self
end

#installed?Boolean

Returns:

  • (Boolean)


512
513
514
# File 'lib/mesa_test.rb', line 512

def installed?
  check_mesa_dir
end

#load_test_source_data(mod: :all) ⇒ Object

load data from the ‘do1_test_source` file that gets used in a lot of testing



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/mesa_test.rb', line 408

def load_test_source_data(mod: :all)
  # allow for brainless loading of all module data
  if mod == :all
    MesaTestCase.modules.each do |this_mod|
      load_test_source_data(mod: this_mod)
    end
  else
    check_mod mod
    # load data from the source file
    source_lines = IO.readlines(
      File.join(test_suite_dir(mod: mod), 'do1_test_source')
    )

    # initialize data hash to empty hash and name array to empty array
    @test_data[mod] = {}
    @test_names[mod] = []
    @test_cases[mod] = {}

    # read through each line and find four data, name, success string, final
    # model name, and photo. Either of model name and photo can be "skip"
    source_lines.each do |line|
      no_skip = /^do_one (.+)\s+"([^"]*)"\s+"([^"]+)"\s+(x?\d+)/
      one_skip = /^do_one (.+)\s+"([^"]*)"\s+"([^"]+)"\s+skip/
      two_skip = /^do_one (.+)\s+"([^"]*)"\s+skip\s+skip/
      found_test = false
      if line =~ no_skip
        found_test = true
        @test_data[mod][$1] = { success_string: $2, final_model: $3,
                                photo: $4} 
      elsif line =~ one_skip
        found_test = true
        @test_data[mod][$1] = { success_string: $2, final_model: $3,
                                photo: nil }
      elsif line =~ two_skip
        found_test = true
        @test_data[mod][$1] = { success_string: $2, final_model: nil,
                                photo: nil }
      end

      if found_test
        @test_names[mod] << $1 unless @test_names.include? $1
      end
    end

    # make MesaTestCase objects accessible by name
    @test_names[mod].each do |test_name|
      data = @test_data[mod][test_name]
      @test_cases[mod][test_name] = MesaTestCase.new(test: test_name,
        mesa: self, success_string: data[:success_string], mod: mod,
        final_model: data[:final_model], photo: data[:photo])
    end
  end
end

#test_suite_dir(mod: nil) ⇒ Object



401
402
403
404
# File 'lib/mesa_test.rb', line 401

def test_suite_dir(mod: nil)
  check_mod mod
  File.join(mesa_dir, mod.to_s, 'test_suite')
end

#version_numberObject

read version number from $MESA_DIR/data/version_number



357
358
359
360
361
362
363
# File 'lib/mesa_test.rb', line 357

def version_number
  contents = ''
  File.open(File.join(mesa_dir, 'data', 'version_number'), 'r') do |f|
    contents = f.read
  end
  contents.strip.to_i
end