Bladeren bron

tests: ppus: added test for recompile needed when the body of an inline function changed

mattias 1 week geleden
bovenliggende
commit
7c9082f8d5

+ 16 - 0
tests/tppu/changeinlinebody/changed/testcib_bird.pas

@@ -0,0 +1,16 @@
+unit testcib_bird;
+
+{$mode objfpc}
+
+interface
+
+function Fly(w : word): word;
+
+implementation
+
+function Fly(w : word): word; inline;
+begin
+  Result:= 3 * w;
+end;
+
+end.

+ 1 - 0
tests/tppu/changeinlinebody/lib/.gitignore

@@ -0,0 +1 @@
+testcib_prog

+ 16 - 0
tests/tppu/changeinlinebody/original/testcib_bird.pas

@@ -0,0 +1,16 @@
+unit testcib_bird;
+
+{$mode objfpc}
+
+interface
+
+function Fly(w : word): word;
+
+implementation
+
+function Fly(w : word): word; inline;
+begin
+  Result:= 13 * w;
+end;
+
+end.

+ 1 - 0
tests/tppu/changeinlinebody/pkg/lib/readme.txt

@@ -0,0 +1 @@
+Output folder for tests.

+ 11 - 0
tests/tppu/changeinlinebody/pkg/testcib_ant.pas

@@ -0,0 +1,11 @@
+unit testcib_ant;
+
+{$mode objfpc}
+
+interface
+
+uses testcib_bird;
+
+implementation
+
+end.

+ 19 - 0
tests/tppu/changeinlinebody/testcib_elk.pas

@@ -0,0 +1,19 @@
+unit testcib_elk;
+
+{$mode objfpc}
+{$inline on}
+
+interface
+
+uses testcib_bird;
+
+function Run(w : word): word;
+
+implementation
+
+function Run(w : word): word;
+begin
+  Result:= 10 * Fly(w);
+end;
+
+end.

+ 6 - 0
tests/tppu/changeinlinebody/testcib_prog.pas

@@ -0,0 +1,6 @@
+{$mode objfpc}
+uses testcib_elk;
+
+begin
+  writeln(Run(2));
+end.

+ 49 - 1
tests/tppu/tcrecompile.pas

@@ -40,6 +40,7 @@ type
     procedure TestTwoUnits; // 2 units
     procedure TestTwoUnits; // 2 units
     procedure TestChangeLeaf1; // prog+2 units, change leaf
     procedure TestChangeLeaf1; // prog+2 units, change leaf
     procedure TestChangeInner1; // prog+2 units, change inner unit, keep leaf
     procedure TestChangeInner1; // prog+2 units, change inner unit, keep leaf
+    procedure TestChangeInlineBody; // prog+1 unit plus a package of 2 units, change of inline body should change crc
 
 
     // inline modifier in implementation (not in interface)
     // inline modifier in implementation (not in interface)
     procedure TestImplInline1; // 2 units, cycle, impl inline
     procedure TestImplInline1; // 2 units, cycle, impl inline
@@ -165,7 +166,7 @@ var
   i, j: Integer;
   i, j: Integer;
 begin
 begin
   for i:=0 to length(Expected)-1 do
   for i:=0 to length(Expected)-1 do
-    if Compiled.IndexOf(Expected[i])<0 then
+    if (Compiled=nil) or (Compiled.IndexOf(Expected[i])<0) then
       Fail('missing compiling "'+Expected[i]+'", Step='+Step);
       Fail('missing compiling "'+Expected[i]+'", Step='+Step);
   for i:=0 to Compiled.Count-1 do
   for i:=0 to Compiled.Count-1 do
   begin
   begin
@@ -263,6 +264,53 @@ begin
   CheckCompiled(['changeinner1_prg.pas','changeinner1_ant.pas']);
   CheckCompiled(['changeinner1_prg.pas','changeinner1_ant.pas']);
 end;
 end;
 
 
+procedure TTestRecompile.TestChangeInlineBody;
+var
+  ProgDir, PkgDir, PkgOutDir: String;
+begin
+  // unit testcib_elk uses an inline function of unit testcib_bird
+  // elk belongs to the program, bird to the package, so they are compiled separately
+  // when the inline body of bird changes, the elk.ppu must be rebuilt too
+
+  ProgDir:='changeinlinebody'+PathDelim;
+  PkgDir:=ProgDir+'pkg';
+  PkgOutDir:=PkgDir+PathDelim+'lib';
+
+  // compile package containing testcib_ant.pas and testcib_bird.pas
+  Step:='Compile original package';
+  UnitPath:=PkgDir+';'+ProgDir+'original';
+  OutDir:=PkgOutDir;
+  MainSrc:=PkgDir+PathDelim+'testcib_ant.pas';
+  CleanOutputDir;
+  Compile;
+  CheckCompiled(['testcib_ant.pas','testcib_bird.pas']);
+
+  // compile program
+  Step:='Compile program with original package ppus';
+  UnitPath:=ProgDir+';'+PkgOutDir;
+  OutDir:=ProgDir+'lib';
+  MainSrc:=ProgDir+'testcib_prog.pas';
+  CleanOutputDir;
+  Compile;
+  CheckCompiled(['testcib_prog.pas','testcib_elk.pas']);
+
+  // recompile package with changed testcib_bird.pas
+  Step:='Compile changed package';
+  UnitPath:=PkgDir+';'+ProgDir+'changed';
+  OutDir:=PkgOutDir;
+  MainSrc:=PkgDir+PathDelim+'testcib_ant.pas';
+  Compile;
+  CheckCompiled(['testcib_ant.pas','testcib_bird.pas']);
+
+  // recompile program
+  Step:='Compile program with changed package ppus';
+  UnitPath:=ProgDir+';'+PkgOutDir;
+  OutDir:=ProgDir+'lib';
+  MainSrc:=ProgDir+'testcib_prog.pas';
+  Compile;
+  CheckCompiled(['testcib_prog.pas','testcib_elk.pas']);
+end;
+
 procedure TTestRecompile.TestImplInline1;
 procedure TTestRecompile.TestImplInline1;
 // unit ant uses bird
 // unit ant uses bird
 // unit bird impl uses ant and has a function with inline modifier in implementation
 // unit bird impl uses ant and has a function with inline modifier in implementation