forked from vkolgi/tuneup_js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-test
executable file
·82 lines (66 loc) · 2.02 KB
/
run-test
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env ruby -wKU
require "fileutils"
require "optparse"
require "ostruct"
require "pty"
options = OpenStruct.new
options.env_vars = {}
opts_parser = OptionParser.new do |opts|
opts.banner = "USAGE: run-test-script <app bundle> <test script> <output directory> [device_id] [pass-through args...]"
opts.on("-d", "--device [DEVICE]", "Device UDID to run test against") do |dev|
options.device = dev
end
opts.on("-e", "--environment [ENV]") do |env|
key, value = env.split '='
options.env_vars[key] = value
end
end
unless ARGV.length >= 3
opts_parser.help
exit 1
end
app_bundle, test_script, test_output = ARGV.shift 3
opts_parser.parse!
# Instruments wants the test_script to be a fully-qualified path
unless test_script[0] == "/"
test_script = "#{Dir.pwd}/#{test_script}"
end
SDKROOT = `/usr/bin/xcodebuild -version -sdk iphoneos | grep PlatformPath`.split(":")[1].chomp.sub(/^\s+/, "")
command = ["/usr/bin/instruments"]
command << "-w #{options.device}" if options.device
command << "-t #{SDKROOT}/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"
command << app_bundle
command << "-e UIASCRIPT #{test_script}"
command << "-e UIARESULTSPATH #{test_output}"
options.env_vars.to_a.each do |pair|
command << "-e #{pair.join ' '}"
end
puts "command=#{command.join ' '}"
failed = false
unless File.directory? test_output
FileUtils.mkdir_p test_output
end
Dir.chdir(test_output) do
begin
PTY.spawn(command.join ' ') do |r, w, pid|
r.each do |line|
puts line
_, date, time, tz, type, msg = line.match(/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) ([+-]\d{4}) ([^:]+): (.*)$/).to_a
case type
when "Fail"
failed = true
end
end
end
rescue Errno::EIO
rescue PTY::ChildExited => e
STDERR.puts "Instruments exited unexpectedly"
exit 1
end
if failed
STDERR.puts "#{test_script} failed, see log output for details"
exit 1
else
STDOUT.puts "TEST PASSED"
end
end