Skip to content

Commit fcb8e01

Browse files
committed
Porting examples from existing tests
- https://github.com/zombocom/dead_end/blob/622dfddda92e27235425dd5a370618c5257731e8/spec/unit/code_search_spec.rb ``` 22 examples, 9 failures Failed examples: rspec ./spec/integration/dead_end_spec.rb:208 # Integration tests that don't spawn a process (like using the cli) missing `do` highlights more than `end` simple rspec ./spec/integration/dead_end_spec.rb:239 # Integration tests that don't spawn a process (like using the cli) missing `do` highlights more than `end`, with internal contents rspec ./spec/integration/dead_end_spec.rb:302 # Integration tests that don't spawn a process (like using the cli) squished do regression rspec ./spec/integration/dead_end_spec.rb:400 # Integration tests that don't spawn a process (like using the cli) handles no spaces between blocks rspec ./spec/integration/dead_end_spec.rb:447 # Integration tests that don't spawn a process (like using the cli) Format Code blocks real world example rspec ./spec/integration/dead_end_spec.rb:492 # Integration tests that don't spawn a process (like using the cli) returns syntax error in outer block without inner block rspec ./spec/integration/dead_end_spec.rb:514 # Integration tests that don't spawn a process (like using the cli) finds multiple syntax errors rspec ./spec/integration/dead_end_spec.rb:547 # Integration tests that don't spawn a process (like using the cli) finds a naked end rspec ./spec/integration/dead_end_spec.rb:565 # Integration tests that don't spawn a process (like using the cli) handles mismatched | ``` Failing tests need to be investigated. Most are variations on a missing keyword but present end. Next I want to group related failures together in the file so I can understand which might have competing requirements/properties. The other thing that seems difficult is that this sometimes identifies one syntax error as several which the old algorithm never did.
1 parent 91b94a4 commit fcb8e01

File tree

1 file changed

+325
-0
lines changed

1 file changed

+325
-0
lines changed

spec/integration/dead_end_spec.rb

Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module DeadEnd
3434
EOM
3535
end
3636

37+
3738
it "re-checks all block code, not just what's visible issues/95" do
3839
file = fixtures_dir.join("ruby_buildpack.rb.txt")
3940
io = StringIO.new
@@ -275,5 +276,329 @@ def bark
275276
19 end
276277
EOM
277278
end
279+
280+
it "works with valid code" do
281+
source = <<~'EOM'
282+
class OH
283+
def hello
284+
end
285+
def hai
286+
end
287+
end
288+
EOM
289+
290+
io = StringIO.new
291+
DeadEnd.call(
292+
io: io,
293+
source: source
294+
)
295+
out = io.string
296+
297+
expect(out).to include(<<~EOM)
298+
Syntax OK
299+
EOM
300+
end
301+
302+
it "squished do regression" do
303+
source = <<~'EOM'
304+
def call
305+
trydo
306+
@options = CommandLineParser.new.parse
307+
options.requires.each { |r| require!(r) }
308+
load_global_config_if_exists
309+
options.loads.each { |file| load(file) }
310+
@user_source_code = ARGV.join(' ')
311+
@user_source_code = 'self' if @user_source_code == ''
312+
@callable = create_callable
313+
init_rexe_context
314+
init_parser_and_formatters
315+
# This is where the user's source code will be executed; the action will in turn call `execute`.
316+
lookup_action(options.input_mode).call unless options.noop
317+
output_log_entry
318+
end # one
319+
end # two
320+
EOM
321+
322+
io = StringIO.new
323+
DeadEnd.call(
324+
io: io,
325+
source: source
326+
)
327+
out = io.string
328+
329+
expect(out).to eq(<<~'EOM'.indent(2))
330+
1 def call
331+
❯ 2 trydo
332+
❯ 15 end # one
333+
16 end
334+
EOM
335+
end
336+
337+
it "handles mismatched }" do
338+
source = <<~EOM
339+
class Blerg
340+
Foo.call do {
341+
puts lol
342+
class Foo
343+
end # two
344+
end # three
345+
EOM
346+
347+
io = StringIO.new
348+
DeadEnd.call(
349+
io: io,
350+
source: source
351+
)
352+
353+
expect(io.string).to include(<<~'EOM')
354+
1 class Blerg
355+
❯ 2 Foo.call do {
356+
4 class Foo
357+
5 end # two
358+
6 end # three
359+
EOM
360+
end
361+
362+
it "handles no spaces between blocks and trailing slash" do
363+
source = <<~'EOM'
364+
require "rails_helper"
365+
RSpec.describe Foo, type: :model do
366+
describe "#bar" do
367+
context "context" do
368+
it "foos the bar with a foo and then bazes the foo with a bar to"\
369+
"fooify the barred bar" do
370+
travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do
371+
foo = build(:foo)
372+
end
373+
end
374+
end
375+
end
376+
describe "#baz?" do
377+
context "baz has barred the foo" do
378+
it "returns true" do # <== HERE
379+
end
380+
end
381+
end
382+
EOM
383+
384+
io = StringIO.new
385+
DeadEnd.call(
386+
io: io,
387+
source: source
388+
)
389+
390+
expect(io.string).to include(<<~'EOM')
391+
2 RSpec.describe Foo, type: :model do
392+
13 describe "#baz?" do
393+
❯ 14 context "baz has barred the foo" do
394+
16 end
395+
17 end
396+
18 end
397+
EOM
398+
end
399+
400+
it "handles no spaces between blocks" do
401+
source = <<~'EOM'
402+
context "foo bar" do
403+
it "bars the foo" do
404+
travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do
405+
end
406+
end
407+
end
408+
context "test" do
409+
it "should" do
410+
end
411+
EOM
412+
io = StringIO.new
413+
DeadEnd.call(
414+
io: io,
415+
source: source
416+
)
417+
418+
expect(io.string).to include(<<~'EOM')
419+
7 context "test" do
420+
❯ 8 it "should" do
421+
9 end
422+
EOM
423+
end
424+
425+
it "finds hanging def in this project" do
426+
source = fixtures_dir.join("this_project_extra_def.rb.txt").read
427+
428+
io = StringIO.new
429+
DeadEnd.call(
430+
io: io,
431+
source: source
432+
)
433+
434+
expect(io.string).to include(<<~'EOM')
435+
1 module SyntaxErrorSearch
436+
3 class DisplayInvalidBlocks
437+
17 def call
438+
34 end
439+
❯ 36 def filename
440+
38 def code_with_filename
441+
45 end
442+
63 end
443+
64 end
444+
EOM
445+
end
446+
447+
it "Format Code blocks real world example" do
448+
source = <<~'EOM'
449+
require 'rails_helper'
450+
RSpec.describe AclassNameHere, type: :worker do
451+
describe "thing" do
452+
context "when" do
453+
let(:thing) { stuff }
454+
let(:another_thing) { moarstuff }
455+
subject { foo.new.perform(foo.id, true) }
456+
it "stuff" do
457+
subject
458+
expect(foo.foo.foo).to eq(true)
459+
end
460+
end
461+
end # line 16 accidental end, but valid block
462+
context "stuff" do
463+
let(:thing) { create(:foo, foo: stuff) }
464+
let(:another_thing) { create(:stuff) }
465+
subject { described_class.new.perform(foo.id, false) }
466+
it "more stuff" do
467+
subject
468+
expect(foo.foo.foo).to eq(false)
469+
end
470+
end
471+
end # mismatched due to 16
472+
end
473+
EOM
474+
475+
io = StringIO.new
476+
DeadEnd.call(
477+
io: io,
478+
source: source
479+
)
480+
481+
expect(io.string).to include(<<~'EOM')
482+
1 require 'rails_helper'
483+
2
484+
3 RSpec.describe AclassNameHere, type: :worker do
485+
❯ 4 describe "thing" do
486+
❯ 16 end # line 16 accidental end, but valid block
487+
❯ 30 end # mismatched due to 16
488+
31 end
489+
EOM
490+
end
491+
492+
it "returns syntax error in outer block without inner block" do
493+
source = <<~'EOM'
494+
Foo.call
495+
def foo
496+
puts "lol"
497+
puts "lol"
498+
end # one
499+
end # two
500+
EOM
501+
502+
io = StringIO.new
503+
DeadEnd.call(
504+
io: io,
505+
source: source
506+
)
507+
508+
expect(io.string).to include(<<~'EOM')
509+
1 Foo.call
510+
❯ 6 end # two
511+
EOM
512+
end
513+
514+
it "finds multiple syntax errors" do
515+
source = <<~'EOM'
516+
describe "hi" do
517+
Foo.call
518+
end
519+
end
520+
it "blerg" do
521+
Bar.call
522+
end
523+
end
524+
EOM
525+
526+
io = StringIO.new
527+
DeadEnd.call(
528+
io: io,
529+
source: source
530+
)
531+
532+
expect(io.string).to include(<<~'EOM')
533+
1 describe "hi" do
534+
❯ 2 Foo.call
535+
❯ 3 end
536+
4 end
537+
EOM
538+
539+
expect(io.string).to include(<<~'EOM')
540+
5 it "blerg" do
541+
❯ 6 Bar.call
542+
❯ 7 end
543+
8 end
544+
EOM
545+
end
546+
547+
it "finds a naked end" do
548+
source = <<~'EOM'
549+
def foo
550+
end # one
551+
end # two
552+
EOM
553+
554+
io = StringIO.new
555+
DeadEnd.call(
556+
io: io,
557+
source: source
558+
)
559+
560+
expect(io.string).to include(<<~'EOM')
561+
❯ end # one
562+
EOM
563+
end
564+
565+
it "handles mismatched |" do
566+
source = <<~EOM
567+
class Blerg
568+
Foo.call do |a
569+
end # one
570+
puts lol
571+
class Foo
572+
end # two
573+
end # three
574+
EOM
575+
576+
io = StringIO.new
577+
DeadEnd.call(
578+
io: io,
579+
source: source
580+
)
581+
582+
expect(io.string).to include(<<~'EOM')
583+
Unmatched `|', missing `|' ?
584+
Unmatched keyword, missing `end' ?
585+
586+
1 class Blerg
587+
❯ 2 Foo.call do |a
588+
5 class Foo
589+
6 end # two
590+
7 end # three
591+
Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ?
592+
593+
1 class Blerg
594+
❯ 3 end # one
595+
5 class Foo
596+
6 end # two
597+
7 end # three
598+
EOM
599+
600+
raise("this should be one failure, not two")
601+
end
602+
278603
end
279604
end

0 commit comments

Comments
 (0)