Warning, /kdevelop/kdev-ruby/Guardfile is written in an unsupported language. File is not indexed.
0001 ## 0002 # This file is part of KDevelop 0003 # 0004 # Copyright (C) 2012-2015 Miquel Sabaté Solà <mikisabate@gmail.com> 0005 # 0006 # This program is free software; you can redistribute it and/or modify 0007 # it under the terms of the GNU General Public License as published by 0008 # the Free Software Foundation; either version 3 of the License, or 0009 # (at your option) any later version. 0010 # 0011 # This program is distributed in the hope that it will be useful, 0012 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 # GNU General Public License for more details. 0015 # 0016 # You should have received a copy of the GNU General Public License along 0017 # with this program; if not, write to the Free Software Foundation, Inc., 0018 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0019 0020 0021 require 'guard' 0022 require 'guard/guard' 0023 0024 0025 module ::Guard 0026 # Subclass the Guard::Guard class so then we can setup the watchers 0027 # through the guard('kdev') method call. 0028 class KDev < ::Guard::Guard 0029 # Public: Initialize the Guard::KDev watcher. 0030 # 0031 # watchers - an Array containing the Guard watchers. 0032 # options - a Hash with the available options: 0033 # :build_url - a String representing the absolute path to the 0034 # build dir. 0035 # :tests - a Hash of hashes with the config for each test. 0036 def initialize(watchers = [], options = {}) 0037 super 0038 @opts = { :build_url => '', :tests => {} }.merge(options) 0039 end 0040 0041 # Public: It will be called on start. It just shows a message. 0042 # 0043 # Returns nothing. 0044 def start 0045 UI.info "Watching everything inside: #{@opts[:build_url]}" 0046 end 0047 0048 # Public: It will be called when some watched file has changed. 0049 # 0050 # paths - An Array of strings that identify which tests 0051 # should be run again. 0052 # 0053 # Returns nothing. 0054 def run_on_changes(paths) 0055 @failed = 0 0056 tests = {} 0057 paths.each { |k| tests[k.to_sym] = @opts[:tests][k.to_sym] } 0058 run_required(tests) 0059 end 0060 0061 # Public: Run all the tests and notify the user (console and libnotify). 0062 # 0063 # Returns nothing. 0064 def run_all 0065 run_required(@opts[:tests]) 0066 end 0067 0068 private 0069 0070 # Internal: Run the required tests. 0071 # 0072 # tests - A Hash of hashes containing all the info of the tests that 0073 # have to be run in this iteration. 0074 # 0075 # Returns nothing. 0076 def run_required(tests) 0077 @results = {} 0078 @failed = 0 0079 tests.each do |k, v| 0080 UI.info "Running the tests for the #{k.to_s.capitalize}..." 0081 v[:execs] = [v[:execs]] if v[:execs].is_a? String 0082 run_tests k, v[:url], v[:execs] 0083 end 0084 0085 notify! 0086 end 0087 0088 # Internal: Run all the tests of a certain component. 0089 # 0090 # key - A Symbol that is the identifier of the test. 0091 # url - A String with the relative url of the component's test directory. 0092 # tests - An Array of strings where each string is the command to be 0093 # executed in order to run the test. 0094 # 0095 # Returns nothing. 0096 def run_tests(key, url, tests) 0097 base = @opts[:build_url] + url 0098 tests.each do |t| 0099 UI.info "Executing the following command: '#{t}' in #{base}" 0100 Dir.chdir base 0101 output = `#{t}` 0102 append_results key, output, t.start_with?('./') 0103 end 0104 end 0105 0106 # Internal: Append the results of an execution to the @results array. 0107 # 0108 # key - A Symbol that is the identifier of the test. 0109 # text - A String with the output of the execution. 0110 # executable - A Boolean that tells us whether this execution comes from 0111 # an executable file or not. 0112 # 0113 # Returns nothing. 0114 def append_results(key, text, executable) 0115 total, win = 0, 0 0116 if executable 0117 text.match /Totals: (\d+) passed, (\d+) failed/ 0118 total, win = $1.to_i + $2.to_i, $1.to_i 0119 else 0120 line = text.split("\n").last 0121 line.match /^(\d+) tests, (\d+) assertions/ 0122 total, win = $1.to_i, $2.to_i 0123 end 0124 @results[key] = [win, total - win] 0125 @failed += 1 0126 end 0127 0128 # Internal: Notify the user by printing the results to the console. 0129 # A notification will also be sent (i.e. through libnotify). 0130 # 0131 # Returns nothing. 0132 def notify! 0133 puts "\n****************************************" 0134 @results.each do |k, v| 0135 puts "#{k.to_s.capitalize}: Passed: #{v.first}, Failed: #{v.last}" 0136 end 0137 puts "****************************************\n" 0138 0139 if @failed > 0 0140 ::Guard::Notifier.notify('Some tests are failing !', :image => :failed) 0141 else 0142 ::Guard::Notifier.notify('All tests passed !') 0143 end 0144 end 0145 end 0146 end 0147 0148 0149 # 0150 # And now let's use the infrastructure created above :) 0151 # 0152 0153 # The base build url. 0154 relative = (ARGV.size > 0) ? ARGV.last : 'build' 0155 build_url = File.join File.expand_path(File.dirname(__FILE__)), relative 0156 build_url += '/' unless build_url.end_with? '/' 0157 unless File.exists?(build_url) 0158 puts 'Error: wrong build directory.' 0159 exit 1 0160 end 0161 0162 # For each component (Completion, DUChain) specify the relative url 0163 # and how to execute each test. 0164 tests = { 0165 :completion => { :url => 'completion/tests/', :execs => './completion' }, 0166 :duchain => { :url => 'duchain/tests/', :execs => ['./duchain', './uses'] } 0167 } 0168 0169 # Setting up the Guard::KDev watcher for DUChain and CodeCompletion. 0170 guard 'kdev', :build_url => build_url, :tests => tests do 0171 watch(%r{^duchain/*}) { [:duchain, :completion] } 0172 watch(%r{^completion/*}) { [:completion] } 0173 end 0174 0175 # And now let's turn the Guard::RSpec watcher on for the parser. 0176 rspec_paths = File.join(build_url, 'parser/tools') 0177 guard 'rspec', cmd: 'bundle exec rspec -c -f doc', spec_paths: ["#{rspec_paths}/parser_spec.rb"] do 0178 watch(%r{^parser/(.*)$}) { "#{rspec_paths}/parser_spec.rb" } 0179 end