Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'better-build'

  • Loading branch information...
commit 2162e35c8f5e142db6673d355ef0e8db342ecf5f 2 parents a25a69a + a7ddfce
Xavier Shay authored

Showing 4 changed files with 83 additions and 2 deletions. Show diff stats Hide diff stats

  1. +1 0  .gitignore
  2. +56 2 Rakefile
  3. +22 0 bin/build
  4. +4 0 spec/spec_helper.rb
1  .gitignore
... ... @@ -1,3 +1,4 @@
1 1 tmp
2 2 .rvmrc
3 3 coverage
  4 +out
58 Rakefile
@@ -16,16 +16,44 @@ task :build do
16 16 exec('bin/build')
17 17 end
18 18
  19 +task :coverage_report do
  20 + require 'isolate/now'
  21 + require 'simplecov'
  22 +
  23 + class MyFormatter < SimpleCov::Formatter::HTMLFormatter
  24 + # TODO: Split up upstream so just the output can be overriden
  25 + def format(result)
  26 + Dir[File.join(File.dirname(__FILE__), '../assets/*')].each do |path|
  27 + FileUtils.cp_r(path, asset_output_path)
  28 + end
  29 +
  30 + File.open(File.join(output_path, "index.html"), "w+") do |file|
  31 + file.puts template('layout').result(binding)
  32 + end
  33 + puts "Coverage report generated at #{output_path[FileUtils.pwd.length+1..-1]}/index.html for:"
  34 + puts result.command_name.split(', ').map {|x| ' ' + x.split(' ', 2).last }
  35 + puts
  36 + puts "#{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
  37 + end
  38 + end
  39 +
  40 + SimpleCov.formatter = MyFormatter
  41 + SimpleCov.result.format!
  42 +end
  43 +
19 44 desc "Ensure that various code quality metrics are met"
20 45 task :quality do
21 46 coverage_threshold = 100
22 47 ratio_threshold = (0.0..1.5) # Don't care for now
23 48 failures = []
  49 + metrics = []
24 50
25 51 # NFI why this doesn't work on 1.9.2
26 52 if RUBY_VERSION >= '1.9.3'
  53 + require 'isolate/now'
27 54 require 'simplecov'
28 55 coverage = SimpleCov::ResultMerger.merged_result.covered_percent
  56 + metrics << "Coverage\t%i%" % coverage
29 57 if coverage < coverage_threshold
30 58 failures << " Coverage % too low: #{coverage} < #{coverage_threshold}"
31 59 end
@@ -34,11 +62,14 @@ task :quality do
34 62 code_loc = `cat lib/*.rb | grep -v "#" | wc -l`.to_f
35 63 spec_loc = `cat spec/**/*_spec.rb | grep -v "#" | wc -l`.to_f
36 64 ratio = spec_loc / code_loc
  65 + metrics << "Code:Spec ratio\t%.2f" % ratio
37 66
38 67 unless ratio_threshold.cover?(ratio)
39   - failures << " code:spec ratio out of range: #{ratio.round(2)} not in #{ratio_threshold}"
  68 + failures << " Code:Spec ratio out of range: #{ratio.round(2)} not in #{ratio_threshold}"
40 69 end
41 70
  71 + puts metrics.join("\n")
  72 +
42 73 unless failures.empty?
43 74 puts
44 75 puts "Code quality standards not met:"
@@ -47,14 +78,37 @@ task :quality do
47 78 end
48 79 end
49 80
  81 +desc "Run nonfunctional checks. Requires `rake benchmark` to have been run."
  82 +task :nonfunctional do
  83 + startup_time = 0.5
  84 +
  85 + results = File.read("out/benchmarks.tsv").lines.map {|x| x.split(/\t+/) }
  86 + time = results.detect {|x| x[0] == 'Startup Time' }[1].to_f
  87 + failures = []
  88 +
  89 + if time > startup_time
  90 + failures << " Startup time too high: #{time} > #{startup_time}"
  91 + end
  92 + unless failures.empty?
  93 + puts
  94 + puts "Non-functional requirements not met:"
  95 + puts failures
  96 + exit 1
  97 + end
  98 +end
  99 +
50 100 desc "Run benchmarks"
51 101 task :benchmark do
52 102 require 'benchmark'
  103 + require 'fileutils'
53 104
54 105 time = Benchmark.realtime {
55 106 `ruby -Ilib -risolate/now -rgust_application -e ''`
56 107 }
57   - puts "Startup Time\t#{time}"
  108 + output = "Startup Time\t#{time}"
  109 + FileUtils.mkdir_p("out")
  110 + File.open("out/benchmarks.tsv", "w") {|f| f.puts output }
  111 + puts output
58 112 end
59 113
60 114 task default: :build
22 bin/build
... ... @@ -1,6 +1,28 @@
1 1 #!/bin/bash
2 2 set -e
  3 +echo
  4 +echo "===== Unit"
  5 +echo
3 6 COVERAGE=1 rake spec:unit
  7 +echo
  8 +echo "===== Integration"
  9 +echo
4 10 COVERAGE=1 RESET_COVERAGE=0 rake spec:integration
  11 +echo
  12 +echo "===== Acceptance"
  13 +echo
5 14 COVERAGE=1 RESET_COVERAGE=0 rake spec:acceptance
  15 +echo
  16 +echo "===== Artifacts"
  17 +echo
  18 +rake coverage_report
  19 +echo
  20 +echo "===== Benchmarks"
  21 +echo
  22 +rake benchmark
  23 +rake nonfunctional
  24 +echo
  25 +echo "===== Quality"
  26 +echo
6 27 rake quality
  28 +echo
4 spec/spec_helper.rb
@@ -11,6 +11,10 @@
11 11 add_filter '/tmp/'
12 12 add_filter '/spec/'
13 13 end
  14 + SimpleCov.at_exit do
  15 + SimpleCov.result
  16 + end
  17 +
14 18 end
15 19
16 20 $LOAD_PATH.unshift(File.expand_path("../support", __FILE__))

0 comments on commit 2162e35

Please sign in to comment.
Something went wrong with that request. Please try again.