forked from XRPLF/rippled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatmans-belt.coffee
More file actions
109 lines (82 loc) · 2.75 KB
/
batmans-belt.coffee
File metadata and controls
109 lines (82 loc) · 2.75 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
################################### REQUIRES ###################################
fs = require 'fs'
testutils = require './testutils'
################################### REQUIRES ###################################
exports.pretty_json = (v) -> JSON.stringify(v, undefined, 2)
exports.beast_configured = beast_configured = (k, v) ->
'''
A very naive regex search in $repo_root/src/BeastConfig.h
@k the name of the macro
@v the value as a string expected
@return {Boolean} k's configured value, trimmed, is v
'''
beast_configured.buf ?= fs.readFileSync("#{__dirname}/../src/BeastConfig.h")
pattern = "^#define\\s+#{k}\\s+(.*?)$"
res = (new RegExp(pattern, 'm').exec(beast_configured.buf))
return false if res == null
actual = res[1].trim()
return v == actual
exports.server_setup_teardown = (options) ->
{setup_func, teardown_func, post_setup, server_opts} = options ? {}
context = null
setup_func ?= setup
teardown_func ?= teardown
setup_func (done) ->
context = @
testutils.build_setup(server_opts).call @, ->
if post_setup?
post_setup(context, done)
else
done()
teardown_func (done) ->
testutils.build_teardown().call context, done
# We turn a function to access the `context`, if we returned it now, it
# would be null (DUH ;)
-> context
exports.str_ends_with = ends_with = (s, suffix) ->
~s.indexOf(suffix, s.length - suffix.length)
exports.skip_or_only = (title, test_or_suite) ->
if ends_with title, '_only'
test_or_suite.only
else if ends_with title, '_skip'
test_or_suite.skip
else
test_or_suite
exports.is_focused_test = (test_name) -> ends_with test_name, '_only'
class BailError extends Error
constructor: (@message) ->
@message ?= "Failed test due to relying on prior failed tests"
exports.suite_test_bailer = () ->
bailed = false
bail = (e) -> bailed = true
suiteSetup ->
process.on 'uncaughtException', bail
suiteTeardown ->
process.removeListener 'uncaughtException', bail
wrapper = (test_func) ->
test = (title, fn) ->
wrapped = (done) ->
if not bailed
fn(done)
else
# We could do this, but it's just noisy
if process.env.BAIL_PASSES
done()
else
done(new BailError)
test_func title, wrapped
test.only = test_func.only
test.skip = test_func.skip
return test
wrapper(global.test)
exports.submit_for_final = (tx, done) ->
'''
This helper submits a transaction, and once it's proposed sends a ledger
accept so the transaction will finalize.
'''
tx.on 'submitted', (m) ->
ter = (m.engine_result ? '').slice(0, 3)
if ter in ['tes', 'tec']
tx.remote.ledger_accept()
tx.on 'final', (m) -> done(m)
tx.submit()