Module: Bashcov

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/detective.rb,
lib/bashcov/field_stream.rb

Overview

:nodoc:

Defined Under Namespace

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

Constant Summary collapse

BASH_VERSION =

Current Bash version (e.g. 4.2)

bash_version.freeze
VERSION =

Current Bashcov version

"3.2.0"

Class Method Summary collapse

Class Method Details

.bash_pathObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bashcov.rb', line 70

def bash_path
  # first attempt to use the value from `options`, but ignore all exceptions
  # this is used early for the `BASH_VERSION` definition, so first use will likely error
  begin
    return @options.bash_path if @options.bash_path
  rescue NoMethodError; end # rubocop:disable Lint/SuppressedException

  # support the same `BASHCOV_BASH_PATH` environment variable used in the spec tests
  return ENV.fetch("BASHCOV_BASH_PATH", nil) unless ENV.fetch("BASHCOV_BASH_PATH", "").empty?

  # fall back to standard Bash location, if available
  return "/bin/bash" if File.executable?("/bin/bash")

  # otherwise, try to execute a Bash from `PATH`
  "bash"
end

.bash_versionObject



87
88
89
# File 'lib/bashcov.rb', line 87

def bash_version
  `#{bash_path} -c 'echo -n ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}'`
end

.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.



63
64
65
66
67
68
# File 'lib/bashcov.rb', line 63

def command_name
  return @options.command_name if @options.command_name
  return ENV.fetch("BASHCOV_COMMAND_NAME", nil) 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



48
49
50
51
52
53
54
55
56
57
# File 'lib/bashcov.rb', line 48

def fullname
  [
    program_name,
    VERSION,
    "with Bash #{BASH_VERSION},",
    "Ruby #{RUBY_VERSION},",
    "and SimpleCov #{SimpleCov::VERSION}",
    (Process.uid.zero? ? "as root user (NOT recommended)" : nil),
  ].compact.join(" ")
end

.optionsStruct

Returns The Struct object representing Bashcov configuration.

Returns:

  • (Struct)

    The Struct object representing Bashcov configuration



18
19
20
21
# File 'lib/bashcov.rb', line 18

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



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bashcov.rb', line 27

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



42
43
44
# File 'lib/bashcov.rb', line 42

def program_name
  "bashcov"
end

.set_default_options!Object

Wipe the current options and reset default values



92
93
94
95
96
97
98
# File 'lib/bashcov.rb', line 92

def set_default_options!
  @options = Options.new

  @options.skip_uncovered   = false
  @options.mute             = false
  @options.root_directory   = Dir.getwd
end