Last active
May 23, 2023 21:46
-
-
Save dillonhafer/f107a37ab1c6a5bf528309a68ea61ce8 to your computer and use it in GitHub Desktop.
go tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
file = ARGV[0] | |
line_num = ARGV[1].to_i | |
TestFn = Struct.new(:name, :start_line, :end_line) | |
tests = [] | |
current_test = nil | |
File.read(file).lines.each.with_index do |line, i| | |
if line.start_with?("func Test") | |
name = line.match(/func (Test[^\(]*)/).captures.first | |
current_test = TestFn.new(name, i+1) | |
end | |
if line.start_with?("}") | |
current_test.end_line = i+1 | |
tests << current_test | |
current_test = nil | |
end | |
end | |
test_on_line = tests.find do |t| | |
t.start_line <= line_num && t.end_line >= line_num | |
end | |
tests_to_run = test_on_line&.name || tests.map(&:name).join("|") | |
puts "\e[#{32}m---->\e[0m go test -run #{tests_to_run}" | |
exec "cd #{File.dirname(file)} && go test -run '#{tests_to_run}' && cd - > /dev/null" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run entire file with
gotest.rb /path/to/main_test.go
or run the single test from line48
withgotest.rb /path/to/main_test.go 48