@@ -72,6 +72,26 @@ defmodule ElixirLS.Debugger.ServerTest do
72
72
end )
73
73
end
74
74
75
+ test "fails when not supported arguments passed" , % { server: server } do
76
+ in_fixture ( __DIR__ , "mix_project" , fn ->
77
+ Server . receive_packet (
78
+ server ,
79
+ initialize_req ( 1 , % { "clientID" => "some_id" , "linesStartAt1" => false } )
80
+ )
81
+
82
+ assert_receive (
83
+ error_response (
84
+ _ ,
85
+ 1 ,
86
+ "initialize" ,
87
+ "invalidRequest" ,
88
+ "0-based lines are not supported" ,
89
+ % { }
90
+ )
91
+ )
92
+ end )
93
+ end
94
+
75
95
test "rejects requests when not initialized" , % { server: server } do
76
96
in_fixture ( __DIR__ , "mix_project" , fn ->
77
97
Server . receive_packet (
@@ -372,6 +392,151 @@ defmodule ElixirLS.Debugger.ServerTest do
372
392
assert_receive ( event ( _ , "terminated" , % { "restart" => false } ) )
373
393
end )
374
394
end
395
+
396
+ @ tag :fixture
397
+ test "launch mix task that raises" , % { server: server } do
398
+ in_fixture ( __DIR__ , "mix_project" , fn ->
399
+ Server . receive_packet (
400
+ server ,
401
+ initialize_req ( 1 , % {
402
+ "supportsVariablePaging" => true ,
403
+ "supportsVariableType" => true
404
+ } )
405
+ )
406
+
407
+ assert_receive ( response ( _ , 1 , "initialize" , % { "supportsConfigurationDoneRequest" => true } ) )
408
+
409
+ Server . receive_packet (
410
+ server ,
411
+ launch_req ( 2 , % {
412
+ "request" => "launch" ,
413
+ "type" => "mix_task" ,
414
+ "noDebug" => true ,
415
+ "task" => "run" ,
416
+ "taskArgs" => [ "-e" , "MixProject.Crash.fun_that_raises()" ] ,
417
+ "projectDir" => File . cwd! ( )
418
+ } )
419
+ )
420
+
421
+ assert_receive ( response ( _ , 2 , "launch" , % { } ) , 5000 )
422
+ assert_receive ( event ( _ , "initialized" , % { } ) )
423
+
424
+ Server . receive_packet ( server , request ( 5 , "configurationDone" , % { } ) )
425
+ assert_receive ( response ( _ , 5 , "configurationDone" , % { } ) )
426
+
427
+ assert_receive event ( _ , "output" , % {
428
+ "category" => "console" ,
429
+ "output" =>
430
+ "Mix task exited with reason\n an exception was raised:\n ** (RuntimeError) foo" <>
431
+ _
432
+ } ) ,
433
+ 3000
434
+
435
+ assert_receive (
436
+ event ( _ , "exited" , % {
437
+ "exitCode" => 1
438
+ } ) ,
439
+ 3000
440
+ )
441
+
442
+ assert_receive ( event ( _ , "terminated" , % { "restart" => false } ) )
443
+ end )
444
+ end
445
+
446
+ @ tag :fixture
447
+ test "launch mix task that fails to initialze" , % { server: server } do
448
+ in_fixture ( __DIR__ , "mix_project" , fn ->
449
+ Server . receive_packet (
450
+ server ,
451
+ initialize_req ( 1 , % {
452
+ "supportsVariablePaging" => true ,
453
+ "supportsVariableType" => true
454
+ } )
455
+ )
456
+
457
+ assert_receive ( response ( _ , 1 , "initialize" , % { "supportsConfigurationDoneRequest" => true } ) )
458
+
459
+ Server . receive_packet (
460
+ server ,
461
+ launch_req ( 2 , % {
462
+ "request" => "launch" ,
463
+ "type" => "mix_task" ,
464
+ "noDebug" => true ,
465
+ "task" => "ru/n" ,
466
+ "taskArgs" => [ ] ,
467
+ "projectDir" => File . cwd! ( )
468
+ } )
469
+ )
470
+
471
+ assert_receive ( response ( _ , 2 , "launch" , % { } ) , 5000 )
472
+ refute_receive ( event ( _ , "initialized" , % { } ) )
473
+
474
+ assert_receive event ( _ , "output" , % {
475
+ "category" => "console" ,
476
+ "output" =>
477
+ "Launch request failed with reason\n an exception was raised:\n ** (Mix.NoTaskError)" <>
478
+ _
479
+ } ) ,
480
+ 3000
481
+
482
+ assert_receive (
483
+ event ( _ , "exited" , % {
484
+ "exitCode" => 1
485
+ } ) ,
486
+ 3000
487
+ )
488
+
489
+ assert_receive ( event ( _ , "terminated" , % { "restart" => false } ) )
490
+ end )
491
+ end
492
+
493
+ @ tag :fixture
494
+ test "launch invalid mix task" , % { server: server } do
495
+ in_fixture ( __DIR__ , "mix_project" , fn ->
496
+ Server . receive_packet (
497
+ server ,
498
+ initialize_req ( 1 , % {
499
+ "supportsVariablePaging" => true ,
500
+ "supportsVariableType" => true
501
+ } )
502
+ )
503
+
504
+ assert_receive ( response ( _ , 1 , "initialize" , % { "supportsConfigurationDoneRequest" => true } ) )
505
+
506
+ Server . receive_packet (
507
+ server ,
508
+ launch_req ( 2 , % {
509
+ "request" => "launch" ,
510
+ "type" => "mix_task" ,
511
+ "noDebug" => true ,
512
+ "task" => "nonexisting" ,
513
+ "taskArgs" => [ ] ,
514
+ "projectDir" => File . cwd! ( )
515
+ } )
516
+ )
517
+
518
+ assert_receive ( response ( _ , 2 , "launch" , % { } ) , 5000 )
519
+ assert_receive ( event ( _ , "initialized" , % { } ) )
520
+
521
+ Server . receive_packet ( server , request ( 5 , "configurationDone" , % { } ) )
522
+ assert_receive ( response ( _ , 5 , "configurationDone" , % { } ) )
523
+
524
+ assert_receive event ( _ , "output" , % {
525
+ "category" => "console" ,
526
+ "output" =>
527
+ "Mix task exited with reason\n an exception was raised:\n ** (Mix.NoTaskError) The task \" nonexisting\" could not be found" <>
528
+ _
529
+ } ) ,
530
+ 3000
531
+
532
+ assert_receive (
533
+ event ( _ , "exited" , % {
534
+ "exitCode" => 1
535
+ } ) ,
536
+ 3000
537
+ )
538
+
539
+ assert_receive ( event ( _ , "terminated" , % { "restart" => false } ) )
375
540
end )
376
541
end
377
542
0 commit comments