diff --git a/tests/test/tlib1.pp b/tests/test/tlib1.pp
index 73a90022a7..9a444ca73b 100644
--- a/tests/test/tlib1.pp
+++ b/tests/test/tlib1.pp
@@ -1,12 +1,13 @@
-{ %opt=-gl }
+{ %opt=-gl -O- }
 { %needlibrary }
 {$goto on}
 
-{ test lineinfo in libraries }
+{ test lineinfo in libraries, to get always proper results, the optimizer
+  must be turned off with -O- }
 
 {$ifdef unix}
 uses
-  dl;
+  dl,sysutils;
 {$endif unix}
 
 procedure p(var a : pointer);external 'tlib1a' name 'p';
@@ -22,6 +23,7 @@ w:
   { library }
   p(a);
   GetLineInfo(PtrUInt(a),s1,s2,l);
+  s2:=ExtractFilename(s2);  
   writeln({ 'Func: ',s1,'} 'Source: ',s2,' Line: ',l);
   { GetLineInfo of dwarf doesn't return the function name }
   if { (s1<>'P') or } (s2<>'tlib1a.pp') or (l<>9) then
@@ -29,9 +31,10 @@ w:
 
   { main program }
   GetLineInfo(PtrUInt(@w),s1,s2,l);
+  s2:=ExtractFilename(s2);
   writeln({ 'Func: ',s1,'} 'Source: ',s2,' Line: ',l);
   { GetLineInfo of dwarf doesn't return the function name }
-  if { (s1<>'P') or } (s2<>'tlib1.pp') or (l<>20) then
+  if { (s1<>'P') or } (s2<>'tlib1.pp') or (l<>21) then
     halt(1);
   
   writeln('ok');
diff --git a/tests/test/tlib1a.pp b/tests/test/tlib1a.pp
index 362653bb98..b65c32afb1 100644
--- a/tests/test/tlib1a.pp
+++ b/tests/test/tlib1a.pp
@@ -1,5 +1,5 @@
+{ %opt=-gl -O- }
 { %norun }
-{ %opt=-gl }
 {$goto on}
 library tlib1a;