xmp2assert 11 → 12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/lib/xmp2assert/assertions.rb +12 -4
- data/lib/xmp2assert/renderer.rb +3 -3
- data/lib/xmp2assert/spawn.rb +8 -3
- data/lib/xmp2assert/template.erb +11 -30
- data/lib/xmp2assert/version.rb +1 -1
- data/lib/xmp2assert/xmp2rexp.rb +2 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2f9ee081b57585fdaa4fc1c04b600b67ed9fcd5
|
4
|
+
data.tar.gz: b32bbf297c76a0934b71281fb5e90f94608eb894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1cb6e90a0cd31ed34c49e85cf2c3c8cd0bd1c0311ba1b9d689f7ee0de19aa7a40feba7bb124025879f51fa53d64404f2037e96cafb80325197bda38e2325821
|
7
|
+
data.tar.gz: 4a47c5aedb2283c6a0acaf7832d3c8bbf525afeb613080ec24cbbbf4796f1dd87051526ce66c211d182218930ffef7e0cc4d579255631c9a55532e073af996f2
|
data/.rubocop.yml
CHANGED
@@ -36,8 +36,6 @@ require_relative 'spawn'
|
|
36
36
|
# Helper module that implements assertions.
|
37
37
|
module XMP2Assert::Assertions
|
38
38
|
include Test::Unit::Assertions
|
39
|
-
include XMP2Assert::XMP2Rexp
|
40
|
-
include XMP2Assert::Renderer
|
41
39
|
|
42
40
|
# Run a ruby script and assert for its comment. This is the main API.
|
43
41
|
#
|
@@ -52,7 +50,7 @@ module XMP2Assert::Assertions
|
|
52
50
|
def assert_xmp script, message = nil, stdin_data: '', **opts
|
53
51
|
qscript = XMP2Assert::Quasifile.new script
|
54
52
|
qf, qo, qe, qx = XMP2Assert::Converter.convert qscript
|
55
|
-
render qf, qx do |f|
|
53
|
+
XMP2Assert::Renderer.render qf, qx do |f|
|
56
54
|
XMP2Assert::Spawn.new f, **opts do |_, i, o, e, r, t|
|
57
55
|
i.write stdin_data
|
58
56
|
i.close
|
@@ -73,13 +71,14 @@ module XMP2Assert::Assertions
|
|
73
71
|
end
|
74
72
|
assert_xmp_raw qo, out.value, message unless qo.empty?
|
75
73
|
assert_xmp_raw qe, err.value, message unless qe.empty?
|
74
|
+
stderr_pass_through qe, err
|
76
75
|
end
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
80
79
|
# :TODO: tbw
|
81
80
|
def assert_xmp_raw xmp, actual, message = nil
|
82
|
-
expected = xmp2rexp xmp
|
81
|
+
expected = XMP2Assert::XMP2Rexp.xmp2rexp xmp
|
83
82
|
|
84
83
|
raise unless expected.match actual
|
85
84
|
rescue
|
@@ -96,4 +95,13 @@ module XMP2Assert::Assertions
|
|
96
95
|
else
|
97
96
|
return self # or...?
|
98
97
|
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def stderr_pass_through qe, err
|
102
|
+
return unless $-w
|
103
|
+
return unless qe.empty?
|
104
|
+
return if err.value.empty?
|
105
|
+
STDERR.puts err.value
|
106
|
+
end
|
99
107
|
end
|
data/lib/xmp2assert/renderer.rb
CHANGED
@@ -30,12 +30,12 @@ require_relative 'namespace'
|
|
30
30
|
require_relative 'quasifile'
|
31
31
|
|
32
32
|
# Compiles a {XMP2Assert::Quasifile} into a separate ruby script.
|
33
|
-
|
33
|
+
class XMP2Assert::Renderer
|
34
34
|
|
35
35
|
# I learned this handy "super-private" maneuver from @a_matsuda
|
36
36
|
# cf: https://github.com/rails/rails/pull/27363/files
|
37
37
|
using Module.new {
|
38
|
-
refine XMP2Assert::Renderer do
|
38
|
+
refine XMP2Assert::Renderer.singleton_class do
|
39
39
|
private
|
40
40
|
|
41
41
|
myself = Pathname.new __FILE__
|
@@ -59,7 +59,7 @@ module XMP2Assert::Renderer
|
|
59
59
|
# @param exception [String] :TBD:
|
60
60
|
# @return [File] rendered file, if no block is given.
|
61
61
|
# @yieldparam [File] rendered file, if block is given.
|
62
|
-
def render qfile, exception = nil
|
62
|
+
def self.render qfile, exception = nil
|
63
63
|
s = erb qfile, exception
|
64
64
|
if defined? yield
|
65
65
|
Tempfile.create '' do |f|
|
data/lib/xmp2assert/spawn.rb
CHANGED
@@ -50,11 +50,16 @@ class XMP2Assert::Spawn
|
|
50
50
|
begin
|
51
51
|
pid = Process.spawn(*argv, opts)
|
52
52
|
theirs.each(&:close)
|
53
|
-
stdin, stdout, stdrrr, rx, tx = *
|
53
|
+
stdin, stdout, stdrrr, rx, tx = *ours
|
54
54
|
yield pid, stdin, stdout, stdrrr, rx, tx
|
55
55
|
ensure
|
56
|
-
|
57
|
-
|
56
|
+
begin
|
57
|
+
ours.each(&:close)
|
58
|
+
rescue IOError
|
59
|
+
# OK, nothing can be done by us for closed streams.
|
60
|
+
ensure
|
61
|
+
Process.waitpid pid if pid
|
62
|
+
end
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
data/lib/xmp2assert/template.erb
CHANGED
@@ -32,38 +32,19 @@ saved_binding = TOPLEVEL_BINDING.dup
|
|
32
32
|
rx = IO.for_fd ARGV.shift.to_i, 'rb'
|
33
33
|
tx = IO.for_fd ARGV.shift.to_i, 'wb'
|
34
34
|
|
35
|
-
|
36
|
-
refine Kernel do
|
35
|
+
private
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
tx.write str
|
49
|
-
tx.flush
|
50
|
-
if rx.gets then
|
51
|
-
return true
|
52
|
-
else
|
53
|
-
Process.exit false
|
54
|
-
end
|
55
|
-
end
|
37
|
+
define_method :xmp2assert_assert do |xmp, expr, bt = caller(3)|
|
38
|
+
bt.reject! {|i| i.start_with? __FILE__ }
|
39
|
+
str = Marshal.dump [xmp, expr.inspect, bt]
|
40
|
+
tx.puts str.length
|
41
|
+
tx.write str
|
42
|
+
tx.flush
|
43
|
+
if rx.gets then
|
44
|
+
return true
|
45
|
+
else
|
46
|
+
Process.exit false
|
56
47
|
end
|
57
|
-
}
|
58
|
-
|
59
|
-
# Simulates test-unit.
|
60
|
-
# @param xmp [String] expected pattern of inspect.
|
61
|
-
# @param expr [Object] object to check.
|
62
|
-
# @param message [String] extra failure message.
|
63
|
-
# @note assertion is done in parent process, not in it.
|
64
|
-
def xmp2assert_assert xmp, expr, c = caller(3)
|
65
|
-
c.reject! {|i| i.start_with? __FILE__ }
|
66
|
-
return assert_xmp_send xmp, expr.inspect, c
|
67
48
|
end
|
68
49
|
|
69
50
|
# Here we go.
|
data/lib/xmp2assert/version.rb
CHANGED
data/lib/xmp2assert/xmp2rexp.rb
CHANGED
@@ -38,13 +38,11 @@ require_relative 'namespace'
|
|
38
38
|
# To reroute the problem, here we convert a XMP comment into a regular
|
39
39
|
# expression. The idea behind this is the diff process hook implemented in
|
40
40
|
# https://github.com/ruby/chkbuild
|
41
|
-
|
42
|
-
module_function
|
43
|
-
|
41
|
+
class XMP2Assert::XMP2Rexp
|
44
42
|
# Generates a regular expression that roughly matches the input.
|
45
43
|
# @param xmp [String] example.
|
46
44
|
# @return [Regexp] converted regular expression.
|
47
|
-
def xmp2rexp xmp
|
45
|
+
def self.xmp2rexp xmp
|
48
46
|
# :NOTE: we are editing regular expressions using regular expressions. In
|
49
47
|
# order to hack this method you must be a seasoned regular expression
|
50
48
|
# craftsperson who can count backslashes at ease.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmp2assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '12'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Urabe, Shyouhei
|
@@ -247,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
247
|
version: '0'
|
248
248
|
requirements: []
|
249
249
|
rubyforge_project:
|
250
|
-
rubygems_version: 2.
|
250
|
+
rubygems_version: 2.5.2
|
251
251
|
signing_key:
|
252
252
|
specification_version: 4
|
253
253
|
summary: auto-generate assertions from `# =>` comments
|