quokkadb 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5581c6ea0323e66a9427c900c403859df29cf962
4
+ data.tar.gz: 8c9c7a4d7eee93b1d3875d8a66bffd16499f2db9
5
+ SHA512:
6
+ metadata.gz: de037adf0b869b13fb19085a467675d0dff6e00a7a498c3237f176a681ff9b627734dd7837ed4412aac89835c74a246a851c6cecf4a1472c4e6de2d5ff734c42
7
+ data.tar.gz: b0a3d681a7644461ccbc6f3ae42031a9b9f5be0607e5f96a00d19df4864a34d59b0a1e28f4d078187ebfb80f828276850905b54adc00f088aff291a56a74481c
@@ -0,0 +1,37 @@
1
+ module ADB
2
+
3
+ def ADB.find_tests(runner:, package:, serial: nil, annotation: nil, shards: nil, index: nil)
4
+ puts("adb #{serial ? "-s #{serial}" : ''} shell am instrument #{annotation ? "-e annotation #{annotation}" : ''} -e numShards 4 -e shardIndex 0 -r -w #{package}/#{runner}\n")
5
+ `adb #{serial ? "-s #{serial}" : ''} shell am instrument #{annotation ? "-e annotation #{annotation}" : ''} #{shards ? "-e numShards #{shards}" : ''} #{index ? "-e shardIndex #{index}" : ''} -e log true -r -w #{package}/#{runner}`
6
+ end
7
+
8
+ def ADB.execute_test(runner:, package:, test_name:, class_name:)
9
+ puts("adb shell am instrument -w -e class #{class_name}##{test_name} #{package}/#{runner}")
10
+ `adb shell am instrument -w -e class #{class_name}##{test_name} #{package}/#{runner}`
11
+ end
12
+
13
+ def ADB.mass_execute(runner:, package:, tests:)
14
+ tests_list = []
15
+ tests.each do |test_info|
16
+ tests_list.push("#{test_info.class_name}##{test_info.name}")
17
+ end
18
+
19
+ puts("adb shell am instrument -w -e class #{tests_list.join(',')} #{package}/#{runner}")
20
+ `adb shell am instrument -w -e class #{tests_list.join(',')} -r #{package}/#{runner}`
21
+ end
22
+
23
+ def ADB.run_tests(runner:, package:, serial: nil, annotation: nil, shards: nil, index: nil, &callback)
24
+ command = "adb #{serial ? "-s #{serial}" : ''} shell am instrument #{annotation ? "-e annotation #{annotation}" : ''} #{ADB.generate_sharding_options(shards: shards, index: index)} -r -w #{package}/#{runner}"
25
+ puts("Command: #{command}")
26
+ pipe = IO.popen(command)
27
+ while (line = pipe.gets)
28
+ callback.call(line)
29
+ end
30
+ end
31
+
32
+ def ADB.generate_sharding_options(shards:, index:)
33
+ return "" unless shards
34
+
35
+ "#{shards != '' ? "-e numShards #{shards}" : ''} #{index && index != '' ? "-e shardIndex #{index}" : ''}"
36
+ end
37
+ end
@@ -0,0 +1,102 @@
1
+ require_relative './test.rb'
2
+ require_relative './test_result.rb'
3
+ require 'colorize'
4
+
5
+ class ADBTestParser
6
+
7
+ PREFIX_TEST = 'INSTRUMENTATION_STATUS: test='
8
+ PREFIX_CLASS = 'INSTRUMENTATION_STATUS: class='
9
+ PREFIX_CODE = 'INSTRUMENTATION_STATUS_CODE: '
10
+ PREFIX_STREAM = 'INSTRUMENTATION_STATUS: stream='
11
+ PREFIX_STACK = 'INSTRUMENTATION_STATUS: stack='
12
+
13
+ attr_accessor :test_results
14
+
15
+ def initialize
16
+ clear
17
+ @test_results = []
18
+ @lock = Mutex.new
19
+ end
20
+
21
+ def parse_line(line:, background_black: false)
22
+ @lock.synchronize do
23
+ # If starts with prefix, we are not parsing an error any more (if we were)
24
+ @parsing_error = false if line.include?('INSTRUMENTATION_STATUS')
25
+
26
+ if (@parsing_error)
27
+ # if we have started with the stack trace continue with it
28
+ if (@current_result.stack_trace)
29
+ @current_result.stack_trace += "\n#{line.gsub("\n", '')}"
30
+ else
31
+ @current_result.failure_output += "\n#{line.gsub("\n", '')}"
32
+ end
33
+ return
34
+ end
35
+
36
+ if (line.include?('INSTRUMENTATION_STATUS: id='))
37
+ # if we have already started parsing a second block for the test, this
38
+ # is a new test
39
+ if (@test_occurences > 1)
40
+ @current_result.original_test = @current_test
41
+ @current_result.passed = @current_result.result_code == "0"
42
+ @test_results.push(@current_result)
43
+
44
+ print_result(@current_result, background_black: background_black)
45
+ clear
46
+ end
47
+
48
+ @test_occurences += 1
49
+ elsif line.include?(PREFIX_TEST)
50
+ @current_test.name = strip(line, PREFIX_TEST)
51
+ elsif line.include?(PREFIX_CLASS)
52
+ @current_test.class_name = strip(line, PREFIX_CLASS)
53
+ elsif line.include?(PREFIX_CODE)
54
+ @current_result.result_code = strip(line, PREFIX_CODE)
55
+ elsif line.include?(PREFIX_STREAM)
56
+ @parsing_error = true
57
+ @current_result.failure_output += "#{strip(line, PREFIX_STREAM)}"
58
+ elsif line.include?(PREFIX_STACK)
59
+ @parsing_error = true
60
+ @current_result.stack_trace = "#{strip(line, PREFIX_STACK)}"
61
+ end
62
+ end
63
+ end
64
+
65
+ def clear
66
+ @parsing_error = false
67
+ @test_occurences = 0
68
+ @current_test = Test.new()
69
+ @current_result = TestResult.new()
70
+ end
71
+
72
+ def strip(str, substring)
73
+ str.sub(substring, '').gsub("\n", '').gsub("\r", '')
74
+ end
75
+
76
+ def print_result(result, background_black: false)
77
+ class_name = result.original_test.class_name.split('.').last
78
+ class_name = '%30.30s' % class_name
79
+ print("#{class_name} ")
80
+
81
+ passed_string = " #{result.passed ? "P" : "F"} ".black
82
+ if (result.passed)
83
+ passed_string = passed_string.on_green
84
+ else
85
+ passed_string = passed_string.on_red
86
+ end
87
+ print passed_string
88
+
89
+ test_name_string = " #{result.original_test.name} ".yellow
90
+ if (background_black)
91
+ test_name_string = test_name_string.yellow.on_light_black
92
+ end
93
+ puts(test_name_string)
94
+
95
+ if (!result.passed)
96
+ result.failure_output.each_line do |line|
97
+ print("#{'%30.30s' % ""} #{line}".red)
98
+ end
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,39 @@
1
+ require_relative './test.rb'
2
+
3
+ module ADBParser
4
+
5
+ PREFIX_INST_STATUS = 'INSTRUMENTATION_STATUS: '
6
+ PREFIX_TEST = 'test='
7
+ PREFIX_CLASS = 'class='
8
+
9
+ def ADBParser.generate_tests(logs)
10
+ if (!logs.respond_to?('each_line'))
11
+ raise 'Logs are not enumerable'
12
+ end
13
+
14
+ tests = []
15
+ active_test = nil
16
+ logs.each_line do |line|
17
+ line.gsub!("\n", '')
18
+ if (!line.include?(PREFIX_INST_STATUS))
19
+ next
20
+ end
21
+
22
+ # Remove beginning of line
23
+ line.sub!(PREFIX_INST_STATUS, '')
24
+
25
+ if (line.start_with?(PREFIX_TEST))
26
+ active_test = Test.new(line.sub(PREFIX_TEST, ''))
27
+ elsif (line.start_with?(PREFIX_CLASS))
28
+ active_test.class_name = line.sub(PREFIX_CLASS, '')
29
+ end
30
+
31
+ if (active_test && active_test.data_complete?)
32
+ tests.push(active_test)
33
+ active_test = nil
34
+ end
35
+ end
36
+ tests
37
+ end
38
+
39
+ end
data/lib/quokkadb.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'quokkadb/adb.rb'
2
+ require 'quokkadb/test.rb'
3
+ require 'quokkadb/test_result.rb'
4
+ require 'quokkadb/adb_test_parser.rb'
5
+ require 'colorize'
6
+
7
+ module QuokkADB
8
+
9
+ def QuokkADB.run(runner:, package:, annotation: nil, shards: nil, index: nil, serial: nil, background_black: false)
10
+ full_log = ""
11
+ parser = ADBTestParser.new()
12
+ ADB.run_tests(
13
+ runner: runner,
14
+ package: package,
15
+ annotation: annotation,
16
+ shards: shards,
17
+ index: index,
18
+ serial: serial
19
+ ) { |line|
20
+ full_log += line
21
+ parser.parse_line(line: line, background_black: background_black)
22
+ }
23
+
24
+ full_log.each_line do |log|
25
+ if (log.include?("FAILURES!!!") or log.include?("Process crashed while executing") or log.include?("INSTRUMENTATION_FAILED"))
26
+ puts("exit 1")
27
+ exit(1)
28
+ end
29
+ end
30
+
31
+ parser.test_results.each do |result|
32
+ if (!result.passed)
33
+ puts("exit 1")
34
+ exit(1)
35
+ end
36
+ end
37
+ puts("exit 0")
38
+ end
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quokkadb
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Joe Beveridge
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ADB test parsing libraryr
14
+ email: joe.beveridge@shopify.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/quokkadb.rb
20
+ - lib/quokkadb/adb.rb
21
+ - lib/quokkadb/adb_test_parser.rb
22
+ - lib/quokkadb/adbparser.rb
23
+ homepage: http://rubygems.org/gems/quokka
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.5.1
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: ADB test parsing library
47
+ test_files: []