livetext 0.9.13 → 0.9.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/errors.rb +4 -2
- data/lib/functions.rb +1 -1
- data/lib/helpers.rb +4 -0
- data/lib/livetext.rb +15 -9
- data/lib/parser/general.rb +1 -1
- data/lib/parser/mixin.rb +1 -7
- data/lib/processor.rb +1 -8
- data/lib/standard.rb +6 -11
- data/lib/userapi.rb +0 -4
- data/test/all.rb +1 -0
- data/test/formatting-tests.rb +35 -0
- data/test/snapshots/OMIT.txt +10 -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_inc/match-error.txt +1 -0
- data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
- data/test/snapshots/{lines.txt → formatting-tests.txt} +0 -0
- data/test/snapshots/predef_vars/match-output.txt +6 -0
- data/test/snapshots.rb +41 -92
- data/test/unit/parser/general.rb +21 -21
- data/test/unit/parser/mixin.rb +1 -1
- data/test/unit/parser.rb +2 -0
- metadata +13 -44
- 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/actual-output.txt +0 -0
- 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/actual-output.txt +0 -0
- 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/actual-output.txt +0 -11
- 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/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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9e6ad9c8d933b361da03fadc6cc4d28e0a8b699f8f50e434db9bf41f0b9d66b
|
4
|
+
data.tar.gz: 49e59704162aea72ac92122d69f0006591856b9fe09f2b2fdbf6843b7253b80b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74b1b06e0bc91d976c0f60a2136ed8bb1c4d2d5ba33359620752b44a51918a89fbba2cec9c542ae12a6368de82bdc4db64b30a4d95146caab4e5a290f9c7fa8b
|
7
|
+
data.tar.gz: ed0c0fa3b4da538ddbd31cd799a84f5647d45a369f0f45d729c223f74c7b0f2445bfc0812aa0c319b9a9f5992efa6af521d550eed38a8e2c551b183e28a16722
|
data/lib/errors.rb
CHANGED
@@ -3,11 +3,13 @@
|
|
3
3
|
|
4
4
|
def make_exception(sym, str, target_class = Object)
|
5
5
|
return if target_class.constants.include?(sym)
|
6
|
-
|
6
|
+
klass = sym # :"#{sym}_Class"
|
7
|
+
target_class.const_set(klass, StandardError.dup)
|
7
8
|
define_method(sym) do |*args|
|
9
|
+
args = [] unless args.first
|
8
10
|
msg = str.dup
|
9
11
|
args.each.with_index {|arg, i| msg.sub!("%#{i+1}", arg) }
|
10
|
-
target_class.class_eval(
|
12
|
+
target_class.class_eval(klass.to_s).new(msg)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
data/lib/functions.rb
CHANGED
data/lib/helpers.rb
CHANGED
data/lib/livetext.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Class Livetext skeleton (top level).
|
2
2
|
|
3
3
|
class Livetext
|
4
|
-
VERSION = "0.9.
|
4
|
+
VERSION = "0.9.14"
|
5
5
|
Path = File.expand_path(File.join(File.dirname(__FILE__)))
|
6
6
|
end
|
7
7
|
|
@@ -9,6 +9,7 @@ end
|
|
9
9
|
|
10
10
|
require 'fileutils'
|
11
11
|
|
12
|
+
require 'helpers'
|
12
13
|
require_relative 'errors'
|
13
14
|
require_relative 'functions'
|
14
15
|
require_relative 'userapi'
|
@@ -20,10 +21,14 @@ Plugins = File.expand_path(File.join(File.dirname(__FILE__), "../plugin"))
|
|
20
21
|
|
21
22
|
TTY = ::File.open("/dev/tty", "w")
|
22
23
|
|
24
|
+
make_exception(:EndWithoutOpening, "Error: found .end with no opening command")
|
25
|
+
|
23
26
|
# Class Livetext reopened (top level).
|
24
27
|
|
25
28
|
class Livetext
|
26
29
|
|
30
|
+
include Helpers
|
31
|
+
|
27
32
|
Vars = {}
|
28
33
|
|
29
34
|
Space = " "
|
@@ -192,7 +197,7 @@ class Livetext
|
|
192
197
|
|
193
198
|
def process_file(fname, btrace=false)
|
194
199
|
_setfile(fname)
|
195
|
-
text = File.readlines(fname)
|
200
|
+
text = File.readlines(fname)
|
196
201
|
enum = text.each
|
197
202
|
@backtrace = btrace
|
198
203
|
@main.source(enum, fname, 0)
|
@@ -228,20 +233,21 @@ class Livetext
|
|
228
233
|
line = line.sub(/# .*$/, "")
|
229
234
|
name = _get_name(line).to_sym
|
230
235
|
result = nil
|
231
|
-
|
232
|
-
|
236
|
+
case
|
237
|
+
when name == :end # special case
|
238
|
+
puts @body
|
239
|
+
raise EndWithoutOpening()
|
240
|
+
when @main.respond_to?(name)
|
241
|
+
result = @main.send(name)
|
233
242
|
else
|
234
243
|
@main._error! "Name '#{name}' is unknown"
|
235
244
|
return
|
236
245
|
end
|
237
246
|
result
|
238
247
|
rescue => err
|
248
|
+
puts @body # earlier correct output, not flushed yet
|
239
249
|
STDERR.puts "Error: #{err.inspect}"
|
240
|
-
|
241
|
-
# @main._error!(err)
|
242
|
-
puts @body
|
243
|
-
@body = ""
|
244
|
-
return @body
|
250
|
+
STDERR.puts err.backtrace
|
245
251
|
end
|
246
252
|
|
247
253
|
end
|
data/lib/parser/general.rb
CHANGED
@@ -7,7 +7,7 @@ make_exception(:NilValue, "Error: nil value")
|
|
7
7
|
make_exception(:NullString, "Error: null string")
|
8
8
|
make_exception(:ExpectedString, "Error: expected a string")
|
9
9
|
|
10
|
-
class Livetext::
|
10
|
+
class Livetext::ParseGeneral < StringParser
|
11
11
|
|
12
12
|
def initialize(str)
|
13
13
|
super
|
data/lib/parser/mixin.rb
CHANGED
@@ -8,13 +8,7 @@ make_exception(:NoEqualSign, "Error: no equal sign found")
|
|
8
8
|
|
9
9
|
class Livetext::ParseMixin # < StringParser
|
10
10
|
|
11
|
-
|
12
|
-
# self.new(str).parse
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# def initialize(line)
|
16
|
-
# super
|
17
|
-
# end
|
11
|
+
include Helpers
|
18
12
|
|
19
13
|
def cwd_root?
|
20
14
|
File.dirname(File.expand_path(".")) == "/"
|
data/lib/processor.rb
CHANGED
@@ -40,12 +40,8 @@ class Livetext
|
|
40
40
|
|
41
41
|
def _error!(err, raise_error=false, trace=false) # FIXME much bullshit happens here
|
42
42
|
where = @sources.last || @save_location
|
43
|
-
#
|
44
|
-
# puts "[lib/processor] Error: #{err}"
|
45
|
-
# puts err.backtrace.join("\n") if err.respond_to?(:backtrace)
|
46
|
-
STDERR.puts "Error: #{err}" # (at #{where[1]} line #{where[2]})"
|
43
|
+
STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
|
47
44
|
STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
|
48
|
-
# raise "lib/processor error!" # FIXME
|
49
45
|
raise GenericError.new("Error: #{err}") if raise_error
|
50
46
|
end
|
51
47
|
|
@@ -76,9 +72,6 @@ class Livetext
|
|
76
72
|
nil
|
77
73
|
end
|
78
74
|
|
79
|
-
def grab_file(fname)
|
80
|
-
File.read(fname)
|
81
|
-
end
|
82
75
|
|
83
76
|
end
|
84
77
|
|
data/lib/standard.rb
CHANGED
@@ -24,7 +24,7 @@ module Livetext::Standard
|
|
24
24
|
|
25
25
|
attr_reader :_data
|
26
26
|
|
27
|
-
def data=(val) # FIXME this is weird, let's
|
27
|
+
def data=(val) # FIXME this is weird, let's remove it soonish
|
28
28
|
@_data = val.chomp
|
29
29
|
@_args = val.split rescue []
|
30
30
|
@_mixins = []
|
@@ -154,6 +154,8 @@ module Livetext::Standard
|
|
154
154
|
set_variables(pairs)
|
155
155
|
end
|
156
156
|
|
157
|
+
# FIXME really these should be one method...
|
158
|
+
|
157
159
|
def variables! # cwd, not FileDir - weird, fix later
|
158
160
|
prefix = _args[0]
|
159
161
|
file = _args[1]
|
@@ -164,7 +166,7 @@ module Livetext::Standard
|
|
164
166
|
else
|
165
167
|
lines = _body
|
166
168
|
end
|
167
|
-
pairs = Livetext::
|
169
|
+
pairs = Livetext::ParseGeneral.parse_vars(prefix, lines)
|
168
170
|
set_variables(pairs)
|
169
171
|
end
|
170
172
|
|
@@ -178,7 +180,7 @@ module Livetext::Standard
|
|
178
180
|
else
|
179
181
|
lines = _body
|
180
182
|
end
|
181
|
-
pairs = Livetext::
|
183
|
+
pairs = Livetext::ParseGeneral.parse_vars(prefix, lines)
|
182
184
|
set_variables(pairs)
|
183
185
|
end
|
184
186
|
|
@@ -225,13 +227,6 @@ module Livetext::Standard
|
|
225
227
|
_optional_blank_line
|
226
228
|
end
|
227
229
|
|
228
|
-
def in_out # FIXME dumb name!
|
229
|
-
file, dest = *@_args
|
230
|
-
check_file_exists(file)
|
231
|
-
@parent.process_file(file, dest)
|
232
|
-
_optional_blank_line
|
233
|
-
end
|
234
|
-
|
235
230
|
def _include # dot command
|
236
231
|
file = _format(@_args.first) # allows for variables
|
237
232
|
check_file_exists(file)
|
@@ -260,7 +255,7 @@ module Livetext::Standard
|
|
260
255
|
name = @_args.first # Expect a module name
|
261
256
|
return if @_mixins.include?(name)
|
262
257
|
@_mixins << name
|
263
|
-
parse = Livetext::ParseMixin.new(name) # FIXME??
|
258
|
+
parse = Livetext::ParseMixin.new # (name) # FIXME??
|
264
259
|
file = parse.find_mixin(name)
|
265
260
|
parse.use_mixin(name, file)
|
266
261
|
_optional_blank_line
|
data/lib/userapi.rb
CHANGED
data/test/all.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative '../lib/livetext'
|
4
|
+
|
5
|
+
# Just another testing class. Chill.
|
6
|
+
|
7
|
+
class TestingLivetext < MiniTest::Test
|
8
|
+
|
9
|
+
TestLines = []
|
10
|
+
|
11
|
+
items = []
|
12
|
+
formatting_tests = File.open("formatting-tests.txt")
|
13
|
+
loop do
|
14
|
+
4.times { items << formatting_tests.gets.chomp }
|
15
|
+
# Blank line terminates each "stanza"
|
16
|
+
raise "Oops? #{items.inspect}" unless items.last.empty?
|
17
|
+
TestLines << items
|
18
|
+
break if formatting_tests.eof?
|
19
|
+
end
|
20
|
+
|
21
|
+
TestLines.each.with_index do |item, num|
|
22
|
+
msg, src, exp, blank = *item
|
23
|
+
define_method("test_formatting_#{num}") do
|
24
|
+
actual = FormatLine.parse!(src)
|
25
|
+
# FIXME could simplify assert logic?
|
26
|
+
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
27
|
+
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
28
|
+
assert_match(exp, actual, msg)
|
29
|
+
else
|
30
|
+
assert_equal(exp, actual, msg)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Comments are ignored.
|
2
|
+
# Other lines: name_of_snapshot and any comments here are ignored (no # needed)
|
3
|
+
# fake_test_name Use # to un-omit ;)
|
4
|
+
error_no_such_inc Output BEFORE error doesn't get passed through
|
5
|
+
error_no_such_copy ^ Same behavior as error_no_such_inc
|
6
|
+
simple_mixin Mixin doesn't work?? But no error... maybe _def isn't working.
|
7
|
+
error_missing_end Output is duplicated somehow. Look for: puts @body or puts @main.body
|
8
|
+
error_no_such_mixin ^ Same behavior as error_missing_end
|
9
|
+
error_line_num Same behavior as error_missing_end
|
10
|
+
error_invalid_name ^ Same behavior as error_no_such_inc
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: Name 'foobar' is unknown/
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: Illegal name 'to_s'/
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: Name 'foobar' is unknown/
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: found .end with no opening command/
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: Expected .end, found end of file/
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: file nosuchfile.txt not found/
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: file nosuchinc.lt3 not found/
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /No such mixin 'nosuchthing'/
|
File without changes
|
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
|
|
@@ -58,13 +68,12 @@ class TestingLivetext < MiniTest::Test
|
|
58
68
|
info = "Expected line #{line_num} of #{actual.inspect} to match #{item.inspect} (was: #{lines[line_num].inspect})"
|
59
69
|
good = item === lines[line_num]
|
60
70
|
@errors = true unless good
|
61
|
-
# assert item === lines[line_num], info # string or regex
|
62
71
|
@assertion.call item === lines[line_num], info # string or regex
|
63
72
|
end
|
64
73
|
end
|
65
74
|
|
66
75
|
def sdiff(f1, f2, out)
|
67
|
-
File.open(out, "w") {|file| file.puts "#{'%-60s'% '
|
76
|
+
File.open(out, "w") {|file| file.puts "#{'%-60s'% 'ACTUAL'}| #{'%-60s'% 'EXPECTED'}" }
|
68
77
|
system("/usr/bin/sdiff -t -w 121 #{f1} #{f2} >>#{out}")
|
69
78
|
end
|
70
79
|
|
@@ -75,8 +84,7 @@ class TestingLivetext < MiniTest::Test
|
|
75
84
|
@errors = true if not same
|
76
85
|
file = "out-sdiff.txt"
|
77
86
|
sdiff(ACTUAL_OUT, EXP_OUT, file)
|
78
|
-
|
79
|
-
@assertion.call same, "Discrepancy in STDOUT - see #@base/#{file}"
|
87
|
+
@assertion.call same, "Discrepancy in STDOUT - see #{file} in test/snapshots/#@base"
|
80
88
|
else
|
81
89
|
check_matches(ACTUAL_OUT, MATCH_OUT)
|
82
90
|
end
|
@@ -89,8 +97,7 @@ class TestingLivetext < MiniTest::Test
|
|
89
97
|
@errors = true if not same
|
90
98
|
file = "err-sdiff.txt"
|
91
99
|
sdiff(ACTUAL_ERR, EXP_ERR, file)
|
92
|
-
|
93
|
-
@assertion.call same, "Discrepancy in STDERR - see #@base/#{file}"
|
100
|
+
@assertion.call same, "Discrepancy in STDERR - see #{file} in test/snapshots/#@base"
|
94
101
|
else
|
95
102
|
check_matches(ACTUAL_ERR, MATCH_ERR)
|
96
103
|
end
|
@@ -101,6 +108,9 @@ class TestingLivetext < MiniTest::Test
|
|
101
108
|
system("rm -f #{ACTUAL_OUT} #{ACTUAL_ERR} *sdiff.txt")
|
102
109
|
end
|
103
110
|
|
111
|
+
def filter # TODO move subset/omit logic here??
|
112
|
+
end
|
113
|
+
|
104
114
|
def run
|
105
115
|
@errors = false # oops, need to reset
|
106
116
|
Dir.chdir(@base) do
|
@@ -115,7 +125,7 @@ class TestingLivetext < MiniTest::Test
|
|
115
125
|
|
116
126
|
TTY = File.open("/dev/tty","w")
|
117
127
|
|
118
|
-
cmdline = ARGV.first == "cmdline"
|
128
|
+
cmdline = ARGV.first == "cmdline" # FIXME remove??
|
119
129
|
if cmdline
|
120
130
|
dir = "../"
|
121
131
|
Dir.chdir `livetext --path`.chomp.chomp
|
@@ -124,38 +134,29 @@ class TestingLivetext < MiniTest::Test
|
|
124
134
|
end
|
125
135
|
|
126
136
|
Data = "#{dir}test/snapshots"
|
127
|
-
TestLines = []
|
128
137
|
Dir.chdir(Data)
|
129
138
|
|
130
|
-
|
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
|
+
TestDirs = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
141
|
+
selected = File.readlines("subset.txt").map(&:chomp)
|
142
|
+
|
143
|
+
omitfile = "OMIT.txt"
|
144
|
+
omitted = File.readlines(omitfile).map(&:chomp)
|
145
|
+
omitted.reject! {|line| line.start_with?("#") }
|
146
|
+
omit_names = omitted.map {|line| line.split.first }
|
147
|
+
STDERR.puts
|
148
|
+
STDERR.puts " >>> Warning: Omitting #{omitted.size} snapshot tests:\n "
|
149
|
+
indented = " "*7
|
150
|
+
omitted.each do |line|
|
151
|
+
STDERR.print indented
|
152
|
+
name, info = line.split(" ", 2)
|
153
|
+
STDERR.printf "%-20s %s\n", name, info
|
154
154
|
end
|
155
|
+
STDERR.puts
|
155
156
|
|
156
|
-
|
157
|
-
|
158
|
-
Subset
|
157
|
+
wanted = selected.empty? ? TestDirs : selected
|
158
|
+
|
159
|
+
Subset = wanted - omit_names
|
159
160
|
|
160
161
|
Subset.each do |tdir|
|
161
162
|
define_method("test_#{tdir}") do
|
@@ -164,56 +165,4 @@ class TestingLivetext < MiniTest::Test
|
|
164
165
|
this.run
|
165
166
|
end
|
166
167
|
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
168
|
end
|
218
|
-
|
219
|
-
|
data/test/unit/parser/general.rb
CHANGED
@@ -3,9 +3,9 @@ require 'minitest/autorun'
|
|
3
3
|
|
4
4
|
require_relative '../../../lib/parser/general'
|
5
5
|
|
6
|
-
|
6
|
+
ParseGeneral = ::Livetext::ParseGeneral
|
7
7
|
|
8
|
-
class
|
8
|
+
class TestParseGeneral < MiniTest::Test
|
9
9
|
|
10
10
|
def setup
|
11
11
|
end
|
@@ -14,45 +14,45 @@ class TestParseMisc < MiniTest::Test
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_strip_quotes
|
17
|
-
assert_raises(NilValue) {
|
18
|
-
assert_raises(NullString) {
|
19
|
-
assert_raises(MismatchedQuotes) {
|
20
|
-
# assert_raises(MismatchedQuotes) {
|
21
|
-
assert_raises(MismatchedQuotes) {
|
22
|
-
# assert_raises(MismatchedQuotes) {
|
23
|
-
assert_raises(MismatchedQuotes) {
|
24
|
-
assert_raises(MismatchedQuotes) {
|
25
|
-
|
26
|
-
assert
|
27
|
-
assert
|
28
|
-
assert
|
29
|
-
assert
|
30
|
-
assert
|
17
|
+
assert_raises(NilValue) { ParseGeneral.new(nil).strip_quotes }
|
18
|
+
assert_raises(NullString) { ParseGeneral.new("").strip_quotes }
|
19
|
+
assert_raises(MismatchedQuotes) { ParseGeneral.new(%['test]).strip_quotes }
|
20
|
+
# assert_raises(MismatchedQuotes) { ParseGeneral.new(%[test']).strip_quotes }
|
21
|
+
assert_raises(MismatchedQuotes) { ParseGeneral.new(%["test]).strip_quotes }
|
22
|
+
# assert_raises(MismatchedQuotes) { ParseGeneral.new(%[test"]).strip_quotes }
|
23
|
+
assert_raises(MismatchedQuotes) { ParseGeneral.new(%["test']).strip_quotes }
|
24
|
+
assert_raises(MismatchedQuotes) { ParseGeneral.new(%['test"]).strip_quotes }
|
25
|
+
|
26
|
+
assert ParseGeneral.new(%[24601]).strip_quotes == "24601", "Failure 1"
|
27
|
+
assert ParseGeneral.new(%[3.14]).strip_quotes == "3.14", "Failure 2"
|
28
|
+
assert ParseGeneral.new(%[test]).strip_quotes == "test", "Failure 3"
|
29
|
+
assert ParseGeneral.new(%['test']).strip_quotes == "test", "Failure 4"
|
30
|
+
assert ParseGeneral.new(%["test"]).strip_quotes == "test", "Failure 5"
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_variables
|
34
34
|
vars = ["foo 234\n", "bar 456\n"]
|
35
35
|
expect = [%w[foo 234], %w[bar 456]]
|
36
|
-
assert_equal
|
36
|
+
assert_equal ParseGeneral.parse_vars(vars), expect
|
37
37
|
|
38
38
|
vars = ["foo2 234", "bar2 456"] # newline irrelevant
|
39
39
|
expect = [%w[foo2 234], %w[bar2 456]]
|
40
|
-
assert_equal
|
40
|
+
assert_equal ParseGeneral.parse_vars(vars), expect
|
41
41
|
|
42
42
|
# quotes are not stripped... hmm
|
43
43
|
vars = ["alpha 'simple string'", 'beta "another string"']
|
44
44
|
expect = [["alpha", "'simple string'"], ["beta", '"another string"']]
|
45
|
-
assert_equal
|
45
|
+
assert_equal ParseGeneral.parse_vars(vars), expect
|
46
46
|
|
47
47
|
# prefix (namespacing)
|
48
48
|
vars = ["alpha 'simple string'", 'beta "another string"']
|
49
49
|
expect = [["this.alpha", "'simple string'"], ["this.beta", '"another string"']]
|
50
|
-
assert_equal
|
50
|
+
assert_equal ParseGeneral.parse_vars(vars, prefix: "this"), expect
|
51
51
|
|
52
52
|
# prefix (namespacing)
|
53
53
|
vars = ["alpha 'simple string'", 'beta "another string"']
|
54
54
|
expect = [["this.that.alpha", "'simple string'"], ["this.that.beta", '"another string"']]
|
55
|
-
assert_equal
|
55
|
+
assert_equal ParseGeneral.parse_vars(vars, prefix: "this.that"), expect
|
56
56
|
|
57
57
|
end
|
58
58
|
|
data/test/unit/parser/mixin.rb
CHANGED