@@ -342,6 +342,19 @@ let verify
342
342
Typing. run_from_pause check paused)
343
343
344
344
345
+ let handle_error_with_user_guidance ~(label : string ) (e : exn ) : unit =
346
+ let msg = Printexc. to_string e in
347
+ let stack = Printexc. get_backtrace () in
348
+ Printf. eprintf " cn: internal error, uncaught exception:\n %s\n " msg;
349
+ let lines = String. split_on_char '\n' stack in
350
+ List. iter (fun line -> Printf. eprintf " %s\n " line) lines;
351
+ Printf. eprintf
352
+ " Issues can be made at https://github.com/rems-project/cerberus/issues.\n " ;
353
+ Printf. eprintf " Prefix your issue with \" [%s]\" . " label;
354
+ Printf. eprintf " Check that there isn't already one for this error.\n " ;
355
+ exit 1
356
+
357
+
345
358
let generate_executable_specs
346
359
filename
347
360
macros
@@ -404,16 +417,19 @@ let generate_executable_specs
404
417
~f: (fun ~prog5 ~ail_prog ~statement_locs ~paused :_ ->
405
418
Cerb_colour. without_colour
406
419
(fun () ->
407
- Executable_spec. main
408
- ~without_ownership_checking
409
- ~with_test_gen
410
- ~copy_source_dir
411
- filename
412
- ail_prog
413
- output_decorated
414
- output_decorated_dir
415
- prog5
416
- statement_locs;
420
+ (try
421
+ Executable_spec. main
422
+ ~without_ownership_checking
423
+ ~with_test_gen
424
+ ~copy_source_dir
425
+ filename
426
+ ail_prog
427
+ output_decorated
428
+ output_decorated_dir
429
+ prog5
430
+ statement_locs
431
+ with
432
+ | e -> handle_error_with_user_guidance ~label: " CN-Exec" e);
417
433
Resultat. return () )
418
434
() )
419
435
@@ -489,25 +505,28 @@ let run_tests
489
505
Option. is_some inst.internal)
490
506
|> List. is_empty
491
507
then (
492
- print_endline " No testable functions, aborting " ;
493
- exit 1 );
508
+ print_endline " No testable functions, trivially passing " ;
509
+ exit 0 );
494
510
if not (Sys. file_exists output_dir) then (
495
511
print_endline (" Directory \" " ^ output_dir ^ " \" does not exist." );
496
512
Sys. mkdir output_dir 0o777 ;
497
513
print_endline
498
514
(" Created directory \" " ^ output_dir ^ " \" with full permissions." ));
499
515
let _, sigma = ail_prog in
500
516
Cn_internal_to_ail. augment_record_map (BaseTypes. Record [] );
501
- Executable_spec. main
502
- ~without_ownership_checking
503
- ~with_test_gen: true
504
- ~copy_source_dir: false
505
- filename
506
- ail_prog
507
- None
508
- (Some output_dir)
509
- prog5
510
- statement_locs;
517
+ (try
518
+ Executable_spec. main
519
+ ~without_ownership_checking
520
+ ~with_test_gen: true
521
+ ~copy_source_dir: false
522
+ filename
523
+ ail_prog
524
+ None
525
+ (Some output_dir)
526
+ prog5
527
+ statement_locs
528
+ with
529
+ | e -> handle_error_with_user_guidance ~label: " CN-Exec" e);
511
530
let config : TestGeneration.config =
512
531
{ num_samples;
513
532
max_backtracks;
@@ -529,13 +548,16 @@ let run_tests
529
548
disable_passes
530
549
}
531
550
in
532
- TestGeneration. run
533
- ~output_dir
534
- ~filename
535
- ~without_ownership_checking
536
- config
537
- sigma
538
- prog5;
551
+ (try
552
+ TestGeneration. run
553
+ ~output_dir
554
+ ~filename
555
+ ~without_ownership_checking
556
+ config
557
+ sigma
558
+ prog5
559
+ with
560
+ | e -> handle_error_with_user_guidance ~label: " CN-Test-Gen" e);
539
561
if not dont_run then
540
562
Unix. execv (Filename. concat output_dir " run_tests.sh" ) (Array. of_list [] ))
541
563
() ;
0 commit comments