Skip to content

Commit

Permalink
Ability to run go test
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Apr 6, 2012
1 parent d0cc23a commit 09aa946
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
39 changes: 27 additions & 12 deletions lib/guard/go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,47 @@ def initialize(watchers = [], options = {})
super

defaults = {
:server => 'app.go'
:server => 'app.go',
:test => false
}

@runner = ::Guard::GoRunner.new(defaults.merge(options))
@options = defaults.merge(options)

@runner = ::Guard::GoRunner.new(@options)
end

def start
UI.info "Starting Go..."
if pid = @runner.start
UI.info "Started Go app, pid #{pid}"
end
start_info
run_info @runner.start
end

def run_on_change(paths)
UI.info "Restarting Go..."
if @runner.restart
UI.info "Go restarted, pid #{@runner.pid}"
else
UI.info "Go NOT restarted, check your log files."
end
start_info
run_info @runner.restart
end

def stop
@runner.stop
UI.info "Stopping Go..."
Notifier.notify("Until next time...", :title => "Go shutting down.", :image => :pending)
end

private
def start_info
if @options[:test]
UI.info "Running go test..."
else
UI.info "Running #{options[:server]}..."
end
end

def run_info(pid)
return if @options[:test]
if pid
UI.info "Started Go app, pid #{pid}"
else
UI.info "Go command failed, check your log files."
end
end
end
end
6 changes: 5 additions & 1 deletion lib/guard/go/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ def restart
end

def build_go_command
%{cd #{Dir.pwd} && go run #{@options[:server]} &}
if @options[:test]
%{cd #{Dir.pwd} && go test}
else
%{cd #{Dir.pwd} && go run #{@options[:server]} &}
end
end

def ps_go_pid
Expand Down

0 comments on commit 09aa946

Please sign in to comment.