Class: Oktest::MainApp

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command = nil) ⇒ MainApp

Returns a new instance of MainApp.



2705
2706
2707
2708
# File 'lib/oktest.rb', line 2705

def initialize(command=nil)
  @command = command || File.basename($0)
  @schema  = option_schema()
end

Class Method Details

.main(argv = nil) ⇒ Object



2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
# File 'lib/oktest.rb', line 2710

def self.main(argv=nil)
  #; [!tb6sx] returns 0 when no errors raised.
  #; [!d5mql] returns 1 when a certain error raised.
  argv ||= ARGV
  begin
    status = self.new.run(*argv)  or raise "** internal error"
    return status
  #; [!jr49p] reports error when unknown option specified.
  #; [!uqomj] reports error when required argument is missing.
  #; [!8i755] reports error when argument is invalid.
  rescue Benry::CmdOpt::OptionError => exc
    $stderr.puts("[ERROR] #{exc.message}")
    return 1
  end
end

Instance Method Details

#run(*args) ⇒ Object



2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
# File 'lib/oktest.rb', line 2726

def run(*args)
  color_enabled = nil
  #; [!v5xie] parses $OKTEST_RB environment variable.
  if ENV.key?('OKTEST_RB')
    args = ENV['OKTEST_RB'].split() + args
  end
  #; [!tt2gj] parses command options even after filenames.
  opts = parse_opts(args)
  filenames = args
  #; [!9973n] '-h' or '--help' option prints help message.
  if opts[:help]
    puts help_message()
    return 0
  end
  #; [!qqizl] '--version' option prints version number.
  if opts[:version]
    puts VERSION
    return 0
  end
  #; [!dk8eg] '-S' or '--skeleton' option prints test code skeleton.
  if opts[:skeleton]
    print skeleton()
    return 0
  end
  #; [!uxh5e] '-G' or '--generate' option prints test code.
  #; [!wmxu5] '--generate=unaryop' option prints test code with unary op.
  if opts[:generate]
    print generate(filenames, opts[:generate])
    return 0
  end
  #; [!65vdx] prints help message if no arguments specified.
  if filenames.empty? && !THE_GLOBAL_SCOPE.has_child?
    puts help_message()
    return 0
  end
  #; [!6ro7j] '--color=on' option enables output coloring forcedly.
  #; [!vmw0q] '--color=off' option disables output coloring forcedly.
  if opts[:color] != nil
    color_enabled = Config.color_enabled
    Config.color_enabled = opts[:color]
  end
  #; [!qs8ab] '--faster' chanages 'Config.ok_location' to false.
  if opts[:faster]
    Config.ok_location = false    # will make 'ok{}' faster
  end
  #
  $LOADED_FEATURES << __FILE__ unless $LOADED_FEATURES.include?(__FILE__) # avoid loading twice
  #; [!hiu5b] finds test scripts in directory and runs them.
  load_files(filenames)
  #; [!yz7g5] '-F topic=...' option filters topics.
  #; [!ww2mp] '-F spec=...' option filters specs.
  #; [!8uvib] '-F tag=...' option filters by tag name.
  #; [!m0iwm] '-F sid=...' option filters by spec id.
  #; [!noi8i] '-F' option supports negative filter.
  if opts[:filter]
    filter_obj = FILTER_CLASS.create_from(opts[:filter])
    Oktest.filter(filter_obj)
  end
  #; [!bim36] changes auto-running to off.
  Config.auto_run = false
  #; [!18qpe] runs test scripts.
  #; [!0qd92] '-s verbose' or '-sv' option prints test results in verbose mode.
  #; [!zfdr5] '-s simple' or '-ss' option prints test results in simple mode.
  #; [!ef5v7] '-s compact' or '-sc' option prints test results in compact mode.
  #; [!244te] '-s plain' or '-sp' option prints test results in plain mode.
  #; [!ai61w] '-s quiet' or '-sq' option prints test results in quiet mode.
  n_errors = Oktest.run(:style=>opts[:style])
  #; [!dsrae] reports if 'ok()' called but assertion not performed.
  AssertionObject.report_not_yet()
  #; [!bzgiw] returns total number of failures and errors.
  return n_errors
ensure
  #; [!937kw] recovers 'Config.color_enabled' value.
  Config.color_enabled = color_enabled if color_enabled != nil
end