2019-07-28 23:53:15 +03:00
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
2015-06-12 21:59:28 +03:00
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
2015-05-14 22:35:07 +03:00
{$reference Compiler.dll}
{$reference CodeCompletion.dll}
{$reference Errors.dll}
{$reference CompilerTools.dll}
2016-05-06 14:56:19 +03:00
{$reference Localization.dll}
2015-05-14 22:35:07 +03:00
{$reference System.Windows.Forms.dll}
2024-05-25 12:26:32 +03:00
{$reference LanguageIntegrator.dll}
2015-05-14 22:35:07 +03:00
uses PascalABCCompiler, System. IO, System. Diagnostics;
2025-12-21 21:11:52 +03:00
type
LanguageTestsInfo = auto class
languageName: string ;
languageExtensions: array of string ;
commentSymbol: string ;
end ;
2018-06-03 20:49:55 +03:00
var
TestSuiteDir: string ;
2025-12-21 21:11:52 +03:00
CurrentLanguageInfo: LanguageTestsInfo;
2021-01-05 14:32:21 +03:00
nogui: boolean ;
2025-12-21 21:11:52 +03:00
2018-06-03 20:49:55 +03:00
var
PathSeparator: string : = Path. DirectorySeparatorChar;
2015-05-14 22:35:07 +03:00
2015-12-29 21:05:42 +03:00
function IsUnix: boolean ;
begin
Result : = ( System. Environment. OSVersion. Platform = System. PlatformID. Unix) or ( System. Environment. OSVersion. Platform = System. PlatformID. MacOSX) ;
end ;
2025-12-21 21:11:52 +03:00
function GetCurrentLanguageInfo( dir: string ) : LanguageTestsInfo;
2015-05-14 22:35:07 +03:00
begin
2025-12-21 21:11:52 +03:00
var configDict : = & File . ReadLines( dir + PathSeparator + 'testsettings.config' )
. Select( line - > line. Split( [ ':' , ' ' ] , System. StringSplitOptions. RemoveEmptyEntries) )
. ToDictionary( arr - > arr[ 0 ] , arr - > arr[ 1 ] ) ;
var languageInformation : = Languages. Facade. LanguageProvider. Instance. SelectLanguageByName( configDict[ 'languageName' ] ) . LanguageInformation;
Result : = new LanguageTestsInfo( languageInformation. Name , languageInformation. FilesExtensions, languageInformation. CommentSymbol) ;
2015-05-14 22:35:07 +03:00
end ;
2025-12-21 21:11:52 +03:00
function GetFilesByExtensions( path: string ; extensions: array of string ; searchOption: SearchOption : = System. IO. SearchOption. TopDirectoryOnly) : array of string ;
begin
Result : = extensions. SelectMany( ext - > Directory. GetFiles( path, $ '*{ext}' , searchOption) ) . ToArray( ) ;
end ;
function GetCodeExamplesDir: string ;
begin
var dir : = Path. GetDirectoryName( GetEXEFileName( ) ) ;
Result : = ( new DirectoryInfo( dir) ) . Parent. FullName + PathSeparator + 'CodeExamples' + PathSeparator + CurrentLanguageInfo. languageName;
end ;
2015-05-14 22:35:07 +03:00
procedure CompileErrorTests( withide: boolean ) ;
begin
2025-12-21 21:11:52 +03:00
var dir : = TestSuiteDir + PathSeparator + 'errors' ;
if not Directory. Exists( dir) then exit;
2021-10-31 15:48:32 +03:00
2025-12-21 21:11:52 +03:00
var commentSymbol : = CurrentLanguageInfo. commentSymbol;
var files : = GetFilesByExtensions( dir, CurrentLanguageInfo. languageExtensions) ;
2015-05-14 22:35:07 +03:00
for var i : = 0 to files. Length - 1 do
begin
2021-10-31 15:48:32 +03:00
var comp : = new Compiler( ) ;
2015-12-29 21:05:42 +03:00
var content : = & File . ReadAllText( files[ i] ) ;
2025-12-21 21:11:52 +03:00
if content. StartsWith( commentSymbol + 'winonly' ) and IsUnix then
2015-12-29 21:05:42 +03:00
continue;
2025-12-21 21:11:52 +03:00
if content. StartsWith( commentSymbol + 'exclude' ) then
2021-10-17 13:04:24 +03:00
continue;
var errorMessage : = '' ;
2025-12-21 21:11:52 +03:00
if content. StartsWith( commentSymbol + '!' ) then
2021-10-17 13:04:24 +03:00
begin
2025-12-21 21:11:52 +03:00
errorMessage : = content. Substring( commentSymbol. Length + 1 , content. IndexOf( System. Environment. NewLine) - commentSymbol. Length + 1 ) . Trim;
2021-10-17 13:04:24 +03:00
end ;
2018-06-03 20:49:55 +03:00
var co: CompilerOptions : = new CompilerOptions( files[ i] , CompilerOptions. OutputType. ConsoleApplicaton) ;
2015-05-14 22:35:07 +03:00
co. Debug : = true ;
2018-06-03 20:49:55 +03:00
co. OutputDirectory : = TestSuiteDir + PathSeparator + 'errors' ;
2015-05-14 22:35:07 +03:00
co. UseDllForSystemUnits : = false ;
co. RunWithEnvironment : = withide;
comp . ErrorsList. Clear( ) ;
comp . Warnings. Clear( ) ;
comp . Compile( co) ;
if comp . ErrorsList. Count = 0 then
begin
2021-01-05 14:32:21 +03:00
if nogui then
raise new Exception( 'Compilation of error sample ' + files[ i] + ' was successfull' ) ;
2018-06-03 20:49:55 +03:00
System. Windows. Forms. MessageBox. Show( 'Compilation of error sample ' + files[ i] + ' was successfull' + System. Environment. NewLine) ;
2016-05-15 22:01:40 +03:00
Halt( ) ;
2015-05-14 22:35:07 +03:00
end
else if comp . ErrorsList. Count = 1 then
begin
if comp . ErrorsList[ 0 ] . GetType( ) = typeof( PascalABCCompiler. Errors. CompilerInternalError) then
2021-01-05 14:32:21 +03:00
begin
if nogui then
raise new Exception( 'Compilation of ' + files[ i] + ' failed' + System. Environment. NewLine + comp . ErrorsList[ 0 ] . ToString( ) ) ;
2018-06-03 20:49:55 +03:00
System. Windows. Forms. MessageBox. Show( 'Compilation of ' + files[ i] + ' failed' + System. Environment. NewLine + comp . ErrorsList[ 0 ] . ToString( ) ) ;
2021-01-05 14:32:21 +03:00
end ;
2025-12-21 21:11:52 +03:00
if ( errorMessage < > '' ) and ( comp . ErrorsList[ comp . ErrorsList. Count - 1 ] . Message . Trim < > errorMessage) then
2021-10-17 13:04:24 +03:00
begin
2021-10-31 15:48:32 +03:00
if nogui then
2025-12-21 21:11:52 +03:00
raise new Exception( 'Wrong error message in file ' + files[ i] + ', should ' + errorMessage + ', is ' + comp . ErrorsList[ comp . ErrorsList. Count - 1 ] . Message ) ;
System. Windows. Forms. MessageBox. Show( 'Wrong error message in file ' + files[ i] + ', should ' + errorMessage + ', is ' + comp . ErrorsList[ comp . ErrorsList. Count - 1 ] . Message ) ;
2021-10-17 13:04:24 +03:00
end ;
2015-05-14 22:35:07 +03:00
end ;
2019-10-04 16:40:51 +03:00
if i mod 5 0 = 0 then
2018-01-30 22:39:20 +03:00
System. GC. Collect( ) ;
2015-05-14 22:35:07 +03:00
end ;
end ;
procedure CompileAllRunTests( withdll: boolean ; only32bit: boolean : = false ) ;
begin
var comp : = new Compiler( ) ;
2025-12-21 21:11:52 +03:00
var commentSymbol : = CurrentLanguageInfo. commentSymbol;
var files : = GetFilesByExtensions( TestSuiteDir, CurrentLanguageInfo. languageExtensions) ;
2015-05-14 22:35:07 +03:00
for var i : = 0 to files. Length - 1 do
begin
2021-04-18 18:40:56 +03:00
if IsUnix then
2025-12-21 21:11:52 +03:00
Println( 'Compile file ' + files[ i] ) ;
2015-12-29 21:05:42 +03:00
var content : = & File . ReadAllText( files[ i] ) ;
2025-12-21 21:11:52 +03:00
if content. StartsWith( commentSymbol + 'winonly' ) and IsUnix then
2015-12-29 21:05:42 +03:00
continue;
2025-12-21 21:11:52 +03:00
if content. StartsWith( commentSymbol + 'nopabcrtl' ) and withdll then
2019-06-30 15:22:24 +03:00
continue;
2018-06-03 20:49:55 +03:00
var co: CompilerOptions : = new CompilerOptions( files[ i] , CompilerOptions. OutputType. ConsoleApplicaton) ;
2015-05-14 22:35:07 +03:00
co. Debug : = true ;
2018-06-03 20:49:55 +03:00
co. OutputDirectory : = TestSuiteDir + PathSeparator + 'exe' ;
2023-08-14 00:17:35 +03:00
Directory. CreateDirectory( co. OutputDirectory) ;
2015-05-14 22:35:07 +03:00
co. UseDllForSystemUnits : = withdll;
co. RunWithEnvironment : = false ;
co. IgnoreRtlErrors : = false ;
co. Only32Bit : = only32bit;
comp . ErrorsList. Clear( ) ;
comp . Warnings. Clear( ) ;
comp . Compile( co) ;
if comp . ErrorsList. Count > 0 then
begin
2021-01-05 14:32:21 +03:00
if nogui then
raise new Exception( 'Compilation of ' + files[ i] + ' failed' + System. Environment. NewLine + comp . ErrorsList[ 0 ] . ToString( ) ) ;
2018-06-03 20:49:55 +03:00
System. Windows. Forms. MessageBox. Show( 'Compilation of ' + files[ i] + ' failed' + System. Environment. NewLine + comp . ErrorsList[ 0 ] . ToString( ) ) ;
2018-05-13 15:19:54 +03:00
Halt( ) ;
2015-05-14 22:35:07 +03:00
end ;
2025-12-21 21:11:52 +03:00
if content. StartsWith( commentSymbol + '!' ) then
2024-01-04 17:32:19 +03:00
begin
2025-12-21 21:11:52 +03:00
var warning : = content. Substring( commentSymbol. Length + 1 , content. IndexOf( System. Environment. NewLine) - commentSymbol. Length + 1 ) . Trim;
2024-01-04 17:32:19 +03:00
if comp . Warnings. Count = 0 then
begin
if nogui then
2025-12-21 21:11:52 +03:00
raise new Exception( 'Missing warning in ' + files[ i] ) ;
System. Windows. Forms. MessageBox. Show( 'Missing warning in ' + files[ i] ) ;
2024-01-04 17:32:19 +03:00
Halt( ) ;
end ;
if comp . Warnings[ 0 ] . Message < > warning then
begin
if nogui then
2025-12-21 21:11:52 +03:00
raise new Exception( 'Wrong warning for ' + files[ i] + ': ' + comp . Warnings[ 0 ] . Message ) ;
System. Windows. Forms. MessageBox. Show( 'Wrong warning for ' + files[ i] + ': ' + comp . Warnings[ 0 ] . Message ) ;
2024-01-04 17:32:19 +03:00
Halt( ) ;
end ;
end ;
2019-10-04 16:40:51 +03:00
if i mod 5 0 = 0 then
2018-05-10 18:10:59 +03:00
begin
2018-01-30 22:39:20 +03:00
System. GC. Collect( ) ;
2018-05-10 18:10:59 +03:00
end ;
2015-05-14 22:35:07 +03:00
end ;
2018-05-20 15:18:29 +03:00
//Println;
2015-05-14 22:35:07 +03:00
end ;
procedure CompileAllCompilationTests( dir: string ; withdll: boolean ) ;
begin
var comp : = new Compiler( ) ;
2025-12-21 21:11:52 +03:00
var fullDirName : = TestSuiteDir + PathSeparator + dir;
if not Directory. Exists( fullDirName) then exit;
var commentSymbol : = CurrentLanguageInfo. commentSymbol;
var files : = GetFilesByExtensions( fullDirName, CurrentLanguageInfo. languageExtensions) ;
2015-05-14 22:35:07 +03:00
for var i : = 0 to files. Length - 1 do
begin
2015-12-29 21:05:42 +03:00
var content : = & File . ReadAllText( files[ i] ) ;
2025-12-21 21:11:52 +03:00
if content. StartsWith( commentSymbol + 'winonly' ) and IsUnix then
2015-12-29 21:05:42 +03:00
continue;
2018-06-03 20:49:55 +03:00
var co: CompilerOptions : = new CompilerOptions( files[ i] , CompilerOptions. OutputType. ConsoleApplicaton) ;
2015-05-14 22:35:07 +03:00
co. Debug : = true ;
2018-06-03 20:49:55 +03:00
co. OutputDirectory : = TestSuiteDir + PathSeparator + dir;
2015-05-14 22:35:07 +03:00
co. UseDllForSystemUnits : = withdll;
co. RunWithEnvironment : = false ;
co. IgnoreRtlErrors : = false ;
comp . ErrorsList. Clear( ) ;
comp . Warnings. Clear( ) ;
comp . Compile( co) ;
if comp . ErrorsList. Count > 0 then
begin
2021-01-05 14:32:21 +03:00
if nogui then
raise new Exception( 'Compilation of ' + files[ i] + ' failed' + System. Environment. NewLine + comp . ErrorsList[ 0 ] . ToString( ) ) ;
2018-06-03 20:49:55 +03:00
System. Windows. Forms. MessageBox. Show( 'Compilation of ' + files[ i] + ' failed' + System. Environment. NewLine + comp . ErrorsList[ 0 ] . ToString( ) ) ;
2015-05-14 22:35:07 +03:00
Halt( ) ;
end ;
2019-10-04 16:40:51 +03:00
if i mod 5 0 = 0 then
2018-01-30 22:39:20 +03:00
System. GC. Collect( ) ;
2015-05-14 22:35:07 +03:00
end ;
end ;
procedure CompileAllUnits;
begin
var comp : = new Compiler( ) ;
2024-06-23 21:38:23 +03:00
// Н е пропускать ошибки сохранения PCU, в тесте создания PCU
comp . InternalDebug. SkipPCUErrors : = false ;
2025-12-21 21:11:52 +03:00
2018-06-03 20:49:55 +03:00
var dir : = TestSuiteDir + PathSeparator + 'units' + PathSeparator;
2025-12-21 21:11:52 +03:00
if not Directory. Exists( dir) then exit;
var commentSymbol : = CurrentLanguageInfo. commentSymbol;
var files : = GetFilesByExtensions( TestSuiteDir + PathSeparator + 'units' , CurrentLanguageInfo. languageExtensions) ;
2015-05-14 22:35:07 +03:00
for var i : = 0 to files. Length - 1 do
begin
2015-12-29 21:05:42 +03:00
var content : = & File . ReadAllText( files[ i] ) ;
2025-12-21 21:11:52 +03:00
if content. StartsWith( commentSymbol + 'winonly' ) and IsUnix then
2015-12-29 21:05:42 +03:00
continue;
2018-06-03 20:49:55 +03:00
var co: CompilerOptions : = new CompilerOptions( files[ i] , CompilerOptions. OutputType. ConsoleApplicaton) ;
2015-05-14 22:35:07 +03:00
co. Debug : = true ;
co. OutputDirectory : = dir;
co. UseDllForSystemUnits : = false ;
comp . ErrorsList. Clear( ) ;
comp . Warnings. Clear( ) ;
comp . Compile( co) ;
if comp . ErrorsList. Count > 0 then
begin
2021-01-05 14:32:21 +03:00
if nogui then
raise new Exception( 'Compilation of ' + files[ i] + ' failed' + System. Environment. NewLine + comp . ErrorsList[ 0 ] . ToString( ) ) ;
2018-06-03 20:49:55 +03:00
System. Windows. Forms. MessageBox. Show( 'Compilation of ' + files[ i] + ' failed' + System. Environment. NewLine + comp . ErrorsList[ 0 ] . ToString( ) ) ;
2015-05-14 22:35:07 +03:00
Halt( ) ;
end ;
end ;
2018-01-30 22:39:20 +03:00
System. GC. Collect;
2015-05-14 22:35:07 +03:00
end ;
procedure CompileAllUsesUnits;
begin
var comp : = new Compiler( ) ;
2025-12-21 21:11:52 +03:00
var dir : = TestSuiteDir + PathSeparator + 'usesunits' ;
if not Directory. Exists( dir) then exit;
var commentSymbol : = CurrentLanguageInfo. commentSymbol;
var files : = GetFilesByExtensions( dir, CurrentLanguageInfo. languageExtensions) ;
2015-05-14 22:35:07 +03:00
for var i : = 0 to files. Length - 1 do
begin
2015-12-29 21:05:42 +03:00
var content : = & File . ReadAllText( files[ i] ) ;
2025-12-21 21:11:52 +03:00
if content. StartsWith( commentSymbol + 'winonly' ) and IsUnix then
2015-12-29 21:05:42 +03:00
continue;
2018-06-03 20:49:55 +03:00
var co: CompilerOptions : = new CompilerOptions( files[ i] , CompilerOptions. OutputType. ConsoleApplicaton) ;
2015-05-14 22:35:07 +03:00
co. Debug : = true ;
2018-06-03 20:49:55 +03:00
co. OutputDirectory : = TestSuiteDir + PathSeparator + 'exe' ;
2015-05-14 22:35:07 +03:00
co. UseDllForSystemUnits : = false ;
comp . ErrorsList. Clear( ) ;
comp . Warnings. Clear( ) ;
comp . Compile( co) ;
if comp . ErrorsList. Count > 0 then
begin
2021-01-05 14:32:21 +03:00
if nogui then
raise new Exception( 'Compilation of ' + files[ i] + ' failed' + System. Environment. NewLine + comp . ErrorsList[ 0 ] . ToString( ) ) ;
2018-06-03 20:49:55 +03:00
System. Windows. Forms. MessageBox. Show( 'Compilation of ' + files[ i] + ' failed' + System. Environment. NewLine + comp . ErrorsList[ 0 ] . ToString( ) ) ;
2015-05-14 22:35:07 +03:00
Halt( ) ;
end ;
end ;
2018-01-30 22:39:20 +03:00
System. GC. Collect;
2015-05-14 22:35:07 +03:00
end ;
procedure CopyPCUFiles;
2025-12-21 21:11:52 +03:00
begin
var dir : = TestSuiteDir + PathSeparator + 'units' ;
if not Directory. Exists( dir) then exit;
var files : = Directory. GetFiles( dir, '*.pcu' ) ;
2015-05-14 22:35:07 +03:00
foreach fname: string in files do
begin
2018-06-03 20:49:55 +03:00
& File . Move( fname, TestSuiteDir + PathSeparator + 'usesunits' + PathSeparator + Path. GetFileName( fname) ) ;
2015-05-14 22:35:07 +03:00
end ;
end ;
procedure RunAllTests( redirectIO: boolean ) ;
begin
2020-12-26 20:05:31 +03:00
var dlls : = Directory. GetFiles( TestSuiteDir, '*.dll' ) ;
foreach var dll in dlls do
begin
System. IO. File . Copy( dll, TestSuiteDir + PathSeparator + 'exe' + PathSeparator + Path. GetFileName( dll) , true ) ;
end ;
2025-12-21 21:11:52 +03:00
var dir : = TestSuiteDir + PathSeparator + 'exe' ;
if not Directory. Exists( dir) then exit;
var files : = Directory. GetFiles( dir, '*.exe' ) ;
2015-05-14 22:35:07 +03:00
for var i : = 0 to files. Length - 1 do
begin
2020-01-31 00:52:14 +03:00
//Println(files[i]);
2018-06-03 20:49:55 +03:00
var psi : = new System. Diagnostics. ProcessStartInfo( files[ i] ) ;
psi. CreateNoWindow : = true ;
psi. UseShellExecute : = false ;
psi. WorkingDirectory : = TestSuiteDir + PathSeparator + 'exe' ;
2015-05-14 22:35:07 +03:00
{ psi. RedirectStandardInput : = true ;
psi. RedirectStandardOutput : = true ;
psi. RedirectStandardError : = true ; }
2018-06-03 20:49:55 +03:00
var p: Process : = new Process( ) ;
p. StartInfo : = psi;
p. Start( ) ;
if redirectIO then
p. StandardInput. WriteLine( 'GO' ) ;
2015-05-14 22:35:07 +03:00
//p.StandardInput.AutoFlush := true;
//var p := System.Diagnostics.Process.Start(psi);
2025-12-21 21:11:52 +03:00
if nogui then
2021-01-05 15:50:31 +03:00
begin
var success : = p. WaitForExit( 6 0 0 0 0 ) ;
if not success then
begin
raise new Exception( 'Running of ' + files[ i] + ' failed.' ) ;
end ;
end
else
p. WaitForExit( ) ;
2021-01-02 16:49:05 +03:00
//while not p.HasExited do
// Sleep(5);
2018-06-03 20:49:55 +03:00
if p. ExitCode < > 0 then
begin
2021-01-05 14:32:21 +03:00
if nogui then
raise new Exception( 'Running of ' + files[ i] + ' failed. Exit code is not 0' ) ;
2018-06-03 20:49:55 +03:00
System. Windows. Forms. MessageBox. Show( 'Running of ' + files[ i] + ' failed. Exit code is not 0' ) ;
Halt;
end ;
2015-05-14 22:35:07 +03:00
end ;
end ;
procedure RunExpressionsExtractTests;
begin
2025-12-21 21:11:52 +03:00
// Пока для других языков не поддерживается
if CurrentLanguageInfo. languageName < > 'PascalABC.NET' then exit;
CodeCompletion. CodeCompletionTester. Test( ) ;
2015-05-14 22:35:07 +03:00
end ;
2016-05-06 14:56:19 +03:00
function GetLineByPos( lines: array of string ; pos: integer ) : integer ;
begin
var cum_pos : = 0 ;
for var i : = 0 to lines. Length - 1 do
2018-06-03 20:49:55 +03:00
for var j : = 0 to lines[ j] . Length - 1 do
2016-05-06 14:56:19 +03:00
begin
2018-06-03 20:49:55 +03:00
if cum_pos = pos then
begin
Result : = i + 1 ;
exit;
end ;
Inc( cum_pos) ;
2016-05-06 14:56:19 +03:00
end ;
end ;
function GetColByPos( lines: array of string ; pos: integer ) : integer ;
begin
var cum_pos : = 0 ;
for var i : = 0 to lines. Length - 1 do
2018-06-03 20:49:55 +03:00
for var j : = 0 to lines[ j] . Length - 1 do
2016-05-06 14:56:19 +03:00
begin
2018-06-03 20:49:55 +03:00
if cum_pos = pos then
begin
Result : = j + 1 ;
exit;
end ;
Inc( cum_pos) ;
2016-05-06 14:56:19 +03:00
end ;
end ;
procedure RunIntellisenseTests;
begin
2025-12-21 21:11:52 +03:00
var dir : = TestSuiteDir + PathSeparator + 'intellisense_tests' ;
if not Directory. Exists( dir) then exit;
2016-05-06 14:56:19 +03:00
PascalABCCompiler. StringResourcesLanguage. CurrentTwoLetterISO : = 'ru' ;
2025-12-21 21:11:52 +03:00
CodeCompletion. CodeCompletionTester. TestIntellisense( dir) ;
2016-05-06 14:56:19 +03:00
end ;
2015-05-14 22:35:07 +03:00
procedure RunFormatterTests;
begin
2025-12-21 21:11:52 +03:00
var dir : = TestSuiteDir + PathSeparator + 'formatter_tests' ;
if not Directory. Exists( dir) then exit;
2015-05-14 22:35:07 +03:00
CodeCompletion. FormatterTester. Test( ) ;
2025-12-21 21:11:52 +03:00
var errors : = & File . ReadAllText( dir + PathSeparator + 'output' + PathSeparator + 'log.txt' ) ;
2015-05-14 22:35:07 +03:00
if not string . IsNullOrEmpty( errors) then
begin
2025-12-21 21:11:52 +03:00
var dirInfo : = new DirectoryInfo( TestSuiteDir) ;
if nogui then
raise new Exception( 'Formatter tests failed.' + NewLine + errors) ;
System. Windows. Forms. MessageBox. Show( errors + System. Environment. NewLine + $ 'more info at {dirInfo.Parent.Name}/{dirInfo.Name}/formatter_tests/output/log.txt' ) ;
2015-05-14 22:35:07 +03:00
Halt;
end ;
end ;
procedure ClearDirByPattern( dir, pattern: string ) ;
begin
2023-08-14 00:17:35 +03:00
if not Directory. Exists( dir) then exit;
2015-05-14 22:35:07 +03:00
var files : = Directory. GetFiles( dir, pattern) ;
for var i : = 0 to files. Length - 1 do
begin
try
2015-05-15 12:35:40 +03:00
if Path. GetFileName( files[ i] ) < > '.gitignore' then
& File . Delete( files[ i] ) ;
2015-05-14 22:35:07 +03:00
except
end ;
end ;
end ;
procedure ClearExeDir;
begin
2018-06-03 20:49:55 +03:00
ClearDirByPattern( TestSuiteDir + PathSeparator + 'exe' , '*.*' ) ;
ClearDirByPattern( TestSuiteDir + PathSeparator + 'CompilationSamples' , '*.exe' ) ;
ClearDirByPattern( TestSuiteDir + PathSeparator + 'CompilationSamples' , '*.mdb' ) ;
ClearDirByPattern( TestSuiteDir + PathSeparator + 'CompilationSamples' , '*.pdb' ) ;
ClearDirByPattern( TestSuiteDir + PathSeparator + 'CompilationSamples' , '*.pcu' ) ;
ClearDirByPattern( TestSuiteDir + PathSeparator + 'pabcrtl_tests' , '*.exe' ) ;
ClearDirByPattern( TestSuiteDir + PathSeparator + 'pabcrtl_tests' , '*.pdb' ) ;
ClearDirByPattern( TestSuiteDir + PathSeparator + 'pabcrtl_tests' , '*.mdb' ) ;
ClearDirByPattern( TestSuiteDir + PathSeparator + 'pabcrtl_tests' , '*.pcu' ) ;
2015-05-14 22:35:07 +03:00
end ;
procedure DeletePCUFiles;
begin
2018-06-03 20:49:55 +03:00
ClearDirByPattern( TestSuiteDir + PathSeparator + 'usesunits' , '*.pcu' ) ;
2015-05-14 22:35:07 +03:00
end ;
2025-12-21 21:11:52 +03:00
//procedure DeletePABCSystemPCU;
//begin
// var dir := Path.Combine(Path.GetDirectoryName(GetEXEFileName()), 'Lib');
// var pcu := Path.Combine(dir, 'PABCSystem.pcu');
//end;
2026-02-03 12:10:31 +03:00
/// Копирует всю папку CodeExamples в TestSuite (если такая уже есть, то предварительно удаляет её)
2025-12-21 21:11:52 +03:00
procedure CopyCodeExamples;
2015-05-14 22:35:07 +03:00
begin
2025-12-21 21:11:52 +03:00
var dir : = GetCodeExamplesDir( ) ;
if not Directory. Exists( dir) then exit;
var files : = GetFilesByExtensions( dir, CurrentLanguageInfo. languageExtensions, SearchOption. AllDirectories) ;
2026-02-03 12:10:31 +03:00
var destinationDir : = TestSuiteDir + PathSeparator + 'CodeExamples' + PathSeparator;
if Directory. Exists( destinationDir) then
Directory. Delete( destinationDir, True ) ;
Directory. CreateDirectory( destinationDir) ;
2015-05-14 22:35:07 +03:00
foreach f: string in files do
begin
2026-02-03 12:10:31 +03:00
& File . Copy( f, destinationDir + Path. GetFileName( f) , true ) ;
2015-05-14 22:35:07 +03:00
end ;
end ;
2025-12-21 21:11:52 +03:00
function MsToMinutes( ms: integer ) : string ;
begin
var span : = System. TimeSpan. FromMilliseconds( ms) ;
Result : = span. Minutes > 0 ? $ '{span.Minutes}m {span.Seconds}s' : $ '{span.Seconds}s' ;
end ;
2015-05-14 22:35:07 +03:00
begin
//DeletePABCSystemPCU;
2015-08-02 18:28:08 +03:00
try
2026-01-13 08:20:13 +03:00
Languages. Integration. LanguageIntegrator. LoadAllLanguages( ) ;
2024-03-13 22:16:40 +03:00
2025-12-21 21:11:52 +03:00
TestSuiteDir : = System. Environment. CurrentDirectory;
2015-08-02 18:28:08 +03:00
System. Environment. CurrentDirectory : = Path. GetDirectoryName( GetEXEFileName( ) ) ;
2025-12-21 21:11:52 +03:00
CurrentLanguageInfo : = GetCurrentLanguageInfo( TestSuiteDir) ;
if ( ParamCount = 0 ) or ( ParamStr( 1 ) = '1' ) then
Println( $ '----- {CurrentLanguageInfo.languageName} тесты -----' ) ;
2021-01-05 14:32:21 +03:00
if ( ParamCount = 2 ) and ( ParamStr( 2 ) = '1' ) then
nogui : = true ;
2018-06-03 20:49:55 +03:00
if ( ParamCount = 0 ) or ( ParamStr( 1 ) = '1' ) then
begin
2025-12-21 21:11:52 +03:00
Println( 'Compiling tests...' ) ;
2018-06-03 20:49:55 +03:00
DeletePCUFiles;
ClearExeDir;
CompileAllRunTests( false ) ;
2025-12-21 21:11:52 +03:00
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
2018-06-03 20:49:55 +03:00
end ;
if ( ParamCount = 0 ) or ( ParamStr( 1 ) = '2' ) then
begin
2026-02-03 12:10:31 +03:00
Println( 'Compiling compilation samples...' ) ;
2025-12-21 21:11:52 +03:00
CopyCodeExamples;
2026-02-03 12:10:31 +03:00
CompileAllCompilationTests( 'CodeExamples' , false ) ;
2018-06-03 20:49:55 +03:00
CompileAllCompilationTests( 'CompilationSamples' , false ) ;
2025-12-21 21:11:52 +03:00
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
2018-06-03 20:49:55 +03:00
end ;
if ( ParamCount = 0 ) or ( ParamStr( 1 ) = '3' ) then
begin
2025-12-21 21:11:52 +03:00
Println( 'Compiling tests with multiple units and error throwing tests...' ) ;
2018-06-03 20:49:55 +03:00
CompileAllUnits;
CopyPCUFiles;
CompileAllUsesUnits;
CompileErrorTests( false ) ;
2025-12-21 21:11:52 +03:00
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
2018-06-03 20:49:55 +03:00
end ;
if ( ParamCount = 0 ) or ( ParamStr( 1 ) = '4' ) then
begin
2025-12-21 21:11:52 +03:00
Println( 'Running tests...' ) ;
2018-06-03 20:49:55 +03:00
RunAllTests( false ) ;
2025-12-21 21:11:52 +03:00
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
2018-06-03 20:49:55 +03:00
ClearExeDir;
DeletePCUFiles;
end ;
if ( ParamCount = 0 ) or ( ParamStr( 1 ) = '5' ) then
begin
2025-12-21 21:11:52 +03:00
Println( 'Compiling tests in 32bit mode...' ) ;
CompileAllRunTests( false , true ) ;
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
Println( 'Running tests in 32bit mode...' ) ;
RunAllTests( false ) ;
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
ClearExeDir;
Println( 'Compiling tests with PABCRtl.dll...' ) ;
CompileAllRunTests( true ) ;
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
Println( 'Compiling compilation samples with PABCRtl.dll...' ) ;
CompileAllCompilationTests( 'pabcrtl_tests' , true ) ;
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
2019-10-06 13:38:27 +03:00
end ;
if ( ParamCount = 0 ) or ( ParamStr( 1 ) = '6' ) then
begin
2025-12-21 21:11:52 +03:00
Println( 'Running tests with PABCRtl.dll...' ) ;
2019-10-06 13:38:27 +03:00
RunAllTests( false ) ;
2025-12-21 21:11:52 +03:00
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
Println( 'Running intellisense expression tests...' ) ;
2018-06-03 20:49:55 +03:00
RunExpressionsExtractTests;
2025-12-21 21:11:52 +03:00
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
Println( 'Running basic intellisense tests...' ) ;
2018-06-03 20:49:55 +03:00
RunIntellisenseTests;
2025-12-21 21:11:52 +03:00
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
Println( 'Running formatter tests...' ) ;
2018-06-03 20:49:55 +03:00
RunFormatterTests;
2025-12-21 21:11:52 +03:00
Println( 'Success. Time elapsed: ' + MsToMinutes( MillisecondsDelta( ) ) ) ;
2018-06-03 20:49:55 +03:00
end ;
2015-08-02 18:28:08 +03:00
except
on e: Exception do
2021-01-05 14:53:09 +03:00
begin
if nogui then
raise new Exception( e. ToString( ) ) ;
2018-06-03 20:49:55 +03:00
assert( false , e. ToString( ) ) ;
2021-01-05 14:53:09 +03:00
end ;
2025-12-21 21:11:52 +03:00
2015-08-02 18:28:08 +03:00
end ;
2015-05-14 22:35:07 +03:00
end .