livetext 0.9.13 → 0.9.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.lt3 +2 -2
- data/imports/bookish.rb +288 -0
- data/imports/calibre.rb +28 -0
- data/imports/livemagick.rb +133 -0
- data/imports/markdown.rb +44 -0
- data/imports/markdown_importable.rb +46 -0
- data/imports/pyggish.rb +204 -0
- data/imports/tutorial.rb +95 -0
- data/lib/cmdargs.rb +93 -0
- data/lib/errors.rb +4 -2
- data/lib/formatline.rb +56 -83
- data/lib/functions.rb +1 -1
- data/lib/handler/icanhaz.rb +35 -0
- data/lib/handler.rb +1 -0
- data/lib/helpers.rb +177 -4
- data/lib/livetext.rb +20 -139
- data/lib/parser/file.rb +8 -0
- data/lib/parser/general.rb +1 -1
- data/lib/parser/import.rb +1 -3
- data/lib/parser/mixin.rb +22 -30
- data/lib/parser/set.rb +35 -26
- data/lib/parser/string.rb +19 -4
- data/lib/processor.rb +2 -12
- data/lib/standard.rb +73 -107
- data/lib/userapi.rb +1 -4
- data/livetext.gemspec +2 -1
- data/plugin/bookish.rb +26 -22
- data/plugin/calibre.rb +1 -1
- data/plugin/livemagick.rb +10 -10
- data/plugin/markdown.rb +13 -11
- data/plugin/pyggish.rb +94 -84
- data/plugin/tutorial.rb +10 -5
- data/test/snapshots/OMIT.txt +11 -0
- data/test/snapshots/clusion.txt +84 -0
- data/test/snapshots/error_inc_line_num/match-error.txt +1 -0
- data/test/snapshots/error_invalid_name/match-error.txt +1 -0
- data/test/snapshots/error_line_num/match-error.txt +1 -0
- data/test/snapshots/error_mismatched_end/expected-output.txt +0 -2
- data/test/snapshots/error_mismatched_end/match-error.txt +1 -0
- data/test/snapshots/error_missing_end/match-error.txt +1 -0
- data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
- data/test/snapshots/error_no_such_copy/source.lt3 +0 -1
- data/test/snapshots/error_no_such_inc/match-error.txt +1 -0
- data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
- data/test/snapshots/icanhaz/expected-output.txt +5 -0
- data/test/snapshots/icanhaz/match-error.txt +1 -0
- data/test/snapshots/icanhaz/simple_import.rb +5 -0
- data/test/snapshots/{error_no_such_mixin/actual-output.txt → icanhaz/source.lt3} +3 -4
- data/test/snapshots/{error_invalid_name/actual-output.txt → icanhaz2/expected-error.txt} +0 -0
- data/test/snapshots/icanhaz2/expected-output.txt +6 -0
- data/test/snapshots/icanhaz2/simple_canhaz.rb +5 -0
- data/test/snapshots/icanhaz2/source.lt3 +6 -0
- data/test/snapshots/predef_vars/match-output.txt +6 -0
- data/test/snapshots/{error_no_such_copy/actual-output.txt → simple_import/expected-error.txt} +0 -0
- data/test/snapshots/simple_import/expected-output.txt +7 -0
- data/test/snapshots/simple_import/simple_import.rb +5 -0
- data/test/snapshots/simple_import/source.lt3 +7 -0
- data/test/snapshots/simple_include/source.lt3 +0 -1
- data/test/snapshots.rb +103 -107
- data/test/unit/all.rb +1 -0
- data/test/unit/formatline.rb +650 -0
- data/test/unit/parser/general.rb +21 -21
- data/test/unit/parser/importable.rb +1 -1
- data/test/unit/parser/mixin.rb +2 -2
- data/test/unit/parser/set.rb +19 -12
- data/test/unit/parser/string.rb +14 -14
- data/test/unit/parser.rb +2 -0
- metadata +37 -46
- data/test/formatting.rb +0 -103
- data/test/snapshots/error_inc_line_num/actual-error.txt +0 -1
- data/test/snapshots/error_inc_line_num/actual-output.txt +0 -13
- data/test/snapshots/error_inc_line_num/expected-err-line1match.txt +0 -1
- data/test/snapshots/error_inc_line_num/out-sdiff.txt +0 -14
- data/test/snapshots/error_invalid_name/actual-error.txt +0 -10
- data/test/snapshots/error_invalid_name/expected-err-line1match.txt +0 -1
- data/test/snapshots/error_invalid_name/out-sdiff.txt +0 -6
- data/test/snapshots/error_line_num/actual-error.txt +0 -1
- data/test/snapshots/error_line_num/actual-output.txt +0 -5
- data/test/snapshots/error_line_num/expected-err-line1match.txt +0 -1
- data/test/snapshots/error_line_num/out-sdiff.txt +0 -6
- data/test/snapshots/error_mismatched_end/actual-error.txt +0 -1
- data/test/snapshots/error_mismatched_end/actual-output.txt +0 -8
- data/test/snapshots/error_mismatched_end/expected-err-line1match.txt +0 -1
- data/test/snapshots/error_mismatched_end/out-sdiff.txt +0 -9
- data/test/snapshots/error_missing_end/actual-error.txt +0 -1
- data/test/snapshots/error_missing_end/actual-output.txt +0 -5
- data/test/snapshots/error_missing_end/expected-err-line1match.txt +0 -1
- data/test/snapshots/error_missing_end/out-sdiff.txt +0 -6
- data/test/snapshots/error_name_not_permitted/OLD-exp-out +0 -4
- data/test/snapshots/error_no_such_copy/actual-error.txt +0 -10
- data/test/snapshots/error_no_such_copy/expected-err-line1match.txt +0 -1
- data/test/snapshots/error_no_such_copy/out-sdiff.txt +0 -5
- data/test/snapshots/error_no_such_inc/actual-error.txt +0 -10
- data/test/snapshots/error_no_such_inc/actual-output.txt +0 -0
- data/test/snapshots/error_no_such_inc/expected-err-line1match.txt +0 -1
- data/test/snapshots/error_no_such_inc/out-sdiff.txt +0 -6
- data/test/snapshots/error_no_such_mixin/actual-error.txt +0 -1
- data/test/snapshots/error_no_such_mixin/expected-err-line1match.txt +0 -1
- data/test/snapshots/error_no_such_mixin/out-sdiff.txt +0 -12
- data/test/snapshots/lines.txt +0 -124
- data/test/snapshots/predef_vars/actual-error.txt +0 -0
- data/test/snapshots/predef_vars/actual-output.txt +0 -6
- data/test/snapshots/predef_vars/expected-output.txt +0 -6
- data/test/snapshots/predef_vars/out-sdiff.txt +0 -7
- data/test/snapshots/simple_mixin/actual-error.txt +0 -2
- data/test/snapshots/simple_mixin/actual-output.txt +0 -4
- data/test/snapshots/simple_mixin/out-sdiff.txt +0 -6
- data/test/unit/parse_misc.rb +0 -60
- data/test/unit/parse_set.rb +0 -157
data/test/snapshots.rb
CHANGED
@@ -8,17 +8,27 @@ Snapshots...
|
|
8
8
|
NOTE that the external_files method has been replaced by the Snapshot class.
|
9
9
|
|
10
10
|
You can add any ordinary test method above. But so far, most of these tests simply
|
11
|
-
call
|
11
|
+
call Snapshot.new
|
12
12
|
|
13
|
-
|
13
|
+
It works this way:
|
14
14
|
- If the test (caller) method is test_my_silly_feature, then we will
|
15
15
|
look for a directory called snapshots/my_silly_feature
|
16
|
-
- In here, there must be a source.lt3
|
17
|
-
-
|
16
|
+
- In here, there must be a source.lt3
|
17
|
+
- ...and also either expected-output.txt OR match-output.txt (not both)
|
18
|
+
- ...and also either expected-error.txt OR match-error.txt (not both)
|
19
|
+
- Technically, any existing file can be empty
|
20
|
+
- The expected-* files are "literal" data
|
21
|
+
* compared byte-for-byte
|
22
|
+
* watch spaces and bad regexes, etc. #duh
|
23
|
+
* each of these files corresponds to a single assertion
|
24
|
+
- A match-* file has two entries per line:
|
25
|
+
* a ONE-BASED line number (in actual-* file)
|
26
|
+
* a String OR a Regexp (to match against that line)
|
27
|
+
* If there is nonsense here, it currently isn't caught
|
28
|
+
* each of these files MAY correspond to many assertions
|
18
29
|
- We run livetext on the source and compare actual vs expected (stdout, stderr)
|
19
|
-
- The
|
30
|
+
- The error output gets checked first (expected or match), THEN standard output
|
20
31
|
- Of course, both must compare correctly for the test to pass
|
21
|
-
- See also: match*
|
22
32
|
=end
|
23
33
|
|
24
34
|
|
@@ -33,6 +43,69 @@ class TestingLivetext < MiniTest::Test
|
|
33
43
|
EXP_OUT, EXP_ERR = "expected-output.txt", "expected-error.txt"
|
34
44
|
MATCH_OUT, MATCH_ERR = "match-output.txt", "match-error.txt"
|
35
45
|
|
46
|
+
TTY = File.open("/dev/tty","w")
|
47
|
+
|
48
|
+
def self.get_dir # FIXME - uh what?
|
49
|
+
cmdline = ARGV.first == "cmdline" # FIXME remove??
|
50
|
+
if cmdline
|
51
|
+
dir = "../"
|
52
|
+
Dir.chdir `livetext --path`.chomp.chomp
|
53
|
+
else
|
54
|
+
dir = ""
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
args = ARGV - ["cmdline"]
|
59
|
+
|
60
|
+
dir = self.get_dir
|
61
|
+
|
62
|
+
Data = "#{dir}test/snapshots"
|
63
|
+
Dir.chdir(Data)
|
64
|
+
|
65
|
+
TestDirs = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
|
66
|
+
|
67
|
+
|
68
|
+
def self.filter # TODO move subset/omit logic here??
|
69
|
+
all = Dir.entries(Data).reject {|fname| ! File.directory?(fname) } - %w[. ..]
|
70
|
+
included, excluded = [], []
|
71
|
+
@iflag, @eflag = true, false # defaults to INCLUDE
|
72
|
+
control = File.new("clusion.txt")
|
73
|
+
control.each_line do |line|
|
74
|
+
line.sub!(/#.*/, "")
|
75
|
+
line.strip!
|
76
|
+
lower = line.downcase
|
77
|
+
dejavu = false
|
78
|
+
case
|
79
|
+
when lower.empty?
|
80
|
+
# ignore
|
81
|
+
when lower == "default include all"
|
82
|
+
raise "Only one 'default' allowed" if dejavu
|
83
|
+
@iflag, @eflag = true, false # defaults to INCLUDE
|
84
|
+
dejavu = true
|
85
|
+
when lower == "default exclude all"
|
86
|
+
raise "Only one 'default' allowed" if dejavu
|
87
|
+
@iflag, @eflag = false, true
|
88
|
+
dejavu = true
|
89
|
+
when lower == "quit"
|
90
|
+
break
|
91
|
+
when lower[0] == "i"
|
92
|
+
TTY.puts "Warning: Can't include with 'i' when that is default" if @iflag
|
93
|
+
included << line.split(" ", 2)[1] # add to included
|
94
|
+
when lower[0] == "x"
|
95
|
+
TTY.puts "Warning: Can't exclude with 'x' when that is default" if @eflag
|
96
|
+
excluded << line.split(" ", 2)[1] # add to excluded
|
97
|
+
# add to excluded
|
98
|
+
end
|
99
|
+
[included, excluded]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
i, e = self.filter
|
104
|
+
p i
|
105
|
+
p e
|
106
|
+
|
107
|
+
exit
|
108
|
+
|
36
109
|
def initialize(base, assertion = nil)
|
37
110
|
@assertion = assertion
|
38
111
|
@base = base
|
@@ -43,7 +116,8 @@ class TestingLivetext < MiniTest::Test
|
|
43
116
|
@match_out = File.exist?(MATCH_OUT)
|
44
117
|
@match_err = File.exist?(MATCH_ERR)
|
45
118
|
end
|
46
|
-
bad_files = (@literal_out && @match_out) || (@literal_err && @match_err)
|
119
|
+
bad_files = (@literal_out && @match_out) || (@literal_err && @match_err) ||
|
120
|
+
(! @literal_out && ! @match_out)
|
47
121
|
raise "Inconsistent structure for #@base" if bad_files
|
48
122
|
end
|
49
123
|
|
@@ -58,13 +132,12 @@ class TestingLivetext < MiniTest::Test
|
|
58
132
|
info = "Expected line #{line_num} of #{actual.inspect} to match #{item.inspect} (was: #{lines[line_num].inspect})"
|
59
133
|
good = item === lines[line_num]
|
60
134
|
@errors = true unless good
|
61
|
-
# assert item === lines[line_num], info # string or regex
|
62
135
|
@assertion.call item === lines[line_num], info # string or regex
|
63
136
|
end
|
64
137
|
end
|
65
138
|
|
66
139
|
def sdiff(f1, f2, out)
|
67
|
-
File.open(out, "w") {|file| file.puts "#{'%-60s'% '
|
140
|
+
File.open(out, "w") {|file| file.puts "#{'%-60s'% 'ACTUAL'}| #{'%-60s'% 'EXPECTED'}" }
|
68
141
|
system("/usr/bin/sdiff -t -w 121 #{f1} #{f2} >>#{out}")
|
69
142
|
end
|
70
143
|
|
@@ -75,8 +148,7 @@ class TestingLivetext < MiniTest::Test
|
|
75
148
|
@errors = true if not same
|
76
149
|
file = "out-sdiff.txt"
|
77
150
|
sdiff(ACTUAL_OUT, EXP_OUT, file)
|
78
|
-
|
79
|
-
@assertion.call same, "Discrepancy in STDOUT - see #@base/#{file}"
|
151
|
+
@assertion.call same, "Discrepancy in STDOUT - see #{file} in test/snapshots/#@base"
|
80
152
|
else
|
81
153
|
check_matches(ACTUAL_OUT, MATCH_OUT)
|
82
154
|
end
|
@@ -89,8 +161,7 @@ class TestingLivetext < MiniTest::Test
|
|
89
161
|
@errors = true if not same
|
90
162
|
file = "err-sdiff.txt"
|
91
163
|
sdiff(ACTUAL_ERR, EXP_ERR, file)
|
92
|
-
|
93
|
-
@assertion.call same, "Discrepancy in STDERR - see #@base/#{file}"
|
164
|
+
@assertion.call same, "Discrepancy in STDERR - see #{file} in test/snapshots/#@base"
|
94
165
|
else
|
95
166
|
check_matches(ACTUAL_ERR, MATCH_ERR)
|
96
167
|
end
|
@@ -106,57 +177,34 @@ class TestingLivetext < MiniTest::Test
|
|
106
177
|
Dir.chdir(@base) do
|
107
178
|
cmd = "../../../bin/livetext #{SOURCE} >#{ACTUAL_OUT} 2>#{ACTUAL_ERR}"
|
108
179
|
system(cmd)
|
109
|
-
check_stdout
|
110
180
|
check_stderr
|
181
|
+
check_stdout
|
111
182
|
cleanup
|
112
183
|
end
|
113
184
|
end
|
114
185
|
end
|
115
186
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
items = []
|
131
|
-
short_tests = File.open("lines.txt")
|
132
|
-
loop do
|
133
|
-
4.times { items << short_tests.gets.chomp }
|
134
|
-
# Blank line terminates each "stanza"
|
135
|
-
raise "Oops? #{items.inspect}" unless items.last.empty?
|
136
|
-
TestLines << items
|
137
|
-
break if short_tests.eof?
|
138
|
-
end
|
139
|
-
|
140
|
-
if File.size("subset.txt") == 0
|
141
|
-
puts "Defining via TestLines"
|
142
|
-
TestLines.each.with_index do |item, num|
|
143
|
-
msg, src, exp, blank = *item
|
144
|
-
define_method("test_formatting_#{num}") do
|
145
|
-
actual = FormatLine.parse!(src)
|
146
|
-
if exp[0] == "/" # regex!
|
147
|
-
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
148
|
-
assert_match(exp, actual, msg)
|
149
|
-
else
|
150
|
-
assert_equal(exp, actual, msg)
|
151
|
-
end
|
152
|
-
end
|
187
|
+
if args.empty?
|
188
|
+
selected = File.readlines("subset.txt").map(&:chomp)
|
189
|
+
omitfile = "OMIT.txt"
|
190
|
+
omitted = File.readlines(omitfile).map(&:chomp)
|
191
|
+
omitted.reject! {|line| line.start_with?("#") }
|
192
|
+
omit_names = omitted.map {|line| line.split.first }
|
193
|
+
STDERR.puts
|
194
|
+
STDERR.puts " >>> Warning: Omitting #{omitted.size} snapshot tests:\n "
|
195
|
+
indented = " "*7
|
196
|
+
omitted.each do |line|
|
197
|
+
STDERR.print indented
|
198
|
+
name, info = line.split(" ", 2)
|
199
|
+
STDERR.printf "%-20s %s\n", name, info
|
153
200
|
end
|
201
|
+
STDERR.puts
|
202
|
+
wanted = selected.empty? ? TestDirs : selected
|
203
|
+
Subset = wanted - omit_names
|
204
|
+
else
|
205
|
+
Subset = args
|
154
206
|
end
|
155
207
|
|
156
|
-
TestDirs = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
|
157
|
-
selected = File.readlines("subset.txt").map(&:chomp)
|
158
|
-
Subset = selected.empty? ? TestDirs : selected
|
159
|
-
|
160
208
|
Subset.each do |tdir|
|
161
209
|
define_method("test_#{tdir}") do
|
162
210
|
myproc = Proc.new {|bool, info| assert bool, info }
|
@@ -164,56 +212,4 @@ class TestingLivetext < MiniTest::Test
|
|
164
212
|
this.run
|
165
213
|
end
|
166
214
|
end
|
167
|
-
|
168
|
-
def green(str)
|
169
|
-
"[32m" + str.to_s + "[0m"
|
170
|
-
end
|
171
|
-
|
172
|
-
def red(str)
|
173
|
-
"[31m" + str.to_s + "[0m"
|
174
|
-
end
|
175
|
-
|
176
|
-
def sdiff(which, f1, f2, out, rx)
|
177
|
-
return "\n >>> No match for std#{which}!" if rx
|
178
|
-
File.open(out, "w") {|file| file.puts "#{'%-60s'% 'EXPECTED'}| #{'%-60s'% 'ACTUAL'}" }
|
179
|
-
system("/usr/bin/sdiff -t -w 121 #{f1} #{f2} >>#{out}")
|
180
|
-
return "\n >>> Unexpected std#{which}! See #{out}"
|
181
|
-
end
|
182
|
-
|
183
|
-
def external_files(base)
|
184
|
-
Dir.chdir(base) do
|
185
|
-
src, out, exp = "source.lt3", "/tmp/#{base}--actual-output.txt", "expected-output.txt"
|
186
|
-
err, erx = "/tmp/#{base}--actual-error.txt", "expected-error.txt"
|
187
|
-
|
188
|
-
# New features - match out/err by regex
|
189
|
-
expout_regex = "expected-out-line1match.txt"
|
190
|
-
experr_regex = "expected-err-line1match.txt"
|
191
|
-
|
192
|
-
cmd = "livetext #{src} >#{out} 2>#{err}"
|
193
|
-
system(cmd)
|
194
|
-
|
195
|
-
output = File.read(out)
|
196
|
-
errors = File.read(err)
|
197
|
-
rx_out = rx_err = nil
|
198
|
-
|
199
|
-
expected = File.exist?(expout_regex) ? rx_out = /#{Regexp.escape(File.read(expout_regex).chomp)}/ : File.read(exp)
|
200
|
-
errexp = File.exist?(experr_regex) ? rx_err = /#{Regexp.escape(File.read(experr_regex).chomp)}/ : File.read(erx)
|
201
|
-
|
202
|
-
out_ok = rx_out ? output =~ rx_out : output == expected
|
203
|
-
err_ok = rx_err ? errors =~ rx_err : errors == errexp
|
204
|
-
|
205
|
-
system("mkdir -p /tmp/#{base}")
|
206
|
-
bad_out = bad_err = nil
|
207
|
-
bad_out = sdiff("out", exp, out, "/tmp/#{base}/exp.out.sdiff", rx_out) unless out_ok
|
208
|
-
bad_err = sdiff("err", erx, err, "/tmp/#{base}/exp.err.sdiff", rx_err) unless err_ok
|
209
|
-
|
210
|
-
assert(err_ok, bad_err)
|
211
|
-
assert(out_ok, bad_out)
|
212
|
-
# only on success
|
213
|
-
system("rm -rf #{out} #{err} /tmp/#{base}") if out_ok && err_ok
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
215
|
end
|
218
|
-
|
219
|
-
|
data/test/unit/all.rb
CHANGED