Class: Oktest::MainApp

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

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.main(argv = nil) ⇒ Object



2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
# File 'lib/oktest.rb', line 2470

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 OptionParser::ParseError => exc
    case exc
    when OptionParser::InvalidOption   ; s = "unknown option."
    when OptionParser::InvalidArgument ; s = "invalid argument."
    when OptionParser::MissingArgument ; s = "argument required."
    else                               ; s = nil
    end
    msg = s ? "#{exc.args.join(' ')}: #{s}" : exc.message
    $stderr.puts("#{File.basename($0)}: #{msg}")
    return 1
  end
end

Instance Method Details

#run(*args) ⇒ Object



2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
# File 'lib/oktest.rb', line 2493

def run(*args)
  color_enabled = nil
  opts = Options.new
  parser = option_parser(opts)
  filenames = parser.parse(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] '-C' or '--create' option prints test code skeleton.
  if opts.create
    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
    color_enabled = Config.color_enabled
    Config.color_enabled = (opts.color == 'on')
  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