Module: Bashcov

Extended by:
BashInfo
Defined in:
lib/bashcov.rb,
lib/bashcov/line.rb,
lib/bashcov/lexer.rb,
lib/bashcov/errors.rb,
lib/bashcov/runner.rb,
lib/bashcov/xtrace.rb,
lib/bashcov/version.rb,
lib/bashcov/bash_info.rb,
lib/bashcov/detective.rb,
lib/bashcov/field_stream.rb

Overview

:nodoc:

Defined Under Namespace

Modules: BashInfo, Line Classes: Detective, FieldStream, Lexer, Options, Runner, Xtrace, XtraceError

Constant Summary collapse

BASH_VERSION =

Current Bash version (e.g. 4.2)

`#{bash_path} -c 'echo -n ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}'`.freeze
VERSION =

Current Bashcov version

"1.8.2"

Class Method Summary collapse

Methods included from BashInfo

bash_xtracefd?, truncated_ps4?

Class Method Details

.command_nameString

Returns The value to use as SimpleCov.command_name. Uses the value of --command-name, if this flag was provided, or +BASHCOV_COMMAND_NAME, if set, defaulting to a stringified representation of #command.

Returns:

  • (String)

    The value to use as SimpleCov.command_name. Uses the value of --command-name, if this flag was provided, or +BASHCOV_COMMAND_NAME, if set, defaulting to a stringified representation of #command.



66
67
68
69
70
# File 'lib/bashcov.rb', line 66

def command_name
  return @options.command_name if @options.command_name
  return ENV["BASHCOV_COMMAND_NAME"] unless ENV.fetch("BASHCOV_COMMAND_NAME", "").empty?
  command.compact.join(" ")
end

.fullnameString

Note:

fullname instead of name to avoid clashing with Module.name

Returns Program name including version for easy consistent output.

Returns:

  • (String)

    Program name including version for easy consistent output



52
53
54
55
56
57
58
59
60
# File 'lib/bashcov.rb', line 52

def fullname
  [
    program_name,
    VERSION,
    "with Bash #{BASH_VERSION},",
    "Ruby #{RUBY_VERSION},",
    "and SimpleCov #{SimpleCov::VERSION}.",
  ].join(" ")
end

.optionsStruct

Returns The Struct object representing Bashcov configuration.

Returns:

  • (Struct)

    The Struct object representing Bashcov configuration



22
23
24
25
# File 'lib/bashcov.rb', line 22

def options
  set_default_options! unless defined?(@options)
  @options
end

.parse_options!(args) ⇒ void

This method returns an undefined value.

Parses the given CLI arguments and sets options.

Parameters:

  • args (Array)

    list of arguments

Raises:

  • (SystemExit)

    if invalid arguments are given



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bashcov.rb', line 31

def parse_options!(args)
  begin
    option_parser.parse!(args)
  rescue OptionParser::ParseError, Errno::ENOENT => e
    abort "#{option_parser.program_name}: #{e.message}"
  end

  if args.empty?
    abort("You must give exactly one command to execute.")
  else
    options.command = args.unshift(bash_path)
  end
end

.program_nameString

Returns Program name.

Returns:

  • (String)

    Program name



46
47
48
# File 'lib/bashcov.rb', line 46

def program_name
  "bashcov"
end

.set_default_options!Object

Wipe the current options and reset default values



73
74
75
76
77
78
79
80
# File 'lib/bashcov.rb', line 73

def set_default_options!
  @options = Options.new

  @options.skip_uncovered   = false
  @options.mute             = false
  @options.bash_path        = "/bin/bash"
  @options.root_directory   = Dir.getwd
end