livetext 0.9.10 → 0.9.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cmdargs.rb +93 -0
- data/lib/errors.rb +15 -0
- data/lib/formatline.rb +59 -88
- data/lib/functions.rb +6 -2
- data/lib/helpers.rb +163 -0
- data/lib/html.rb +32 -0
- data/lib/livetext/importable.rb +2 -0
- data/lib/livetext.rb +30 -148
- data/lib/parser/file.rb +8 -0
- data/lib/parser/general.rb +38 -0
- data/lib/parser/import.rb +17 -0
- data/lib/parser/mixin.rb +53 -0
- data/lib/parser/set.rb +145 -0
- data/lib/parser/string.rb +70 -0
- data/lib/parser.rb +5 -0
- data/lib/processor.rb +23 -27
- data/lib/standard.rb +155 -348
- data/lib/userapi.rb +2 -5
- data/livetext.gemspec +1 -2
- 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/all.rb +3 -0
- data/test/snapshots/OMIT.txt +9 -0
- data/test/{data → snapshots}/basic_formatting/expected-error.txt +0 -0
- data/test/{data → snapshots}/basic_formatting/expected-output.txt +0 -0
- data/test/{data → snapshots}/basic_formatting/source.lt3 +0 -0
- data/test/{data → snapshots}/block_comment/expected-error.txt +0 -0
- data/test/{data → snapshots}/block_comment/expected-output.txt +0 -0
- data/test/{data → snapshots}/block_comment/source.lt3 +0 -0
- data/test/snapshots/clusion.txt +35 -0
- data/test/{data → snapshots}/comments_ignored_1/expected-error.txt +0 -0
- data/test/{data → snapshots}/comments_ignored_1/expected-output.txt +0 -0
- data/test/{data → snapshots}/comments_ignored_1/source.lt3 +0 -0
- data/test/{data → snapshots}/copy_is_raw/expected-error.txt +0 -0
- data/test/{data → snapshots}/copy_is_raw/expected-output.txt +0 -0
- data/test/{data → snapshots}/copy_is_raw/rawtext.inc +0 -0
- data/test/{data → snapshots}/copy_is_raw/source.lt3 +0 -0
- data/test/{data → snapshots}/crap +0 -0
- data/test/{data → snapshots}/def_method/expected-error.txt +0 -0
- data/test/{data → snapshots}/def_method/expected-output.txt +0 -0
- data/test/{data → snapshots}/def_method/source.lt3 +0 -0
- data/test/snapshots/error_inc_line_num/actual-error.txt +14 -0
- data/test/{data/error_inc_line_num/expected-output.txt → snapshots/error_inc_line_num/actual-output.txt} +0 -0
- data/test/snapshots/error_inc_line_num/expected-output.txt +13 -0
- data/test/{data → snapshots}/error_inc_line_num/file2.lt3 +0 -0
- data/test/snapshots/error_inc_line_num/match-error.txt +1 -0
- data/test/snapshots/error_inc_line_num/out-sdiff.txt +14 -0
- data/test/{data → snapshots}/error_inc_line_num/source.lt3 +0 -0
- data/test/snapshots/error_invalid_name/actual-error.txt +10 -0
- data/test/{data/error_no_such_mixin/expected-output.txt → snapshots/error_invalid_name/actual-output.txt} +0 -0
- data/test/{data → snapshots}/error_invalid_name/expected-output.txt +0 -0
- data/test/snapshots/error_invalid_name/match-error.txt +1 -0
- data/test/snapshots/error_invalid_name/out-sdiff.txt +6 -0
- data/test/{data → snapshots}/error_invalid_name/source.lt3 +0 -0
- data/test/{data → snapshots}/error_line_num/expected-output.txt +0 -0
- data/test/snapshots/error_line_num/match-error.txt +1 -0
- data/test/{data → snapshots}/error_line_num/source.lt3 +0 -0
- data/test/{data → snapshots}/error_mismatched_end/expected-output.txt +0 -0
- data/test/snapshots/error_mismatched_end/match-error.txt +1 -0
- data/test/{data → snapshots}/error_mismatched_end/source.lt3 +0 -0
- data/test/snapshots/error_missing_end/actual-error.txt +10 -0
- data/test/{data/example_alpha/expected-error.txt → snapshots/error_missing_end/actual-output.txt} +0 -0
- data/test/{data → snapshots}/error_missing_end/expected-output.txt +1 -0
- data/test/snapshots/error_missing_end/match-error.txt +1 -0
- data/test/snapshots/error_missing_end/out-sdiff.txt +6 -0
- data/test/{data → snapshots}/error_missing_end/source.lt3 +0 -0
- data/test/{data/example_alpha2/expected-error.txt → snapshots/error_name_not_permitted/expected-output.txt} +0 -0
- data/test/snapshots/error_name_not_permitted/match-error.txt +1 -0
- data/test/{data → snapshots}/error_name_not_permitted/source.lt3 +0 -0
- data/test/snapshots/error_no_such_copy/actual-error.txt +10 -0
- data/test/{data/functions/expected-error.txt → snapshots/error_no_such_copy/actual-output.txt} +0 -0
- data/test/{data → snapshots}/error_no_such_copy/expected-output.txt +0 -1
- data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
- data/test/snapshots/error_no_such_copy/out-sdiff.txt +5 -0
- data/test/{data → snapshots}/error_no_such_copy/source.lt3 +0 -0
- data/test/snapshots/error_no_such_inc/actual-error.txt +10 -0
- data/test/{data/hello_world/expected-error.txt → snapshots/error_no_such_inc/actual-output.txt} +0 -0
- data/test/{data → snapshots}/error_no_such_inc/expected-output.txt +0 -0
- data/test/snapshots/error_no_such_inc/match-error.txt +1 -0
- data/test/snapshots/error_no_such_inc/out-sdiff.txt +6 -0
- data/test/{data → snapshots}/error_no_such_inc/source.lt3 +0 -0
- data/test/snapshots/error_no_such_mixin/actual-error.txt +37 -0
- data/test/{data/more_complex_vars/expected-error.txt → snapshots/error_no_such_mixin/actual-output.txt} +0 -0
- data/test/snapshots/error_no_such_mixin/expected-output.txt +5 -0
- data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
- data/test/snapshots/error_no_such_mixin/out-sdiff.txt +6 -0
- data/test/{data → snapshots}/error_no_such_mixin/source.lt3 +0 -0
- data/test/{data/raw_lines → snapshots/example_alpha}/expected-error.txt +0 -0
- data/test/{data → snapshots}/example_alpha/expected-output.txt +0 -0
- data/test/{data → snapshots}/example_alpha/source.lt3 +0 -0
- data/test/{data/raw_text_block → snapshots/example_alpha2}/expected-error.txt +0 -0
- data/test/{data → snapshots}/example_alpha2/expected-output.txt +0 -0
- data/test/{data → snapshots}/example_alpha2/source.lt3 +0 -0
- data/test/{data → snapshots}/fixit +0 -0
- data/test/{data/simple_copy → snapshots/functions}/expected-error.txt +0 -0
- data/test/{data → snapshots}/functions/expected-output.txt +0 -0
- data/test/{data → snapshots}/functions/source.lt3 +0 -0
- data/test/{data/simple_include → snapshots/hello_world}/expected-error.txt +0 -0
- data/test/{data → snapshots}/hello_world/expected-output.txt +0 -0
- data/test/{data → snapshots}/hello_world/source.lt3 +0 -0
- data/test/{data/simple_mixin → snapshots/more_complex_vars}/expected-error.txt +0 -0
- data/test/{data → snapshots}/more_complex_vars/expected-output.txt +0 -0
- data/test/{data → snapshots}/more_complex_vars/source.lt3 +0 -0
- data/test/{data/simple_vars → snapshots/predef_vars}/expected-error.txt +0 -0
- data/test/snapshots/predef_vars/match-output.txt +6 -0
- data/test/snapshots/predef_vars/source.lt3 +6 -0
- data/test/{data/single_raw_line → snapshots/raw_lines}/expected-error.txt +0 -0
- data/test/{data → snapshots}/raw_lines/expected-output.txt +0 -0
- data/test/{data → snapshots}/raw_lines/source.lt3 +0 -0
- data/test/{data/table_with_heredocs → snapshots/raw_text_block}/expected-error.txt +0 -0
- data/test/{data → snapshots}/raw_text_block/expected-output.txt +0 -0
- data/test/{data → snapshots}/raw_text_block/rawtext.inc +0 -0
- data/test/{data → snapshots}/raw_text_block/source.lt3 +0 -0
- data/test/{data/subset.txt → snapshots/simple_copy/expected-error.txt} +0 -0
- data/test/{data → snapshots}/simple_copy/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_copy/simplefile.inc +0 -0
- data/test/{data → snapshots}/simple_copy/source.lt3 +0 -0
- data/test/snapshots/simple_import/actual-error.txt +8 -0
- data/test/snapshots/simple_import/actual-output.txt +3 -0
- data/test/snapshots/simple_import/err-sdiff.txt +9 -0
- data/test/snapshots/simple_import/expected-error.txt +0 -0
- data/test/snapshots/simple_import/expected-output.txt +7 -0
- data/test/snapshots/simple_import/out-sdiff.txt +9 -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/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_include/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_include/simplefile.inc +0 -0
- data/test/{data → snapshots}/simple_include/source.lt3 +0 -1
- data/test/snapshots/simple_mixin/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_mixin/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_mixin/simple_mixin.rb +0 -0
- data/test/{data → snapshots}/simple_mixin/source.lt3 +0 -0
- data/test/snapshots/simple_vars/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_vars/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_vars/source.lt3 +0 -0
- data/test/snapshots/single_raw_line/expected-error.txt +0 -0
- data/test/{data → snapshots}/single_raw_line/expected-output.txt +0 -0
- data/test/{data → snapshots}/single_raw_line/source.lt3 +0 -0
- data/test/snapshots/subset.txt +0 -0
- data/test/snapshots/table_with_heredocs/expected-error.txt +0 -0
- data/test/{data → snapshots}/table_with_heredocs/expected-output.txt +0 -0
- data/test/{data → snapshots}/table_with_heredocs/source.lt3 +0 -0
- data/test/snapshots.rb +169 -0
- data/test/testlines.rb +17 -7
- data/test/unit/all.rb +4 -0
- data/test/unit/formatline.rb +650 -0
- data/test/unit/html.rb +38 -0
- data/test/unit/parser/all.rb +3 -0
- data/test/unit/parser/general.rb +59 -0
- data/test/unit/parser/importable.rb +19 -0
- data/test/unit/parser/mixin.rb +19 -0
- data/test/unit/parser/set.rb +164 -0
- data/test/unit/parser/string.rb +130 -0
- data/test/unit/parser.rb +6 -0
- data/test/unit/standard.rb +23 -0
- data/test/unit/stringparser.rb +140 -0
- metadata +150 -97
- data/test/data/error_inc_line_num/expected-err-line1match.txt +0 -1
- data/test/data/error_invalid_name/expected-err-line1match.txt +0 -1
- data/test/data/error_line_num/expected-err-line1match.txt +0 -1
- data/test/data/error_mismatched_end/expected-err-line1match.txt +0 -1
- data/test/data/error_missing_end/expected-err-line1match.txt +0 -1
- data/test/data/error_name_not_permitted/expected-error.txt +0 -1
- data/test/data/error_name_not_permitted/expected-output.txt +0 -4
- data/test/data/error_no_such_copy/expected-err-line1match.txt +0 -1
- data/test/data/error_no_such_inc/expected-err-line1match.txt +0 -1
- data/test/data/error_no_such_mixin/expected-err-line1match.txt +0 -1
- data/test/data/lines.txt +0 -120
- data/test/extratests.txt +0 -20
- data/test/formatting.rb +0 -110
- data/test/test.rb +0 -140
data/test/snapshots.rb
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative '../lib/livetext'
|
4
|
+
|
5
|
+
=begin
|
6
|
+
Snapshots...
|
7
|
+
|
8
|
+
NOTE that the external_files method has been replaced by the Snapshot class.
|
9
|
+
|
10
|
+
You can add any ordinary test method above. But so far, most of these tests simply
|
11
|
+
call Snapshot.new
|
12
|
+
|
13
|
+
It works this way:
|
14
|
+
- If the test (caller) method is test_my_silly_feature, then we will
|
15
|
+
look for a directory called snapshots/my_silly_feature
|
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
|
29
|
+
- We run livetext on the source and compare actual vs expected (stdout, stderr)
|
30
|
+
- The error output gets checked first (expected or match), THEN standard output
|
31
|
+
- Of course, both must compare correctly for the test to pass
|
32
|
+
=end
|
33
|
+
|
34
|
+
|
35
|
+
# Just a testing class. Chill.
|
36
|
+
|
37
|
+
class TestingLivetext < MiniTest::Test
|
38
|
+
|
39
|
+
class Snapshot
|
40
|
+
SOURCE = "source.lt3"
|
41
|
+
# Will now keep "actual" output in same dir?
|
42
|
+
ACTUAL_OUT, ACTUAL_ERR = "actual-output.txt", "actual-error.txt"
|
43
|
+
EXP_OUT, EXP_ERR = "expected-output.txt", "expected-error.txt"
|
44
|
+
MATCH_OUT, MATCH_ERR = "match-output.txt", "match-error.txt"
|
45
|
+
|
46
|
+
def initialize(base, assertion = nil)
|
47
|
+
@assertion = assertion
|
48
|
+
@base = base
|
49
|
+
@errors = false
|
50
|
+
Dir.chdir(base) do
|
51
|
+
@literal_out = File.exist?(EXP_OUT)
|
52
|
+
@literal_err = File.exist?(EXP_ERR)
|
53
|
+
@match_out = File.exist?(MATCH_OUT)
|
54
|
+
@match_err = File.exist?(MATCH_ERR)
|
55
|
+
end
|
56
|
+
bad_files = (@literal_out && @match_out) || (@literal_err && @match_err) ||
|
57
|
+
(! @literal_out && ! @match_out)
|
58
|
+
raise "Inconsistent structure for #@base" if bad_files
|
59
|
+
end
|
60
|
+
|
61
|
+
def check_matches(actual, control)
|
62
|
+
controls = File.readlines(control).map(&:chomp)
|
63
|
+
lines = File.readlines(actual).map(&:chomp)
|
64
|
+
lines.unshift("DUMMY LINE") # 1-based index! (for when I'm editing)
|
65
|
+
controls.each do |line|
|
66
|
+
line_num, item = line.split(" ", 2)
|
67
|
+
item = Regexp.new(item[1..-2]) if item[0] == "/" # Hmm, string can't start with /...
|
68
|
+
line_num = line_num.to_i
|
69
|
+
info = "Expected line #{line_num} of #{actual.inspect} to match #{item.inspect} (was: #{lines[line_num].inspect})"
|
70
|
+
good = item === lines[line_num]
|
71
|
+
@errors = true unless good
|
72
|
+
@assertion.call item === lines[line_num], info # string or regex
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def sdiff(f1, f2, out)
|
77
|
+
File.open(out, "w") {|file| file.puts "#{'%-60s'% 'ACTUAL'}| #{'%-60s'% 'EXPECTED'}" }
|
78
|
+
system("/usr/bin/sdiff -t -w 121 #{f1} #{f2} >>#{out}")
|
79
|
+
end
|
80
|
+
|
81
|
+
def check_stdout
|
82
|
+
if @literal_out
|
83
|
+
actual, expected = File.read(ACTUAL_OUT), File.read(EXP_OUT)
|
84
|
+
same = actual == expected
|
85
|
+
@errors = true if not same
|
86
|
+
file = "out-sdiff.txt"
|
87
|
+
sdiff(ACTUAL_OUT, EXP_OUT, file)
|
88
|
+
@assertion.call same, "Discrepancy in STDOUT - see #{file} in test/snapshots/#@base"
|
89
|
+
else
|
90
|
+
check_matches(ACTUAL_OUT, MATCH_OUT)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def check_stderr
|
95
|
+
if @literal_err
|
96
|
+
actual, expected = File.read(ACTUAL_ERR), File.read(EXP_ERR)
|
97
|
+
same = actual == expected
|
98
|
+
@errors = true if not same
|
99
|
+
file = "err-sdiff.txt"
|
100
|
+
sdiff(ACTUAL_ERR, EXP_ERR, file)
|
101
|
+
@assertion.call same, "Discrepancy in STDERR - see #{file} in test/snapshots/#@base"
|
102
|
+
else
|
103
|
+
check_matches(ACTUAL_ERR, MATCH_ERR)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def cleanup
|
108
|
+
return if @errors
|
109
|
+
system("rm -f #{ACTUAL_OUT} #{ACTUAL_ERR} *sdiff.txt")
|
110
|
+
end
|
111
|
+
|
112
|
+
def filter # TODO move subset/omit logic here??
|
113
|
+
end
|
114
|
+
|
115
|
+
def run
|
116
|
+
@errors = false # oops, need to reset
|
117
|
+
Dir.chdir(@base) do
|
118
|
+
cmd = "../../../bin/livetext #{SOURCE} >#{ACTUAL_OUT} 2>#{ACTUAL_ERR}"
|
119
|
+
system(cmd)
|
120
|
+
check_stderr
|
121
|
+
check_stdout
|
122
|
+
cleanup
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
TTY = File.open("/dev/tty","w")
|
128
|
+
|
129
|
+
cmdline = ARGV.first == "cmdline" # FIXME remove??
|
130
|
+
if cmdline
|
131
|
+
dir = "../"
|
132
|
+
Dir.chdir `livetext --path`.chomp.chomp
|
133
|
+
else
|
134
|
+
dir = ""
|
135
|
+
end
|
136
|
+
|
137
|
+
Data = "#{dir}test/snapshots"
|
138
|
+
Dir.chdir(Data)
|
139
|
+
|
140
|
+
TestDirs = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
|
141
|
+
|
142
|
+
selected = File.readlines("subset.txt").map(&:chomp)
|
143
|
+
|
144
|
+
omitfile = "OMIT.txt"
|
145
|
+
omitted = File.readlines(omitfile).map(&:chomp)
|
146
|
+
omitted.reject! {|line| line.start_with?("#") }
|
147
|
+
omit_names = omitted.map {|line| line.split.first }
|
148
|
+
STDERR.puts
|
149
|
+
STDERR.puts " >>> Warning: Omitting #{omitted.size} snapshot tests:\n "
|
150
|
+
indented = " "*7
|
151
|
+
omitted.each do |line|
|
152
|
+
STDERR.print indented
|
153
|
+
name, info = line.split(" ", 2)
|
154
|
+
STDERR.printf "%-20s %s\n", name, info
|
155
|
+
end
|
156
|
+
STDERR.puts
|
157
|
+
|
158
|
+
wanted = selected.empty? ? TestDirs : selected
|
159
|
+
|
160
|
+
Subset = wanted - omit_names
|
161
|
+
|
162
|
+
Subset.each do |tdir|
|
163
|
+
define_method("test_#{tdir}") do
|
164
|
+
myproc = Proc.new {|bool, info| assert bool, info }
|
165
|
+
this = Snapshot.new(tdir, myproc)
|
166
|
+
this.run
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
data/test/testlines.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'livetext'
|
2
|
-
require 'formatline'
|
1
|
+
require '../lib/livetext'
|
2
|
+
require '../lib/formatline'
|
3
3
|
|
4
4
|
def red(str)
|
5
5
|
"[31m" + str + "[0m"
|
@@ -8,20 +8,30 @@ require 'formatline'
|
|
8
8
|
input = ARGV.first || "test/data/lines.txt"
|
9
9
|
data = File.readlines(input)
|
10
10
|
|
11
|
-
|
11
|
+
pass = fail = 0
|
12
|
+
data.each_slice(4).with_index do |lines, i|
|
12
13
|
title, input, expected, blank = *lines
|
14
|
+
lnum = i*4 + 1
|
13
15
|
input.chomp!
|
14
16
|
expected.chomp!
|
15
17
|
expected = eval(expected) if expected[0] == "/"
|
16
18
|
|
17
|
-
puts "-----------------------------"
|
18
|
-
print "Test: #{title}"
|
19
19
|
|
20
20
|
actual = FormatLine.parse!(input)
|
21
|
-
|
21
|
+
if expected === actual
|
22
|
+
pass += 1
|
23
|
+
# puts "PASS: #{title}"
|
24
|
+
next
|
25
|
+
end
|
22
26
|
|
23
|
-
|
27
|
+
fail += 1
|
28
|
+
puts "----------------------------- (line #{lnum})"
|
29
|
+
puts "Test: #{title}"
|
30
|
+
puts "Input: #{input}"
|
24
31
|
puts " #{red('FAIL Expected: ')} #{expected.inspect}"
|
25
32
|
puts " #{red(' Actual : ')} #{actual.inspect}"
|
26
33
|
puts
|
27
34
|
end
|
35
|
+
|
36
|
+
puts
|
37
|
+
puts "#{pass} passes #{fail} fails"
|
data/test/unit/all.rb
ADDED