run_loop 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/run_loop/core.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'tmpdir'
3
3
  require 'timeout'
4
+ #require 'open4'
4
5
 
5
6
  module RunLoop
6
7
 
@@ -11,7 +12,8 @@ module RunLoop
11
12
 
12
13
  SCRIPTS_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'scripts'))
13
14
  SCRIPTS = {
14
- :dismiss => "run_dismiss_location.js"
15
+ :dismiss => "run_dismiss_location.js",
16
+ :run_loop => "run_loop.js"
15
17
  }
16
18
 
17
19
  def self.scripts_path
@@ -32,6 +34,19 @@ module RunLoop
32
34
  results_dir_trace = File.join(results_dir,"trace")
33
35
  FileUtils.mkdir_p(results_dir_trace)
34
36
 
37
+ script = File.join(results_dir,"_run_loop.js")
38
+
39
+
40
+ code = File.read(options[:script])
41
+ code = code.gsub(/\$PATH/, results_dir)
42
+
43
+ repl_path = File.join(results_dir,"repl-cmd.txt")
44
+ File.open(repl_path, "w") {|file| file.puts "0:UIALogger.logMessage('Listening for run loop commands');"}
45
+
46
+ File.open(script, "w") {|file| file.puts code}
47
+
48
+
49
+
35
50
  bundle_dir_or_bundle_id = options[:app] || ENV['APP_BUNDLE_PATH']
36
51
 
37
52
  unless bundle_dir_or_bundle_id
@@ -71,7 +86,7 @@ module RunLoop
71
86
  "-t", template,
72
87
  "\"#{bundle_dir_or_bundle_id}\"",
73
88
  "-e", "UIARESULTSPATH", results_dir,
74
- "-e", "UIASCRIPT", options[:script],
89
+ "-e", "UIASCRIPT", script,
75
90
  *(options[:instruments_args] || [])
76
91
  ]
77
92
 
@@ -90,7 +105,7 @@ module RunLoop
90
105
  f.write pid
91
106
  end
92
107
 
93
- return {:pid => pid, :results_dir => results_dir}
108
+ return {:pid => pid, :repl_path => repl_path, :results_dir => results_dir}
94
109
  end
95
110
 
96
111
  def self.automation_template
@@ -122,6 +137,31 @@ module RunLoop
122
137
  Core.run_with_options(options)
123
138
  end
124
139
 
140
+ def self.send_command(run_loop,cmd)
141
+ repl_path = run_loop[:repl_path]
142
+
143
+ if not cmd.is_a?(String)
144
+ raise "Illegal command #{cmd} (must be a string)"
145
+ end
146
+
147
+ cur = File.read(repl_path)
148
+
149
+ colon = cur.index(":")
150
+
151
+ if colon.nil?
152
+ raise "Illegal contents of #{repl_path}: #{cur}"
153
+ end
154
+ index = cur[0,colon].to_i + 1
155
+
156
+
157
+ tmp_cmd = File.join(File.dirname(repl_path), "__repl-cmd.txt")
158
+ File.open(tmp_cmd,"w") do |f|
159
+ f.write("#{index}:#{cmd}")
160
+ end
161
+
162
+ FileUtils.mv(tmp_cmd,repl_path)
163
+ end
164
+
125
165
  def self.stop(options)
126
166
  results_dir = options[:results_dir]
127
167
  pid = options[:pid] || IO.read(File.join(results_dir,"run_loop.pid"))
@@ -152,7 +192,7 @@ module RunLoop
152
192
  raise "Unknown type for :script key: #{options[:script].class}"
153
193
  end
154
194
  else
155
- script = Core.script_for_key(:dismiss)
195
+ script = Core.script_for_key(:run_loop)
156
196
  end
157
197
  script
158
198
  end
@@ -1,3 +1,3 @@
1
1
  module RunLoop
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/run_loop.gemspec CHANGED
@@ -11,10 +11,11 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "http://calaba.sh"
12
12
  s.summary = %q{Tools related to running Calabash iOS tests}
13
13
  s.description = %q{calabash-cucumber drives tests for native iOS apps. RunLoop provides a number of tools associated with running Calabash tests.}
14
- s.files = `git ls-files`.split("\n")
14
+ s.files = ["scripts/udidetect"].concat(`git ls-files`.split("\n"))
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.executables = "run-loop"
17
17
  s.require_paths = ["lib"]
18
18
 
19
19
  s.add_dependency( "thor" )
20
+ #s.add_dependency( "open4", "~> 1.3.0")
20
21
  end
@@ -0,0 +1,26 @@
1
+
2
+ if(typeof JSON!=='object'){JSON={};}
3
+ (function(){'use strict';function f(n){return n<10?'0'+n:n;}
4
+ if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
5
+ f(this.getUTCMonth()+1)+'-'+
6
+ f(this.getUTCDate())+'T'+
7
+ f(this.getUTCHours())+':'+
8
+ f(this.getUTCMinutes())+':'+
9
+ f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
10
+ var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
11
+ function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
12
+ if(typeof rep==='function'){value=rep.call(holder,key,value);}
13
+ switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
14
+ gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
15
+ v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v;}
16
+ if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){if(typeof rep[i]==='string'){k=rep[i];v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
17
+ v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
18
+ if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
19
+ rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
20
+ return str('',{'':value});};}
21
+ if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
22
+ return reviver.call(holder,key,value);}
23
+ text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
24
+ ('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
25
+ if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
26
+ throw new SyntaxError('JSON.parse');};}}());
data/scripts/json2.js ADDED
@@ -0,0 +1,486 @@
1
+ /*
2
+ json2.js
3
+ 2012-10-08
4
+
5
+ Public Domain.
6
+
7
+ NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
8
+
9
+ See http://www.JSON.org/js.html
10
+
11
+
12
+ This code should be minified before deployment.
13
+ See http://javascript.crockford.com/jsmin.html
14
+
15
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
16
+ NOT CONTROL.
17
+
18
+
19
+ This file creates a global JSON object containing two methods: stringify
20
+ and parse.
21
+
22
+ JSON.stringify(value, replacer, space)
23
+ value any JavaScript value, usually an object or array.
24
+
25
+ replacer an optional parameter that determines how object
26
+ values are stringified for objects. It can be a
27
+ function or an array of strings.
28
+
29
+ space an optional parameter that specifies the indentation
30
+ of nested structures. If it is omitted, the text will
31
+ be packed without extra whitespace. If it is a number,
32
+ it will specify the number of spaces to indent at each
33
+ level. If it is a string (such as '\t' or '&nbsp;'),
34
+ it contains the characters used to indent at each level.
35
+
36
+ This method produces a JSON text from a JavaScript value.
37
+
38
+ When an object value is found, if the object contains a toJSON
39
+ method, its toJSON method will be called and the result will be
40
+ stringified. A toJSON method does not serialize: it returns the
41
+ value represented by the name/value pair that should be serialized,
42
+ or undefined if nothing should be serialized. The toJSON method
43
+ will be passed the key associated with the value, and this will be
44
+ bound to the value
45
+
46
+ For example, this would serialize Dates as ISO strings.
47
+
48
+ Date.prototype.toJSON = function (key) {
49
+ function f(n) {
50
+ // Format integers to have at least two digits.
51
+ return n < 10 ? '0' + n : n;
52
+ }
53
+
54
+ return this.getUTCFullYear() + '-' +
55
+ f(this.getUTCMonth() + 1) + '-' +
56
+ f(this.getUTCDate()) + 'T' +
57
+ f(this.getUTCHours()) + ':' +
58
+ f(this.getUTCMinutes()) + ':' +
59
+ f(this.getUTCSeconds()) + 'Z';
60
+ };
61
+
62
+ You can provide an optional replacer method. It will be passed the
63
+ key and value of each member, with this bound to the containing
64
+ object. The value that is returned from your method will be
65
+ serialized. If your method returns undefined, then the member will
66
+ be excluded from the serialization.
67
+
68
+ If the replacer parameter is an array of strings, then it will be
69
+ used to select the members to be serialized. It filters the results
70
+ such that only members with keys listed in the replacer array are
71
+ stringified.
72
+
73
+ Values that do not have JSON representations, such as undefined or
74
+ functions, will not be serialized. Such values in objects will be
75
+ dropped; in arrays they will be replaced with null. You can use
76
+ a replacer function to replace those with JSON values.
77
+ JSON.stringify(undefined) returns undefined.
78
+
79
+ The optional space parameter produces a stringification of the
80
+ value that is filled with line breaks and indentation to make it
81
+ easier to read.
82
+
83
+ If the space parameter is a non-empty string, then that string will
84
+ be used for indentation. If the space parameter is a number, then
85
+ the indentation will be that many spaces.
86
+
87
+ Example:
88
+
89
+ text = JSON.stringify(['e', {pluribus: 'unum'}]);
90
+ // text is '["e",{"pluribus":"unum"}]'
91
+
92
+
93
+ text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
94
+ // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
95
+
96
+ text = JSON.stringify([new Date()], function (key, value) {
97
+ return this[key] instanceof Date ?
98
+ 'Date(' + this[key] + ')' : value;
99
+ });
100
+ // text is '["Date(---current time---)"]'
101
+
102
+
103
+ JSON.parse(text, reviver)
104
+ This method parses a JSON text to produce an object or array.
105
+ It can throw a SyntaxError exception.
106
+
107
+ The optional reviver parameter is a function that can filter and
108
+ transform the results. It receives each of the keys and values,
109
+ and its return value is used instead of the original value.
110
+ If it returns what it received, then the structure is not modified.
111
+ If it returns undefined then the member is deleted.
112
+
113
+ Example:
114
+
115
+ // Parse the text. Values that look like ISO date strings will
116
+ // be converted to Date objects.
117
+
118
+ myData = JSON.parse(text, function (key, value) {
119
+ var a;
120
+ if (typeof value === 'string') {
121
+ a =
122
+ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
123
+ if (a) {
124
+ return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
125
+ +a[5], +a[6]));
126
+ }
127
+ }
128
+ return value;
129
+ });
130
+
131
+ myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
132
+ var d;
133
+ if (typeof value === 'string' &&
134
+ value.slice(0, 5) === 'Date(' &&
135
+ value.slice(-1) === ')') {
136
+ d = new Date(value.slice(5, -1));
137
+ if (d) {
138
+ return d;
139
+ }
140
+ }
141
+ return value;
142
+ });
143
+
144
+
145
+ This is a reference implementation. You are free to copy, modify, or
146
+ redistribute.
147
+ */
148
+
149
+ /*jslint evil: true, regexp: true */
150
+
151
+ /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
152
+ call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
153
+ getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
154
+ lastIndex, length, parse, prototype, push, replace, slice, stringify,
155
+ test, toJSON, toString, valueOf
156
+ */
157
+
158
+
159
+ // Create a JSON object only if one does not already exist. We create the
160
+ // methods in a closure to avoid creating global variables.
161
+
162
+ if (typeof JSON !== 'object') {
163
+ JSON = {};
164
+ }
165
+
166
+ (function () {
167
+ 'use strict';
168
+
169
+ function f(n) {
170
+ // Format integers to have at least two digits.
171
+ return n < 10 ? '0' + n : n;
172
+ }
173
+
174
+ if (typeof Date.prototype.toJSON !== 'function') {
175
+
176
+ Date.prototype.toJSON = function (key) {
177
+
178
+ return isFinite(this.valueOf())
179
+ ? this.getUTCFullYear() + '-' +
180
+ f(this.getUTCMonth() + 1) + '-' +
181
+ f(this.getUTCDate()) + 'T' +
182
+ f(this.getUTCHours()) + ':' +
183
+ f(this.getUTCMinutes()) + ':' +
184
+ f(this.getUTCSeconds()) + 'Z'
185
+ : null;
186
+ };
187
+
188
+ String.prototype.toJSON =
189
+ Number.prototype.toJSON =
190
+ Boolean.prototype.toJSON = function (key) {
191
+ return this.valueOf();
192
+ };
193
+ }
194
+
195
+ var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
196
+ escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
197
+ gap,
198
+ indent,
199
+ meta = { // table of character substitutions
200
+ '\b': '\\b',
201
+ '\t': '\\t',
202
+ '\n': '\\n',
203
+ '\f': '\\f',
204
+ '\r': '\\r',
205
+ '"' : '\\"',
206
+ '\\': '\\\\'
207
+ },
208
+ rep;
209
+
210
+
211
+ function quote(string) {
212
+
213
+ // If the string contains no control characters, no quote characters, and no
214
+ // backslash characters, then we can safely slap some quotes around it.
215
+ // Otherwise we must also replace the offending characters with safe escape
216
+ // sequences.
217
+
218
+ escapable.lastIndex = 0;
219
+ return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
220
+ var c = meta[a];
221
+ return typeof c === 'string'
222
+ ? c
223
+ : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
224
+ }) + '"' : '"' + string + '"';
225
+ }
226
+
227
+
228
+ function str(key, holder) {
229
+
230
+ // Produce a string from holder[key].
231
+
232
+ var i, // The loop counter.
233
+ k, // The member key.
234
+ v, // The member value.
235
+ length,
236
+ mind = gap,
237
+ partial,
238
+ value = holder[key];
239
+
240
+ // If the value has a toJSON method, call it to obtain a replacement value.
241
+
242
+ if (value && typeof value === 'object' &&
243
+ typeof value.toJSON === 'function') {
244
+ value = value.toJSON(key);
245
+ }
246
+
247
+ // If we were called with a replacer function, then call the replacer to
248
+ // obtain a replacement value.
249
+
250
+ if (typeof rep === 'function') {
251
+ value = rep.call(holder, key, value);
252
+ }
253
+
254
+ // What happens next depends on the value's type.
255
+
256
+ switch (typeof value) {
257
+ case 'string':
258
+ return quote(value);
259
+
260
+ case 'number':
261
+
262
+ // JSON numbers must be finite. Encode non-finite numbers as null.
263
+
264
+ return isFinite(value) ? String(value) : 'null';
265
+
266
+ case 'boolean':
267
+ case 'null':
268
+
269
+ // If the value is a boolean or null, convert it to a string. Note:
270
+ // typeof null does not produce 'null'. The case is included here in
271
+ // the remote chance that this gets fixed someday.
272
+
273
+ return String(value);
274
+
275
+ // If the type is 'object', we might be dealing with an object or an array or
276
+ // null.
277
+
278
+ case 'object':
279
+
280
+ // Due to a specification blunder in ECMAScript, typeof null is 'object',
281
+ // so watch out for that case.
282
+
283
+ if (!value) {
284
+ return 'null';
285
+ }
286
+
287
+ // Make an array to hold the partial results of stringifying this object value.
288
+
289
+ gap += indent;
290
+ partial = [];
291
+
292
+ // Is the value an array?
293
+
294
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
295
+
296
+ // The value is an array. Stringify every element. Use null as a placeholder
297
+ // for non-JSON values.
298
+
299
+ length = value.length;
300
+ for (i = 0; i < length; i += 1) {
301
+ partial[i] = str(i, value) || 'null';
302
+ }
303
+
304
+ // Join all of the elements together, separated with commas, and wrap them in
305
+ // brackets.
306
+
307
+ v = partial.length === 0
308
+ ? '[]'
309
+ : gap
310
+ ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
311
+ : '[' + partial.join(',') + ']';
312
+ gap = mind;
313
+ return v;
314
+ }
315
+
316
+ // If the replacer is an array, use it to select the members to be stringified.
317
+
318
+ if (rep && typeof rep === 'object') {
319
+ length = rep.length;
320
+ for (i = 0; i < length; i += 1) {
321
+ if (typeof rep[i] === 'string') {
322
+ k = rep[i];
323
+ v = str(k, value);
324
+ if (v) {
325
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
326
+ }
327
+ }
328
+ }
329
+ } else {
330
+
331
+ // Otherwise, iterate through all of the keys in the object.
332
+
333
+ for (k in value) {
334
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
335
+ v = str(k, value);
336
+ if (v) {
337
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
338
+ }
339
+ }
340
+ }
341
+ }
342
+
343
+ // Join all of the member texts together, separated with commas,
344
+ // and wrap them in braces.
345
+
346
+ v = partial.length === 0
347
+ ? '{}'
348
+ : gap
349
+ ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
350
+ : '{' + partial.join(',') + '}';
351
+ gap = mind;
352
+ return v;
353
+ }
354
+ }
355
+
356
+ // If the JSON object does not yet have a stringify method, give it one.
357
+
358
+ if (typeof JSON.stringify !== 'function') {
359
+ JSON.stringify = function (value, replacer, space) {
360
+
361
+ // The stringify method takes a value and an optional replacer, and an optional
362
+ // space parameter, and returns a JSON text. The replacer can be a function
363
+ // that can replace values, or an array of strings that will select the keys.
364
+ // A default replacer method can be provided. Use of the space parameter can
365
+ // produce text that is more easily readable.
366
+
367
+ var i;
368
+ gap = '';
369
+ indent = '';
370
+
371
+ // If the space parameter is a number, make an indent string containing that
372
+ // many spaces.
373
+
374
+ if (typeof space === 'number') {
375
+ for (i = 0; i < space; i += 1) {
376
+ indent += ' ';
377
+ }
378
+
379
+ // If the space parameter is a string, it will be used as the indent string.
380
+
381
+ } else if (typeof space === 'string') {
382
+ indent = space;
383
+ }
384
+
385
+ // If there is a replacer, it must be a function or an array.
386
+ // Otherwise, throw an error.
387
+
388
+ rep = replacer;
389
+ if (replacer && typeof replacer !== 'function' &&
390
+ (typeof replacer !== 'object' ||
391
+ typeof replacer.length !== 'number')) {
392
+ throw new Error('JSON.stringify');
393
+ }
394
+
395
+ // Make a fake root object containing our value under the key of ''.
396
+ // Return the result of stringifying the value.
397
+
398
+ return str('', {'': value});
399
+ };
400
+ }
401
+
402
+
403
+ // If the JSON object does not yet have a parse method, give it one.
404
+
405
+ if (typeof JSON.parse !== 'function') {
406
+ JSON.parse = function (text, reviver) {
407
+
408
+ // The parse method takes a text and an optional reviver function, and returns
409
+ // a JavaScript value if the text is a valid JSON text.
410
+
411
+ var j;
412
+
413
+ function walk(holder, key) {
414
+
415
+ // The walk method is used to recursively walk the resulting structure so
416
+ // that modifications can be made.
417
+
418
+ var k, v, value = holder[key];
419
+ if (value && typeof value === 'object') {
420
+ for (k in value) {
421
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
422
+ v = walk(value, k);
423
+ if (v !== undefined) {
424
+ value[k] = v;
425
+ } else {
426
+ delete value[k];
427
+ }
428
+ }
429
+ }
430
+ }
431
+ return reviver.call(holder, key, value);
432
+ }
433
+
434
+
435
+ // Parsing happens in four stages. In the first stage, we replace certain
436
+ // Unicode characters with escape sequences. JavaScript handles many characters
437
+ // incorrectly, either silently deleting them, or treating them as line endings.
438
+
439
+ text = String(text);
440
+ cx.lastIndex = 0;
441
+ if (cx.test(text)) {
442
+ text = text.replace(cx, function (a) {
443
+ return '\\u' +
444
+ ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
445
+ });
446
+ }
447
+
448
+ // In the second stage, we run the text against regular expressions that look
449
+ // for non-JSON patterns. We are especially concerned with '()' and 'new'
450
+ // because they can cause invocation, and '=' because it can cause mutation.
451
+ // But just to be safe, we want to reject all unexpected forms.
452
+
453
+ // We split the second stage into 4 regexp operations in order to work around
454
+ // crippling inefficiencies in IE's and Safari's regexp engines. First we
455
+ // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
456
+ // replace all simple value tokens with ']' characters. Third, we delete all
457
+ // open brackets that follow a colon or comma or that begin the text. Finally,
458
+ // we look to see that the remaining characters are only whitespace or ']' or
459
+ // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
460
+
461
+ if (/^[\],:{}\s]*$/
462
+ .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
463
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
464
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
465
+
466
+ // In the third stage we use the eval function to compile the text into a
467
+ // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
468
+ // in JavaScript: it can begin a block or an object literal. We wrap the text
469
+ // in parens to eliminate the ambiguity.
470
+
471
+ j = eval('(' + text + ')');
472
+
473
+ // In the optional fourth stage, we recursively walk the new structure, passing
474
+ // each name/value pair to a reviver function for possible transformation.
475
+
476
+ return typeof reviver === 'function'
477
+ ? walk({'': j}, '')
478
+ : j;
479
+ }
480
+
481
+ // If the text is not JSON parseable, then a SyntaxError is thrown.
482
+
483
+ throw new SyntaxError('JSON.parse');
484
+ };
485
+ }
486
+ }());
@@ -56,7 +56,8 @@ UIATarget.onAlert = function (alert) {
56
56
 
57
57
  function performAction(action, data) {
58
58
  UIALogger.logMessage("perform action:" + action);
59
- var actionTaken = true;
59
+ var actionTaken = true,
60
+ res = null;
60
61
  switch (action) {
61
62
  case "setLocation":
62
63
  target.setLocation({"latitude":data.latitude, "longitude":data.longitude});
@@ -71,10 +72,20 @@ function performAction(action, data) {
71
72
  screenshot_count += 1;
72
73
  target.captureScreenWithName(data.name || ("screenshot_" + screenshot_count));
73
74
  break;
75
+ case "eval":
76
+ try {
77
+ res = eval(data);
78
+ } catch (e) {
79
+ if (e) {
80
+ UIALogger.logMessage(e.toString());
81
+ }
82
+ }
83
+ break;
74
84
  }
75
85
  if (actionTaken && !data.preserve) {
76
86
  target.frontMostApp().setPreferencesValueForKey(null, "__run_loop_action");
77
87
  }
88
+ return res;
78
89
 
79
90
  }
80
91
 
@@ -82,15 +93,32 @@ UIALogger.logStart("RunLoop");
82
93
 
83
94
  var app = target.frontMostApp(),
84
95
  val,
96
+ res,
85
97
  count = 0,
86
98
  action = null;
87
99
  while (true) {
88
- target.delay(0.3);
89
- val = app.preferencesValueForKey("__run_loop_action");
100
+ target.delay(1);
101
+ val = target.frontMostApp().preferencesValueForKey("__run_loop_action");
102
+ if (val)
103
+ UIALogger.logMessage(val);
104
+ else {
105
+ UIALogger.logMessage("null");
106
+ val = target.frontMostApp().preferencesValueForKey("x");
107
+ if (val)
108
+ UIALogger.logMessage(val.toString());
109
+ }
110
+
90
111
  if (val && typeof val == 'object') {
91
112
  action = val.action;
92
113
  performAction(action, val);
93
114
  }
115
+ else if (val && typeof val == 'string') {
116
+ res = performAction("eval", val);
117
+ if (res) {
118
+ UIALogger.logMessage(res.toString());
119
+ }
120
+ }
121
+
94
122
  count += 1;
95
123
  }
96
124
 
@@ -0,0 +1,125 @@
1
+ if(typeof JSON!=='object'){JSON={};}
2
+ (function(){'use strict';function f(n){return n<10?'0'+n:n;}
3
+ if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
4
+ f(this.getUTCMonth()+1)+'-'+
5
+ f(this.getUTCDate())+'T'+
6
+ f(this.getUTCHours())+':'+
7
+ f(this.getUTCMinutes())+':'+
8
+ f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
9
+ var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
10
+ function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
11
+ if(typeof rep==='function'){value=rep.call(holder,key,value);}
12
+ switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
13
+ gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
14
+ v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v;}
15
+ if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){if(typeof rep[i]==='string'){k=rep[i];v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
16
+ v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
17
+ if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
18
+ rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
19
+ return str('',{'':value});};}
20
+ if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
21
+ return reviver.call(holder,key,value);}
22
+ text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
23
+ ('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
24
+ if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
25
+ throw new SyntaxError('JSON.parse');};}}());
26
+
27
+ var commandPath = "$PATH";
28
+ if (!/\/$/.test(commandPath))
29
+ {
30
+ commandPath += "/";
31
+ }
32
+ commandPath += "repl-cmd.txt";
33
+
34
+ var Log = (function () {
35
+ // According to Appium,
36
+ //16384 is the buffer size used by instruments
37
+ var forceFlush = [],
38
+ N = 0, i = N;
39
+ if ("$MODE" == "FLUSH")
40
+ {
41
+ N = 16384
42
+ }
43
+ while(i--) { forceFlush[i] = "*"; }
44
+ forceFlush = forceFlush.join('');
45
+
46
+ return {
47
+ result: function (status, data) {
48
+ UIALogger.logMessage(JSON.stringify({"status":status, "value":data}));
49
+ if (forceFlush.length > 0) {
50
+ UIALogger.logMessage(forceFlush);
51
+ }
52
+ },
53
+ output: function (msg) {
54
+ UIALogger.logMessage(JSON.stringify({"output":msg}));
55
+ if (forceFlush.length > 0) {
56
+ UIALogger.logMessage(forceFlush);
57
+ }
58
+ }
59
+ };
60
+ })();
61
+
62
+ var target = null,
63
+ host = null;
64
+
65
+ var expectedIndex = 0,//expected index of next command
66
+ actualIndex,//actual index of next command by reading commandPath
67
+ index,//index of ':' char in command
68
+ exp,//expression to be eval'ed
69
+ result,//result of eval
70
+ input,//command
71
+ process;//host command process
72
+
73
+ while (true)
74
+ {
75
+ target = UIATarget.localTarget();
76
+ host = target.host();
77
+ target.delay(0.2);
78
+ try
79
+ {
80
+ process = host.performTaskWithPathArgumentsTimeout("/bin/cat",
81
+ [commandPath],
82
+ 2);
83
+
84
+ } catch (e)
85
+ {
86
+ Log.output("Timeout on cat...");
87
+ continue;
88
+ }
89
+ if (process.exitCode != 0)
90
+ {
91
+ Log.output("unable to execute /bin/cat " + commandPath + " exitCode " + process.exitCode + ". Error: " + process.stderr);
92
+ }
93
+ else
94
+ {
95
+ input = process.stdout;
96
+ try
97
+ {
98
+ index = input.indexOf(":", 0);
99
+ if (index > -1) {
100
+ actualIndex = parseInt(input.substring(0,index),10);
101
+ if (!isNaN(actualIndex) && actualIndex >= expectedIndex) {
102
+ exp = input.substring(index+1, input.length);
103
+ result = eval(exp);
104
+ }
105
+ else {//likely old command is lingering...
106
+ continue;
107
+ }
108
+ }
109
+ else {
110
+ continue;
111
+ }
112
+
113
+ }
114
+ catch (err)
115
+ {
116
+ Log.result("error", err.toString() + " " + (err.stack ? err.stack.toString() : ""));
117
+ expectedIndex++;
118
+ continue;
119
+ }
120
+
121
+ expectedIndex++;
122
+ Log.result("success",result);
123
+
124
+ }
125
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_loop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-18 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -36,6 +36,7 @@ executables:
36
36
  extensions: []
37
37
  extra_rdoc_files: []
38
38
  files:
39
+ - scripts/udidetect
39
40
  - .gitignore
40
41
  - .gitmodules
41
42
  - .irbrc
@@ -52,9 +53,11 @@ files:
52
53
  - lib/run_loop/core.rb
53
54
  - lib/run_loop/version.rb
54
55
  - run_loop.gemspec
56
+ - scripts/json2-min.js
57
+ - scripts/json2.js
55
58
  - scripts/run_dismiss_location.js
59
+ - scripts/run_loop.js
56
60
  - scripts/run_screenshooter.sh
57
- - scripts/udidetect
58
61
  - scripts/unix_instruments
59
62
  homepage: http://calaba.sh
60
63
  licenses: []
@@ -81,3 +84,4 @@ signing_key:
81
84
  specification_version: 3
82
85
  summary: Tools related to running Calabash iOS tests
83
86
  test_files: []
87
+ has_rdoc: