Class: Mesa
- Inherits:
-
Object
- Object
- Mesa
- Defined in:
- lib/mesa_test.rb
Instance Attribute Summary collapse
-
#github_protocol ⇒ Object
readonly
Returns the value of attribute github_protocol.
-
#mesa_dir ⇒ Object
readonly
Returns the value of attribute mesa_dir.
-
#mirror_dir ⇒ Object
readonly
Returns the value of attribute mirror_dir.
-
#names_to_numbers ⇒ Object
readonly
Returns the value of attribute names_to_numbers.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
-
#test_case_names ⇒ Object
readonly
Returns the value of attribute test_case_names.
-
#test_cases ⇒ Object
readonly
Returns the value of attribute test_cases.
Class Method Summary collapse
Instance Method Summary collapse
-
#check_installation ⇒ Object
throw an error unless it seems like it’s properly compiled.
-
#check_mod(mod) ⇒ Object
TEST SUITE METHODS.
- #checkout(new_sha: 'HEAD') ⇒ Object
- #clean ⇒ Object
-
#compiler_hash ⇒ Object
sourced from $MESA_DIR/testhub.yml, which should be created after installation.
- #downloaded? ⇒ Boolean
- #each_test_run(mod: :all) ⇒ Object
-
#find_test_case(test_case_name: nil, mod: :all) ⇒ Object
can accept a number (in string form) as a name for indexed access.
- #git_sha ⇒ Object
-
#initialize(mesa_dir: , mirror_dir: nil, github_protocol: :ssh) ⇒ Mesa
constructor
A new instance of Mesa.
- #install ⇒ Object
- #installed? ⇒ Boolean
-
#load_test_source_data(mod: :all) ⇒ Object
load data from the ‘do1_test_source` file that gets used in a lot of testing.
- #remove ⇒ Object
- #sha ⇒ Object
- #test_case_count(mod: :all) ⇒ Object
- #test_suite_dir(mod: nil) ⇒ Object
- #update_mirror ⇒ Object
Constructor Details
#initialize(mesa_dir: , mirror_dir: nil, github_protocol: :ssh) ⇒ Mesa
Returns a new instance of Mesa.
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/mesa_test.rb', line 387 def initialize(mesa_dir: ENV['MESA_DIR'], mirror_dir: nil, github_protocol: :ssh) # absolute_path ensures that it doesn't matter where commands are executed # from @mesa_dir = File.absolute_path(mesa_dir) @mirror_dir = File.absolute_path(mirror_dir) # don't worry about validity of github protocol until it is needed in a # checkout. This way you can have garbage in there if you never really need # it. @github_protocol = if github_protocol.respond_to? :to_sym github_protocol.to_sym else github_protocol end # these get populated by calling #load_test_data @test_cases = {} @test_case_names = {} @names_to_numbers = {} # way to output colored text @shell = Thor::Shell::Color.new end |
Instance Attribute Details
#github_protocol ⇒ Object (readonly)
Returns the value of attribute github_protocol.
376 377 378 |
# File 'lib/mesa_test.rb', line 376 def github_protocol @github_protocol end |
#mesa_dir ⇒ Object (readonly)
Returns the value of attribute mesa_dir.
376 377 378 |
# File 'lib/mesa_test.rb', line 376 def mesa_dir @mesa_dir end |
#mirror_dir ⇒ Object (readonly)
Returns the value of attribute mirror_dir.
376 377 378 |
# File 'lib/mesa_test.rb', line 376 def mirror_dir @mirror_dir end |
#names_to_numbers ⇒ Object (readonly)
Returns the value of attribute names_to_numbers.
376 377 378 |
# File 'lib/mesa_test.rb', line 376 def names_to_numbers @names_to_numbers end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
376 377 378 |
# File 'lib/mesa_test.rb', line 376 def shell @shell end |
#test_case_names ⇒ Object (readonly)
Returns the value of attribute test_case_names.
376 377 378 |
# File 'lib/mesa_test.rb', line 376 def test_case_names @test_case_names end |
#test_cases ⇒ Object (readonly)
Returns the value of attribute test_cases.
376 377 378 |
# File 'lib/mesa_test.rb', line 376 def test_cases @test_cases end |
Class Method Details
.checkout(sha: nil, work_dir: nil, mirror_dir: nil, github_protocol: :ssh) ⇒ Object
379 380 381 382 383 384 385 |
# File 'lib/mesa_test.rb', line 379 def self.checkout(sha: nil, work_dir: nil, mirror_dir: nil, github_protocol: :ssh) m = Mesa.new(mesa_dir: work_dir, mirror_dir: mirror_dir, github_protocol: github_protocol) m.checkout(new_sha: sha) m end |
Instance Method Details
#check_installation ⇒ Object
throw an error unless it seems like it’s properly compiled
547 548 549 550 551 552 |
# File 'lib/mesa_test.rb', line 547 def check_installation return if installed? raise MesaDirError, 'Installation check failed (build.log doesn\'t '\ 'show a successful installation).' end |
#check_mod(mod) ⇒ Object
TEST SUITE METHODS
570 571 572 573 574 575 |
# File 'lib/mesa_test.rb', line 570 def check_mod(mod) return if MesaTestCase.modules.include? mod raise TestCaseDirError, "Invalid module: #{mod}. Must be one of: " + MesaTestCase.modules.join(', ') end |
#checkout(new_sha: 'HEAD') ⇒ Object
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 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/mesa_test.rb', line 412 def checkout(new_sha: 'HEAD') # before anything confirm that git-lfs has been installed shell.say "\nEnsuring that git-lfs is installed... ", :blue command = 'git lfs help >> /dev/null 2>&1' if bash_execute(command) shell.say "yes", :green else shell.say "no", :red raise(GitHubError, "The command #{command} returned with an error "\ 'status, indicating that git-lfs is not installed. '\ 'Make sure it is installed and try again.') end # set up mirror if it doesn't exist unless dir_or_symlink_exists?(mirror_dir) shell.say "\nCreating initial mirror at #{mirror_dir}. "\ 'This might take awhile...', :blue FileUtils.mkdir_p mirror_dir case github_protocol when :ssh command = "git clone --mirror #{GITHUB_SSH} #{mirror_dir}" shell.say command # fail loudly if this doesn't work unless bash_execute(command) # nuke the mirror directory since it is probably bogus (make this # code fire off the next time checkout is done) shell.say "Failed. Removing the [potentially corrupted] mirror.", :red command = "rm -rf #{mirror_dir}" shell.say command bash_execute(command) raise(GitHubError, 'Error while executing the following command:'\ "#{command}. Perhaps you haven't set up "\ 'ssh keys with your GitHub account?') end when :https command = "git clone --mirror #{GITHUB_HTTPS} #{mirror_dir}" shell.say command # fail loudly if this doesn't work unless bash_execute(command) # nuke the mirror directory since it is probably bogus (make this # code fire off the next time checkout is done) shell.say "Failed. Removing the [potentially corrupted] mirror.", :red command = "rm -rf #{mirror_dir}" shell.say command bash_execute(command) raise(GitHubError, 'Error while executing the following command: '\ "#{command}. Perhaps you need to configure "\ 'global GitHub account settings for https '\ 'authentication to work properly?') end else raise(GitHubError, "Invalid GitHub protocol: \"#{github_protocol}\"") end end update_mirror # ensure "work" directory is removed from worktree remove # create "work" directory with proper commit shell.say "\nSetting up worktree repo...", :blue FileUtils.mkdir_p mesa_dir command = "git -C #{mirror_dir} worktree add #{mesa_dir} #{new_sha}" shell.say command return if bash_execute(command) raise(GitHubError, 'Failed while executing the following command: '\ "\"#{command}\".") end |
#clean ⇒ Object
520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/mesa_test.rb', line 520 def clean with_mesa_dir do visit_and_check mesa_dir, MesaDirError, 'E\countered a problem in ' \ "running `clean` in #{mesa_dir}." do shell.say('MESA_DIR = ' + ENV['MESA_DIR']) shell.say './clean' bash_execute('./clean') end end self end |
#compiler_hash ⇒ Object
sourced from $MESA_DIR/testhub.yml, which should be created after installation
556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/mesa_test.rb', line 556 def compiler_hash data_file = File.join(mesa_dir, 'testhub.yml') unless File.exist? data_file raise(MesaDirError, "Could not find file testhub.yml in #{mesa_dir}.") end res = YAML.safe_load(File.read(data_file)) # currently version_number is reported, but we don't need that in Git land res.delete('version_number') # returns the value, not the updated hash res end |
#downloaded? ⇒ Boolean
641 642 643 |
# File 'lib/mesa_test.rb', line 641 def downloaded? check_mesa_dir end |
#each_test_run(mod: :all) ⇒ Object
627 628 629 630 631 632 633 634 635 636 637 638 639 |
# File 'lib/mesa_test.rb', line 627 def each_test_run(mod: :all) check_installation if mod == :all MesaTestCase.modules.each do |this_mod| each_test_run(mod: this_mod) end else visit_dir(test_suite_dir(mod: mod)) do bash_execute('./each_test_run') end 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
619 620 621 622 623 624 625 |
# File 'lib/mesa_test.rb', line 619 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 |
#git_sha ⇒ Object
512 513 514 |
# File 'lib/mesa_test.rb', line 512 def git_sha bashticks("git -C #{mesa_dir} rev-parse HEAD") end |
#install ⇒ Object
532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/mesa_test.rb', line 532 def install with_mesa_dir do visit_and_check mesa_dir, MesaDirError, 'Encountered a problem in ' \ "running `install` in #{mesa_dir}." do shell.say('MESA_DIR = ' + ENV['MESA_DIR']) shell.say './install' bash_execute('./install') end end # this should never happen if visit_and_check works properly. check_installation self end |
#installed? ⇒ Boolean
645 646 647 648 649 650 651 |
# File 'lib/mesa_test.rb', line 645 def installed? # assume build log reflects installation status; does not account for # mucking with modules after the fact downloaded? && File.read(File.join(mesa_dir, 'build.log')).include?( 'MESA installation was successful' ) end |
#load_test_source_data(mod: :all) ⇒ Object
load data from the ‘do1_test_source` file that gets used in a lot of testing
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
# File 'lib/mesa_test.rb', line 584 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 # convert output of +list_tests+ to a dictionary that maps # names to numbers since +each_test_run+ only knows about numbers @names_to_numbers[mod] = {} @test_case_names[mod] = [] @test_cases[mod] = {} visit_dir(test_suite_dir(mod: mod), quiet: true) do bashticks('./list_tests').split("\n").each do |line| num, tc_name = line.strip.split @names_to_numbers[mod][tc_name.strip] = num.to_i @test_case_names[mod] << tc_name.strip @test_cases[mod][tc_name.strip] = MesaTestCase.new( test: tc_name.strip, mod: mod, position: num.to_i, mesa: self ) end end end end |
#remove ⇒ Object
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/mesa_test.rb', line 496 def remove return unless File.exist? mesa_dir shell.say "\nRemoving work directory from worktree (clearing old data)...", :blue command = "git -C #{mirror_dir} worktree remove --force #{mesa_dir}" shell.say command return if bash_execute(command) shell.say "Failed. Simply trying to remove the directory.", :red command = "rm -rf #{mesa_dir}" shell.say command # fail loudly (the "true" tells bash_execute to raise an exception if # the command fails) bash_execute(command, true) end |
#sha ⇒ Object
516 517 518 |
# File 'lib/mesa_test.rb', line 516 def sha git_sha end |
#test_case_count(mod: :all) ⇒ Object
614 615 616 |
# File 'lib/mesa_test.rb', line 614 def test_case_count(mod: :all) all_names_ordered(mod: mod).count end |
#test_suite_dir(mod: nil) ⇒ Object
577 578 579 580 |
# File 'lib/mesa_test.rb', line 577 def test_suite_dir(mod: nil) check_mod mod File.join(mesa_dir, mod.to_s, 'test_suite') end |
#update_mirror ⇒ Object
485 486 487 488 489 490 491 492 493 494 |
# File 'lib/mesa_test.rb', line 485 def update_mirror shell.say "\nFetching MESA history...", :blue command = "git -C #{mirror_dir} fetch origin" shell.say command # fail loudly return if bash_execute(command) raise(GitHubError, 'Failed while executing the following command: '\ "\"#{command}\".") end |