Sha256: bcff4c6b0e1537bdcda6ee5b34f9f1040b634036b54ca073faea87c3628abf12

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

#!/usr/bin/env ruby
=begin =======================================================================

# TORK-NOTIFY 1 2014-10-26 20.0.0

## NAME

tork-notify - notifies you of test status changes

## SYNOPSIS

`tork-notify` [*OPTION*]...

## DESCRIPTION

This program serves as an example of how to receive and process messages sent
by the various programs in the tork(1) suite.  It notifies you when previously
passing tests fail (or vice versa) through libnotify, xmessage, or growl.  If
none are available on your system, then the notification is printed to stdout.

## OPTIONS

`-h`, `--help`
  Show this help manual.

## EXIT STATUS

See tork-remote(1).

## SEE ALSO

tork-remote(1), tork-engine(1)

=end =========================================================================

$0 = File.basename(__FILE__) # for easier identification in ps(1) output

require 'binman'
BinMan.help

require 'json'
IO.popen('tork-remote tork-engine', 'r+') do |remote|
  while message = remote.gets
    event, test_file, *details = JSON.load(message)

    # make notifications edge-triggered: pass => fail or vice versa.
    # we do not care about pass => pass or fail => fail transitions.
    icon = case event.to_sym
           when :pass! then 'dialog-information'
           when :fail! then 'dialog-error'
           end

    if icon
      _, _, line_numbers, log_file = details.first

      title = [event.upcase, test_file].join(' ')

      statistics = File.readlines(log_file).grep(/^\d+ \w+,/).join.
        gsub(/\e\[\d+(;\d+)?m/, '') # strip ANSI SGR escape codes

      # run in background; see http://stackoverflow.com/q/16745840
      Thread.new(icon, title, statistics) do |icon, title, statistics|
        system 'notify-send', '-i', icon, title, statistics or
        system 'growlnotify', '-a', 'Xcode', '-m', statistics, title or
        system 'xmessage', '-timeout', '5', '-title', title, statistics or
        puts title, statistics, nil
      end
    end
  end
end
exit $?.exitstatus

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tork-20.0.0 bin/tork-notify