Class: Nonnative::GoCommand

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

Overview

Builds command lines for running a Go test binary with optional profiling/trace/coverage flags.

This helper is used by go_executable and by YAML configuration when a process has a go: section (see Configuration).

The generated flags use Go’s testing package flags (e.g. ‘-test.cpuprofile=…`), so this is intended to run a binary compiled from `go test -c`.

## Tools

Tools can be enabled/disabled via the tools list. Supported values:

  • ‘“prof”`: cpu/mem/block/mutex profiles

  • ‘“trace”`: execution trace output

  • ‘“cover”`: coverage profile output

If tools is nil or empty, all tools (prof, trace, cover) are enabled.

Examples:

cmd = Nonnative::GoCommand.new(%w[prof cover], './svc.test', 'reports')
cmd.executable('serve', '--config', 'config.yaml')
# => "./svc.test -test.cpuprofile=... -test.coverprofile=... serve --config config.yaml"

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(tools, exec, output) ⇒ GoCommand

Returns a new instance of GoCommand.

Parameters:

  • tools (Array<String>, nil)

    tool names to enable (see class docs)

  • exec (String)

    path to the compiled Go test binary

  • output (String)

    output directory for generated files



32
33
34
35
36
# File 'lib/nonnative/go_command.rb', line 32

def initialize(tools, exec, output)
  @tools = tools.nil? || tools.empty? ? %w[prof trace cover] : tools
  @exec = exec
  @output = output
end

Instance Method Details

#executable(cmd, *params) ⇒ String

Returns an executable command string including enabled -test.* flags.

A short random suffix is appended to output filenames to reduce collisions across runs.

Parameters:

  • cmd (String)

    command/sub-command argument passed to the Go test binary

  • params (Array<String>)

    additional parameters passed after cmd

Returns:

  • (String)

    the full command to execute



45
46
47
48
# File 'lib/nonnative/go_command.rb', line 45

def executable(cmd, *params)
  params = params.join(' ')
  "#{exec} #{flags(cmd).join(' ')} #{cmd} #{params}".strip
end