Class: Nonnative::GoExecutable

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

Overview

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

This helper is used 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.

Parameter strings are parsed into argv words using shell-style quoting.

Examples:

executable = Nonnative::GoExecutable.new(%w[prof cover], './svc.test', 'reports')
executable.argv('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) ⇒ GoExecutable

Returns a new instance of GoExecutable.

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



35
36
37
38
39
# File 'lib/nonnative/go_executable.rb', line 35

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

Instance Method Details

#argv(cmd, *params) ⇒ Array<String>

Returns an executable argv array 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 parameter strings passed after ‘cmd`

Returns:

  • (Array<String>)

    argv entries to execute



48
49
50
# File 'lib/nonnative/go_executable.rb', line 48

def argv(cmd, *params)
  [exec, *flags(cmd), cmd, *parameter_args(params)]
end

#command(cmd, *params) ⇒ String

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

Parameters:

  • cmd (String)

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

  • params (Array<String>)

    additional parameter strings passed after ‘cmd`

Returns:

  • (String)

    the full command to execute



57
58
59
# File 'lib/nonnative/go_executable.rb', line 57

def command(cmd, *params)
  Shellwords.join(argv(cmd, *params))
end