livetext 0.9.13 → 0.9.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.lt3 +2 -2
  3. data/imports/bookish.rb +288 -0
  4. data/imports/calibre.rb +28 -0
  5. data/imports/livemagick.rb +133 -0
  6. data/imports/markdown.rb +44 -0
  7. data/imports/markdown_importable.rb +46 -0
  8. data/imports/pyggish.rb +204 -0
  9. data/imports/tutorial.rb +95 -0
  10. data/lib/cmdargs.rb +93 -0
  11. data/lib/errors.rb +4 -2
  12. data/lib/formatline.rb +56 -83
  13. data/lib/functions.rb +1 -1
  14. data/lib/handler/icanhaz.rb +35 -0
  15. data/lib/handler.rb +1 -0
  16. data/lib/helpers.rb +177 -4
  17. data/lib/livetext.rb +20 -139
  18. data/lib/parser/file.rb +8 -0
  19. data/lib/parser/general.rb +1 -1
  20. data/lib/parser/import.rb +1 -3
  21. data/lib/parser/mixin.rb +22 -30
  22. data/lib/parser/set.rb +35 -26
  23. data/lib/parser/string.rb +19 -4
  24. data/lib/processor.rb +2 -12
  25. data/lib/standard.rb +73 -107
  26. data/lib/userapi.rb +1 -4
  27. data/livetext.gemspec +2 -1
  28. data/plugin/bookish.rb +26 -22
  29. data/plugin/calibre.rb +1 -1
  30. data/plugin/livemagick.rb +10 -10
  31. data/plugin/markdown.rb +13 -11
  32. data/plugin/pyggish.rb +94 -84
  33. data/plugin/tutorial.rb +10 -5
  34. data/test/snapshots/OMIT.txt +11 -0
  35. data/test/snapshots/clusion.txt +84 -0
  36. data/test/snapshots/error_inc_line_num/match-error.txt +1 -0
  37. data/test/snapshots/error_invalid_name/match-error.txt +1 -0
  38. data/test/snapshots/error_line_num/match-error.txt +1 -0
  39. data/test/snapshots/error_mismatched_end/expected-output.txt +0 -2
  40. data/test/snapshots/error_mismatched_end/match-error.txt +1 -0
  41. data/test/snapshots/error_missing_end/match-error.txt +1 -0
  42. data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
  43. data/test/snapshots/error_no_such_copy/source.lt3 +0 -1
  44. data/test/snapshots/error_no_such_inc/match-error.txt +1 -0
  45. data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
  46. data/test/snapshots/icanhaz/expected-output.txt +5 -0
  47. data/test/snapshots/icanhaz/match-error.txt +1 -0
  48. data/test/snapshots/icanhaz/simple_import.rb +5 -0
  49. data/test/snapshots/{error_no_such_mixin/actual-output.txt → icanhaz/source.lt3} +3 -4
  50. data/test/snapshots/{error_invalid_name/actual-output.txt → icanhaz2/expected-error.txt} +0 -0
  51. data/test/snapshots/icanhaz2/expected-output.txt +6 -0
  52. data/test/snapshots/icanhaz2/simple_canhaz.rb +5 -0
  53. data/test/snapshots/icanhaz2/source.lt3 +6 -0
  54. data/test/snapshots/predef_vars/match-output.txt +6 -0
  55. data/test/snapshots/{error_no_such_copy/actual-output.txt → simple_import/expected-error.txt} +0 -0
  56. data/test/snapshots/simple_import/expected-output.txt +7 -0
  57. data/test/snapshots/simple_import/simple_import.rb +5 -0
  58. data/test/snapshots/simple_import/source.lt3 +7 -0
  59. data/test/snapshots/simple_include/source.lt3 +0 -1
  60. data/test/snapshots.rb +103 -107
  61. data/test/unit/all.rb +1 -0
  62. data/test/unit/formatline.rb +650 -0
  63. data/test/unit/parser/general.rb +21 -21
  64. data/test/unit/parser/importable.rb +1 -1
  65. data/test/unit/parser/mixin.rb +2 -2
  66. data/test/unit/parser/set.rb +19 -12
  67. data/test/unit/parser/string.rb +14 -14
  68. data/test/unit/parser.rb +2 -0
  69. metadata +37 -46
  70. data/test/formatting.rb +0 -103
  71. data/test/snapshots/error_inc_line_num/actual-error.txt +0 -1
  72. data/test/snapshots/error_inc_line_num/actual-output.txt +0 -13
  73. data/test/snapshots/error_inc_line_num/expected-err-line1match.txt +0 -1
  74. data/test/snapshots/error_inc_line_num/out-sdiff.txt +0 -14
  75. data/test/snapshots/error_invalid_name/actual-error.txt +0 -10
  76. data/test/snapshots/error_invalid_name/expected-err-line1match.txt +0 -1
  77. data/test/snapshots/error_invalid_name/out-sdiff.txt +0 -6
  78. data/test/snapshots/error_line_num/actual-error.txt +0 -1
  79. data/test/snapshots/error_line_num/actual-output.txt +0 -5
  80. data/test/snapshots/error_line_num/expected-err-line1match.txt +0 -1
  81. data/test/snapshots/error_line_num/out-sdiff.txt +0 -6
  82. data/test/snapshots/error_mismatched_end/actual-error.txt +0 -1
  83. data/test/snapshots/error_mismatched_end/actual-output.txt +0 -8
  84. data/test/snapshots/error_mismatched_end/expected-err-line1match.txt +0 -1
  85. data/test/snapshots/error_mismatched_end/out-sdiff.txt +0 -9
  86. data/test/snapshots/error_missing_end/actual-error.txt +0 -1
  87. data/test/snapshots/error_missing_end/actual-output.txt +0 -5
  88. data/test/snapshots/error_missing_end/expected-err-line1match.txt +0 -1
  89. data/test/snapshots/error_missing_end/out-sdiff.txt +0 -6
  90. data/test/snapshots/error_name_not_permitted/OLD-exp-out +0 -4
  91. data/test/snapshots/error_no_such_copy/actual-error.txt +0 -10
  92. data/test/snapshots/error_no_such_copy/expected-err-line1match.txt +0 -1
  93. data/test/snapshots/error_no_such_copy/out-sdiff.txt +0 -5
  94. data/test/snapshots/error_no_such_inc/actual-error.txt +0 -10
  95. data/test/snapshots/error_no_such_inc/actual-output.txt +0 -0
  96. data/test/snapshots/error_no_such_inc/expected-err-line1match.txt +0 -1
  97. data/test/snapshots/error_no_such_inc/out-sdiff.txt +0 -6
  98. data/test/snapshots/error_no_such_mixin/actual-error.txt +0 -1
  99. data/test/snapshots/error_no_such_mixin/expected-err-line1match.txt +0 -1
  100. data/test/snapshots/error_no_such_mixin/out-sdiff.txt +0 -12
  101. data/test/snapshots/lines.txt +0 -124
  102. data/test/snapshots/predef_vars/actual-error.txt +0 -0
  103. data/test/snapshots/predef_vars/actual-output.txt +0 -6
  104. data/test/snapshots/predef_vars/expected-output.txt +0 -6
  105. data/test/snapshots/predef_vars/out-sdiff.txt +0 -7
  106. data/test/snapshots/simple_mixin/actual-error.txt +0 -2
  107. data/test/snapshots/simple_mixin/actual-output.txt +0 -4
  108. data/test/snapshots/simple_mixin/out-sdiff.txt +0 -6
  109. data/test/unit/parse_misc.rb +0 -60
  110. data/test/unit/parse_set.rb +0 -157
@@ -1,5 +1,4 @@
1
1
  Here I am
2
- .debug
3
2
  trying to
4
3
  include
5
4
  .include simplefile.inc
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 external_files.
11
+ call Snapshot.new
12
12
 
13
- The external_files method works this way:
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, expected-output.txt, and expected-error.txt
17
- - Technically, any of these can be empty
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 "real" output gets checked first
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'% 'EXPECTED'}| #{'%-60s'% 'ACTUAL'}" }
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
- # assert same, "Discrepancy in STDOUT - see #@base/#{file}"
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
- # assert same, "Discrepancy in STDERR - see #@base/#{file}"
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
- TTY = File.open("/dev/tty","w")
117
-
118
- cmdline = ARGV.first == "cmdline"
119
- if cmdline
120
- dir = "../"
121
- Dir.chdir `livetext --path`.chomp.chomp
122
- else
123
- dir = ""
124
- end
125
-
126
- Data = "#{dir}test/snapshots"
127
- TestLines = []
128
- Dir.chdir(Data)
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
- "" + str.to_s + ""
170
- end
171
-
172
- def red(str)
173
- "" + str.to_s + ""
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
@@ -1,3 +1,4 @@
1
1
 
2
2
  require_relative 'standard'
3
3
  require_relative 'parser' # nested
4
+ require_relative 'formatline'