diff --git a/.gitattributes b/.gitattributes
index 5e05e8eecd..e4a2d7bfa4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -5757,6 +5757,7 @@ test/bugs/testfileutil.pas svneol=native#text/plain
test/bugtestcase.pas svneol=native#text/plain
test/codetoolstests/testbasiccodetools.pas svneol=native#text/plain
test/codetoolstests/testcompleteblock.pas svneol=native#text/plain
+test/codetoolstests/testctrangescan.pas svneol=native#text/plain
test/codetoolstests/testctxmlfixfragments.pas svneol=native#text/pascal
test/hello.ahk svneol=native#text/plain
test/lcltests/testpen.pas svneol=native#text/plain
diff --git a/test/codetoolstests/testctrangescan.pas b/test/codetoolstests/testctrangescan.pas
new file mode 100644
index 0000000000..1d3198288a
--- /dev/null
+++ b/test/codetoolstests/testctrangescan.pas
@@ -0,0 +1,60 @@
+{
+ Test with:
+ ./runtests --format=plain --suite=TestCTScanRange
+}
+unit TestCTRangeScan;
+
+{$mode objfpc}{$H+}
+
+interface
+
+{$IFNDEF EnableCTRange}
+implementation
+end.
+{$ENDIF}
+
+uses
+ Classes, SysUtils, fpcunit, testglobals,
+ CodeToolManager, CodeCache, CustomCodeTool, LinkScanner;
+
+type
+
+ { TTestCodetoolsRangeScan }
+
+ TTestCodetoolsRangeScan = class(TTestCase)
+ protected
+ published
+ procedure TestCTScanRange;
+ end;
+
+implementation
+
+{ TTestCodetoolsRangeScan }
+
+procedure TTestCodetoolsRangeScan.TestCTScanRange;
+var
+ Code: TCodeBuffer;
+ Tool: TCodeTool;
+begin
+ Code:=CodeToolBoss.CreateFile('TestRangeScan.pas');
+ Code.Source:=
+ 'unit TestRangeScan;'+LineEnding
+ +'interface'+LineEnding
+ +'uses'+LineEnding
+ +' Classes;'+LineEnding
+ +'var i: integer;'+LineEnding
+ +'implementation'+LineEnding
+ +'uses'+LineEnding
+ +' Math;'+LineEnding
+ +'const c = 3;'+LineEnding
+ +'end.';
+ Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool;
+ Tool.BuildTree(lsrInitializationStart);
+ Tool.WriteDebugTreeReport;
+end;
+
+initialization
+ AddToCodetoolsTestSuite(TTestCodetoolsRangeScan);
+
+end.
+
diff --git a/test/runtests.lpi b/test/runtests.lpi
index f70574e575..fe4516fb45 100644
--- a/test/runtests.lpi
+++ b/test/runtests.lpi
@@ -39,7 +39,7 @@
-
+
@@ -95,6 +95,11 @@
+
+
+
+
+
@@ -103,6 +108,14 @@
+
+
+
+
+
+
+
diff --git a/test/runtests.lpr b/test/runtests.lpr
index a276ee4583..f3c33032f8 100644
--- a/test/runtests.lpr
+++ b/test/runtests.lpr
@@ -24,7 +24,7 @@ uses
Classes, consoletestrunner,
testglobals, testunits, dom,
{Unit needed to set the LCL version and widget set name}
- LCLVersion, InterfaceBase, Interfaces, TestCTXMLFixFragments;
+ LCLVersion, InterfaceBase, Interfaces, TestCTXMLFixFragments, TestCTRangeScan;
type