• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/04_modules/21_changed_source_compile

  1 Each loadfile() or include() call reads the current content of the file, also
  2 after an exception read the source line of an earlier version for its context.
  3 
  4 A program of an earlier call stays alive and keeps the line information of
  5 its own compilation, also after a later compilation of that file failed.
  6 
  7 -- Testcase --
  8 import * as fs from 'fs';
  9 
 10 function run(label, fn) {
 11         try {
 12                 fn();
 13         }
 14         catch (e) {
 15                 printf("%s: %s: %s\n", label, e.type, split(e.message, "\n")[0]);
 16         }
 17 }
 18 
 19 function load(label, path, code) {
 20         fs.writefile(path, code);
 21         run(label, () => loadfile(path)());
 22 }
 23 
 24 fs.mkdir("files");
 25 
 26 load("longer #1", "files/longer.uc", "print('short\\n');\nnull.x = 1;\n");
 27 load("longer #2", "files/longer.uc", "print('a longer second version\\n');\n");
 28 
 29 load("shorter #1", "files/shorter.uc", "print('a longer first version\\n');\nnull.x = 1;\n");
 30 load("shorter #2", "files/shorter.uc", "print('short\\n');\n");
 31 
 32 load("broken #1", "files/broken.uc", "print('valid\\n');\nnull.x = 1;\n");
 33 load("broken #2", "files/broken.uc", "let = 1;\n");
 34 load("broken #3", "files/broken.uc", "print('valid again\\n');\n");
 35 
 36 function line(label, fn) {
 37         try {
 38                 fn();
 39         }
 40         catch (e) {
 41                 printf("%s: line %d\n", label, e.stacktrace[0].line);
 42         }
 43 }
 44 
 45 let raise = "return function() {\n\tnull.x = 1;\n};\n";
 46 
 47 fs.writefile("files/live.uc", raise);
 48 let first = loadfile("files/live.uc")();
 49 line("first #1", first);
 50 
 51 fs.writefile("files/live.uc", "\n\n\n" + raise);
 52 let second = loadfile("files/live.uc")();
 53 line("first #2", first);
 54 line("second #1", second);
 55 
 56 fs.writefile("files/live.uc", "let = 1;\n");
 57 run("live", () => loadfile("files/live.uc"));
 58 line("first #3", first);
 59 line("second #2", second);
 60 -- End --
 61 
 62 -- Args --
 63 -R
 64 -- End --
 65 
 66 -- Expect stdout --
 67 short
 68 longer #1: Type error: attempt to set property on null value
 69 a longer second version
 70 a longer first version
 71 shorter #1: Type error: attempt to set property on null value
 72 short
 73 valid
 74 broken #1: Type error: attempt to set property on null value
 75 broken #2: Runtime error: Unable to compile source file 'files/broken.uc':
 76 valid again
 77 first #1: line 2
 78 first #2: line 2
 79 second #1: line 5
 80 live: Runtime error: Unable to compile source file 'files/live.uc':
 81 first #3: line 2
 82 second #2: line 5
 83 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt