erbtex 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,393 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module ErbTeX
6
+ describe CommandLine do
7
+ describe 'erbtex options' do
8
+ it 'recognizes no-clobber and removes it from TeX arguments' do
9
+ cl = described_class.new(['--no-clobber', 'file.tex'])
10
+
11
+ expect(cl.no_clobber).to be(true)
12
+ expect(cl.tex_command).to eq(['pdflatex', 'file.tex'])
13
+ end
14
+
15
+ it 'recognizes preprocess-only and removes it from TeX arguments' do
16
+ cl = described_class.new(['--preprocess-only', 'file.tex'])
17
+
18
+ expect(cl.preprocess_only).to be(true)
19
+ expect(cl.tex_command).to eq(['pdflatex', 'file.tex'])
20
+ end
21
+
22
+ it 'accepts hyphenated executable names without truncating them' do
23
+ cl = described_class.new(['--invoke=pdf-latex', 'file.tex'])
24
+
25
+ expect(cl.tex_command).to eq(['pdf-latex', 'file.tex'])
26
+ end
27
+
28
+ it 'accepts executable paths containing spaces and punctuation' do
29
+ cl = described_class.new(['--invoke=/opt/TeX tools/pdf-latex', 'file.tex'])
30
+
31
+ expect(cl.tex_command).to eq(['/opt/TeX tools/pdf-latex', 'file.tex'])
32
+ end
33
+
34
+ it 'keeps the first invoke option when several are supplied' do
35
+ cl = described_class.new(['--invoke=pdf-latex', '--invoke=lualatex', 'file.tex'])
36
+
37
+ expect(cl.tex_command).to eq(['pdf-latex', 'file.tex'])
38
+ end
39
+
40
+ it 'rejects an empty executable name' do
41
+ expect { described_class.new(['--invoke=', 'file.tex']) }
42
+ .to raise_error(ArgumentError, '--invoke requires a nonempty executable name')
43
+ end
44
+
45
+ it 'recognizes exact informational flags and removes them from TeX arguments' do
46
+ cl = described_class.new(['--help', '--version', '--help', 'file.tex'])
47
+
48
+ expect(cl.print_help).to be(true)
49
+ expect(cl.print_version).to be(true)
50
+ expect(cl.tex_command).to eq(['pdflatex', 'file.tex'])
51
+ end
52
+
53
+ it 'passes options with similar prefixes through to TeX unchanged' do
54
+ options = [
55
+ '--helpful',
56
+ '--help=extra',
57
+ '--version-extra',
58
+ '--version=extra',
59
+ '--invoker=tex',
60
+ '--preprocess-only=extra',
61
+ '--no-clobber=extra'
62
+ ]
63
+ cl = described_class.new([*options, 'file.tex'])
64
+
65
+ expect(cl.print_help).to be(false)
66
+ expect(cl.print_version).to be(false)
67
+ expect(cl.preprocess_only).to be(false)
68
+ expect(cl.no_clobber).to be(false)
69
+ expect(cl.tex_command).to eq(['pdflatex', *options, 'file.tex'])
70
+ end
71
+
72
+ it 'preserves option-like text after the first TeX command' do
73
+ commands = ['\\relax', '--help', '--version', '--preprocess-only', '--no-clobber', '--invoke=other', '\\end']
74
+ cl = described_class.new(['--invoke=pdf-latex', *commands])
75
+
76
+ expect(cl.print_help).to be(false)
77
+ expect(cl.print_version).to be(false)
78
+ expect(cl.preprocess_only).to be(false)
79
+ expect(cl.no_clobber).to be(false)
80
+ expect(cl.tex_command).to eq(['pdf-latex', *commands])
81
+ end
82
+ end
83
+
84
+ describe 'parsing' do
85
+ before do
86
+ # Without this fakery, $0 would be rspec when these specs are run.
87
+ $0 = 'erbtex'
88
+ # NOTE: ARGV does not include the name of the program as the first
89
+ # element, as in C.
90
+ @argv_with_file =
91
+ [
92
+ '-draftmode',
93
+ '-enc',
94
+ '-etex',
95
+ '-file-line-error',
96
+ '-fmt',
97
+ 'junk',
98
+ '-halt-on-error',
99
+ '-ini',
100
+ '-interaction',
101
+ 'batchmode',
102
+ '-ipc',
103
+ '-ipc-start',
104
+ '-jobname',
105
+ 'junk',
106
+ '-kpathsea-debug',
107
+ '8',
108
+ '-mktex',
109
+ 'tex',
110
+ '--invoke=pdflatex',
111
+ '-mltex',
112
+ '-nomktex',
113
+ 'tfm',
114
+ '-ouptput-comment',
115
+ 'This is a long comment',
116
+ '-output-directory',
117
+ '~/texmf/tex',
118
+ '-parse-first-line',
119
+ '-progname',
120
+ 'pdflatex',
121
+ '-recorder',
122
+ '-shell-escape',
123
+ '-src-specials',
124
+ 'cr,display,hbox,math,par',
125
+ '-translate-file',
126
+ 'willy',
127
+ '-version',
128
+ '&myformat',
129
+ 'file_name.tex.erb'
130
+ ]
131
+ @argv_with_remote_file =
132
+ [
133
+ '-draftmode',
134
+ '-enc',
135
+ '-etex',
136
+ '-file-line-error',
137
+ '-fmt',
138
+ 'junk',
139
+ '-halt-on-error',
140
+ '-ini',
141
+ '-interaction',
142
+ 'batchmode',
143
+ '-ipc',
144
+ '-ipc-start',
145
+ '-jobname',
146
+ 'junk',
147
+ '-kpathsea-debug',
148
+ '8',
149
+ '-mktex',
150
+ 'tex',
151
+ '--invoke=pdflatex',
152
+ '-mltex',
153
+ '-nomktex',
154
+ 'tfm',
155
+ '-ouptput-comment',
156
+ 'This is a long comment',
157
+ '-output-directory',
158
+ '~/texmf/tex',
159
+ '-parse-first-line',
160
+ '-progname',
161
+ 'pdflatex',
162
+ '-recorder',
163
+ '-shell-escape',
164
+ '-src-specials',
165
+ 'cr,display,hbox,math,par',
166
+ '-translate-file',
167
+ 'willy',
168
+ '-version',
169
+ '&myformat',
170
+ 'example_files/file_name.tex.erb'
171
+ ]
172
+ @argv_with_invoke_and_file =
173
+ [
174
+ '--invoke=lualatex',
175
+ '-draftmode',
176
+ '-enc',
177
+ '-etex',
178
+ '-file-line-error',
179
+ '-fmt',
180
+ 'junk',
181
+ '-halt-on-error',
182
+ '-ini',
183
+ '-interaction',
184
+ 'batchmode',
185
+ '-ipc',
186
+ '-ipc-start',
187
+ '-jobname',
188
+ 'junk',
189
+ '-kpathsea-debug',
190
+ '8',
191
+ '-mktex',
192
+ 'tex',
193
+ '--invoke=pdflatex',
194
+ '-mltex',
195
+ '-nomktex',
196
+ 'tfm',
197
+ '-ouptput-comment',
198
+ 'This is a long comment',
199
+ '-output-directory',
200
+ '~/texmf/tex',
201
+ '-parse-first-line',
202
+ '-progname',
203
+ 'pdflatex',
204
+ '-recorder',
205
+ '-shell-escape',
206
+ '-src-specials',
207
+ 'cr,display,hbox,math,par',
208
+ '-translate-file',
209
+ 'willy',
210
+ '-version',
211
+ '&myformat',
212
+ 'file_name.tex.erb'
213
+ ]
214
+ @argv_with_cmds =
215
+ [
216
+ '-draftmode',
217
+ '-enc',
218
+ '-etex',
219
+ '-file-line-error',
220
+ '-fmt',
221
+ 'junk',
222
+ '-halt-on-error',
223
+ '-ini',
224
+ '-interaction',
225
+ 'batchmode',
226
+ '-ipc',
227
+ '-ipc-start',
228
+ '-jobname',
229
+ 'junk',
230
+ '-kpathsea-debug',
231
+ '8',
232
+ '-mktex',
233
+ 'tex',
234
+ '--invoke=pdflatex',
235
+ '-mltex',
236
+ '-nomktex',
237
+ 'tfm',
238
+ '-ouptput-comment',
239
+ 'This is a long comment',
240
+ '-output-directory',
241
+ '~/texmf/tex',
242
+ '-parse-first-line',
243
+ '-progname',
244
+ 'pdflatex',
245
+ '-recorder',
246
+ '-shell-escape',
247
+ '-src-specials',
248
+ 'cr,display,hbox,math,par',
249
+ '-translate-file',
250
+ 'willy',
251
+ '-version',
252
+ '&myformat',
253
+ '\\input{junk.tex}',
254
+ '\\print',
255
+ 'these',
256
+ '\\items',
257
+ '\\end',
258
+ 'not_a_file'
259
+ ]
260
+ @argv_with_file_cmds =
261
+ [
262
+ '-draftmode',
263
+ '-enc',
264
+ '-etex',
265
+ '-file-line-error',
266
+ '-fmt',
267
+ 'junk',
268
+ '-halt-on-error',
269
+ '-ini',
270
+ '-interaction',
271
+ 'batchmode',
272
+ '-ipc',
273
+ '-ipc-start',
274
+ '-jobname',
275
+ 'junk',
276
+ '-kpathsea-debug',
277
+ '8',
278
+ '-mktex',
279
+ 'tex',
280
+ '--invoke=pdflatex',
281
+ '-mltex',
282
+ '-nomktex',
283
+ 'tfm',
284
+ '-ouptput-comment',
285
+ 'This is a long comment',
286
+ '-output-directory',
287
+ '~/texmf/tex',
288
+ '-parse-first-line',
289
+ '-progname',
290
+ 'pdflatex',
291
+ '-recorder',
292
+ '-shell-escape',
293
+ '-src-specials',
294
+ 'cr,display,hbox,math,par',
295
+ '-translate-file',
296
+ 'willy',
297
+ '-version',
298
+ '&myformat',
299
+ 'file_name',
300
+ '\\input{junk.tex}',
301
+ '\\print',
302
+ 'these',
303
+ '\\items',
304
+ '\\end',
305
+ 'not_a_file'
306
+ ]
307
+ end
308
+
309
+ it 'parse command line with file name' do
310
+ cl = CommandLine.new(@argv_with_file)
311
+ expect(cl.erbtex_name).to eq('erbtex')
312
+ expect(cl.tex_program).to eq('pdflatex')
313
+ expect(cl.input_file).to eq('file_name.tex.erb')
314
+ expect(cl.tex_command).to eq(Shellwords.split(<<~'EOS'))
315
+ pdflatex -draftmode -enc -etex -file-line-error -fmt junk -halt-on-error
316
+ -ini -interaction batchmode -ipc -ipc-start -jobname junk -kpathsea-debug 8
317
+ -mktex tex -mltex -nomktex tfm
318
+ -ouptput-comment This\ is\ a\ long\ comment
319
+ -output-directory \~/texmf/tex -parse-first-line -progname pdflatex
320
+ -recorder -shell-escape -src-specials cr,display,hbox,math,par
321
+ -translate-file willy -version \&myformat file_name.tex.erb
322
+ EOS
323
+ end
324
+
325
+ it 'parse command line with remote file name' do
326
+ cl = CommandLine.new(@argv_with_remote_file)
327
+ expect(cl.erbtex_name).to eq('erbtex')
328
+ expect(cl.tex_program).to eq('pdflatex')
329
+ expect(cl.input_file).to eq('example_files/file_name.tex.erb')
330
+ expect(cl.tex_command).to eq(Shellwords.split(<<~'EOS'))
331
+ pdflatex -draftmode -enc -etex -file-line-error -fmt junk -halt-on-error
332
+ -ini -interaction batchmode -ipc -ipc-start -jobname junk -kpathsea-debug 8
333
+ -mktex tex -mltex -nomktex tfm
334
+ -ouptput-comment This\ is\ a\ long\ comment
335
+ -output-directory \~/texmf/tex -parse-first-line -progname pdflatex
336
+ -recorder -shell-escape -src-specials cr,display,hbox,math,par
337
+ -translate-file willy -version \&myformat example_files/file_name.tex.erb
338
+ EOS
339
+ end
340
+
341
+ it 'parse command line with invoke and file name' do
342
+ cl = CommandLine.new(@argv_with_invoke_and_file)
343
+ expect(cl.erbtex_name).to eq('erbtex')
344
+ expect(cl.tex_program).to eq('lualatex')
345
+ expect(cl.input_file).to eq('file_name.tex.erb')
346
+ expect(cl.tex_command).to eq(Shellwords.split(<<~'EOS'))
347
+ lualatex -draftmode -enc -etex -file-line-error -fmt junk -halt-on-error
348
+ -ini -interaction batchmode -ipc -ipc-start -jobname junk -kpathsea-debug 8
349
+ -mktex tex -mltex -nomktex tfm
350
+ -ouptput-comment This\ is\ a\ long\ comment
351
+ -output-directory \~/texmf/tex -parse-first-line -progname pdflatex
352
+ -recorder -shell-escape -src-specials cr,display,hbox,math,par
353
+ -translate-file willy -version \&myformat file_name.tex.erb
354
+ EOS
355
+ end
356
+
357
+ it 'parse command line with TeX commands' do
358
+ cl = CommandLine.new(@argv_with_cmds)
359
+ expect(cl.erbtex_name).to eq('erbtex')
360
+ expect(cl.tex_program).to eq('pdflatex')
361
+ expect(cl.input_file).to be_nil
362
+ expect(cl.tex_command).to eq(Shellwords.split(<<~'EOS'))
363
+ pdflatex -draftmode -enc -etex -file-line-error -fmt junk -halt-on-error
364
+ -ini -interaction batchmode -ipc -ipc-start -jobname junk -kpathsea-debug 8
365
+ -mktex tex -mltex -nomktex tfm
366
+ -ouptput-comment This\ is\ a\ long\ comment
367
+ -output-directory \~/texmf/tex -parse-first-line -progname pdflatex
368
+ -recorder -shell-escape -src-specials cr,display,hbox,math,par
369
+ -translate-file willy -version \&myformat
370
+ \\input\{junk.tex\} \\print these \\items \\end not_a_file
371
+ EOS
372
+ end
373
+
374
+ it 'parse command line with a file name and TeX commands' do
375
+ cl = CommandLine.new(@argv_with_file_cmds)
376
+ expect(cl.erbtex_name).to eq('erbtex')
377
+ expect(cl.tex_program).to eq('pdflatex')
378
+ expect(cl.input_file).to eq('file_name')
379
+ expect(cl.tex_command).to eq(Shellwords.split(<<~'EOS'))
380
+ pdflatex -draftmode -enc -etex -file-line-error -fmt junk -halt-on-error
381
+ -ini -interaction batchmode -ipc -ipc-start -jobname junk -kpathsea-debug 8
382
+ -mktex tex -mltex -nomktex tfm
383
+ -ouptput-comment This\ is\ a\ long\ comment
384
+ -output-directory \~/texmf/tex -parse-first-line -progname pdflatex
385
+ -recorder -shell-escape -src-specials cr,display,hbox,math,par
386
+ -translate-file willy -version \&myformat
387
+ file_name
388
+ \\input\{junk.tex\} \\print these \\items \\end not_a_file
389
+ EOS
390
+ end
391
+ end
392
+ end
393
+ end
@@ -1,57 +1,48 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module ErbTeX
4
6
  describe 'expand input file' do
5
- before :all do
6
- unless Dir.exist?('tmp')
7
- FileUtils.mkdir_p('tmp')
8
- end
9
- end
10
-
11
- before :each do
7
+ before do
8
+ FileUtils.mkdir_p('tmp') unless Dir.exist?('tmp')
12
9
  FileUtils.rm_f Dir.glob('tmp/*')
13
10
  end
14
11
 
15
- after :all do
12
+ after do
16
13
  FileUtils.rm_rf('tmp')
17
14
  end
18
15
 
19
- it 'expand file name with no extension and .tex existing' do
16
+ it 'expands file name with no extension and .tex existing' do
20
17
  FileUtils.touch('tmp/junk.tex')
21
18
  expect(ErbTeX.expand_input_file('tmp/junk')).to eq('tmp/junk.tex')
22
19
  end
23
20
 
24
- it 'expand file name with no extension and .tex.erb existing' do
21
+ it 'expands file name with no extension and .tex.erb existing' do
25
22
  FileUtils.touch('tmp/junk.tex.erb')
26
23
  expect(ErbTeX.expand_input_file('tmp/junk'))
27
24
  .to eq('tmp/junk.tex.erb')
28
25
  end
29
26
 
30
- it 'expand file name with no extension and .erb existing' do
27
+ it 'expands file name with no extension and .erb existing' do
31
28
  FileUtils.touch('tmp/junk.erb')
32
29
  expect(ErbTeX.expand_input_file('tmp/junk'))
33
30
  .to eq('tmp/junk.erb')
34
31
  end
35
32
 
36
- it 'expand file name with no extension and .tex existing' do
37
- FileUtils.touch('tmp/junk.tex')
38
- expect(ErbTeX.expand_input_file('tmp/junk'))
39
- .to eq('tmp/junk.tex')
40
- end
41
-
42
- it 'expand file name with .tex extension and .tex existing' do
33
+ it 'expands file name with .tex extension and .tex existing' do
43
34
  FileUtils.touch('tmp/junk.tex')
44
35
  expect(ErbTeX.expand_input_file('tmp/junk.tex'))
45
36
  .to eq('tmp/junk.tex')
46
37
  end
47
38
 
48
- it 'expand file name with .tex extension and not existing' do
39
+ it 'expands file name with .tex extension and not existing' do
49
40
  FileUtils.rm_rf('tmp/junk.tex') if File.exist?('tmp/junk.tex')
50
41
  expect(ErbTeX.expand_input_file('tmp/junk.tex'))
51
42
  .to eq('tmp/junk.tex')
52
43
  end
53
44
 
54
- it 'expand file name with funny extension and not existing' do
45
+ it 'expands file name with funny extension and not existing' do
55
46
  expect(ErbTeX.expand_input_file('tmp/junk.arb'))
56
47
  .to eq('tmp/junk.arb')
57
48
  end