File: list_tests

package info (click to toggle)
passenger 6.1.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 50,788 kB
  • sloc: cpp: 589,292; ruby: 43,761; ansic: 27,742; javascript: 5,948; python: 1,158; sh: 1,012; makefile: 51
file content (40 lines) | stat: -rwxr-xr-x 981 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env ruby
#
# Usage: ./dev/list_tests.rb <FILENAME>
#
# Lists the test names in the given .cpp test file.

require_relative '../src/ruby_supportlib/phusion_passenger/utils/ansi_colors'

include PhusionPassenger::Utils::AnsiColors

def extract_category_name(occurrence)
  occurrence =~ / (.+) /
  return $1
end

def extract_test_name(occurrence)
  occurrence = occurrence.sub(/.*?\((.+)\).*/m, '\1')
  occurrence.gsub!(/"\n[ \t]*"/m, '')
  occurrence.sub!(/\A"/, '')
  occurrence.sub!(/"\Z/, '')
  return occurrence
end

def start(filename)
  STDOUT.write(DEFAULT_TERMINAL_COLOR)
  begin
    occurrences = File.read(filename).scan(%r{/\*\*\*\*\* .+? \*\*\*\*\*/|set_test_name\(.+?\);}m)
    occurrences.each do |occurrence|
      if occurrence =~ %r{\A/}
        puts ansi_colorize("<b>" + extract_category_name(occurrence) + "</b>")
      else
        puts "  " + extract_test_name(occurrence)
      end
    end
  ensure
    STDOUT.write(RESET)
  end
end

start(ARGV[0])