THRIFT-5146 Align Delphi to the test suite arguments rules (its "--switch=value", not "--switch value")
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/test/TestClient.pas b/lib/delphi/test/TestClient.pas
index ff59982..6c962ab 100644
--- a/lib/delphi/test/TestClient.pas
+++ b/lib/delphi/test/TestClient.pas
@@ -150,7 +150,7 @@
class procedure PrintCmdLineHelp;
class procedure InvalidArgs;
public
- class function Execute( const args: array of string) : Byte;
+ class function Execute( const arguments: array of string) : Byte;
end;
@@ -191,19 +191,17 @@
const HELPTEXT = ' [options]'#10
+ #10
+ 'Allowed options:'#10
- + ' -h [ --help ] produce help message'#10
- + ' --host arg (=localhost) Host to connect'#10
- + ' --port arg (=9090) Port number to connect'#10
- + ' --domain-socket arg Domain Socket (e.g. /tmp/ThriftTest.thrift),'#10
- + ' instead of host and port'#10
- + ' --pipe arg Windows Named Pipe (e.g. MyThriftPipe)'#10
- + ' --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles)'#10
- + ' --transport arg (=sockets) Transport: buffered, framed, http, winhttp'#10
- + ' --protocol arg (=binary) Protocol: binary, compact, json'#10
- + ' --ssl Encrypted Transport using SSL'#10
- + ' -n [ --testloops ] arg (=1) Number of Tests'#10
- + ' -t [ --threads ] arg (=1) Number of Test threads'#10
- + ' --performance Run the built-in performance test (no other arguments)'#10
+ + ' -h | --help Produces this help message'#10
+ + ' --host=arg (localhost) Host to connect'#10
+ + ' --port=arg (9090) Port number to connect'#10
+ + ' --pipe=arg Windows Named Pipe (e.g. MyThriftPipe)'#10
+ + ' --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles)'#10
+ + ' --transport=arg (sockets) Transport: buffered, framed, http, winhttp'#10
+ + ' --protocol=arg (binary) Protocol: binary, compact, json'#10
+ + ' --ssl Encrypted Transport using SSL'#10
+ + ' -n=num | --testloops=num (1) Number of Tests'#10
+ + ' -t=num | --threads=num (1) Number of Test threads'#10
+ + ' --performance Run the built-in performance test (no other arguments)'#10
;
begin
Writeln( ChangeFileExt(ExtractFileName(ParamStr(0)),'') + HELPTEXT);
@@ -216,11 +214,22 @@
Abort;
end;
-class function TTestClient.Execute(const args: array of string) : Byte;
+class function TTestClient.Execute(const arguments: array of string) : Byte;
+
+ function IsSwitch( const aArgument, aSwitch : string; out sValue : string) : Boolean;
+ begin
+ sValue := '';
+ result := (Copy( aArgument, 1, Length(aSwitch)) = aSwitch);
+ if result then begin
+ if (Copy( aArgument, 1, Length(aSwitch)+1) = (aSwitch+'='))
+ then sValue := Copy( aArgument, Length(aSwitch)+2, MAXINT);
+ end;
+ end;
+
var
- i : Integer;
+ iArg : Integer;
threadExitCode : Byte;
- s : string;
+ sArg, sValue : string;
threads : array of TThread;
dtStart : TDateTime;
test : Integer;
@@ -241,92 +250,83 @@
end;
try
- i := 0;
- while ( i < Length(args) ) do begin
- s := args[i];
- Inc( i);
+ iArg := 0;
+ while iArg < Length(arguments) do begin
+ sArg := arguments[iArg];
+ Inc(iArg);
- if (s = '-h') or (s = '--help') then begin
+ if IsSwitch( sArg, '-h', sValue)
+ or IsSwitch( sArg, '--help', sValue)
+ then begin
// -h [ --help ] produce help message
PrintCmdLineHelp;
result := $FF; // all tests failed
Exit;
end
- else if s = '--host' then begin
+ else if IsSwitch( sArg, '--host', sValue) then begin
// --host arg (=localhost) Host to connect
- setup.host := args[i];
- Inc( i);
+ setup.host := sValue;
end
- else if s = '--port' then begin
+ else if IsSwitch( sArg, '--port', sValue) then begin
// --port arg (=9090) Port number to connect
- s := args[i];
- Inc( i);
- setup.port := StrToIntDef(s,0);
+ setup.port := StrToIntDef(sValue,0);
if setup.port <= 0 then InvalidArgs;
end
- else if s = '--domain-socket' then begin
+ else if IsSwitch( sArg, '--domain-socket', sValue) then begin
// --domain-socket arg Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port
raise Exception.Create('domain-socket not supported');
end
- else if s = '--pipe' then begin
+ // --pipe arg Windows Named Pipe (e.g. MyThriftPipe)
+ else if IsSwitch( sArg, '--pipe', sValue) then begin
// --pipe arg Windows Named Pipe (e.g. MyThriftPipe)
setup.endpoint := trns_NamedPipes;
- setup.sPipeName := args[i];
- Inc( i);
+ setup.sPipeName := sValue;
Console.WriteLine('Using named pipe ('+setup.sPipeName+')');
end
- else if s = '--anon-pipes' then begin
+ else if IsSwitch( sArg, '--anon-pipes', sValue) then begin
// --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles)
setup.endpoint := trns_AnonPipes;
- setup.hAnonRead := THandle( StrToIntDef( args[i], Integer(INVALID_HANDLE_VALUE)));
- Inc( i);
- setup.hAnonWrite := THandle( StrToIntDef( args[i], Integer(INVALID_HANDLE_VALUE)));
- Inc( i);
+ setup.hAnonRead := THandle( StrToIntDef( arguments[iArg], Integer(INVALID_HANDLE_VALUE)));
+ Inc(iArg);
+ setup.hAnonWrite := THandle( StrToIntDef( arguments[iArg], Integer(INVALID_HANDLE_VALUE)));
+ Inc(iArg);
Console.WriteLine('Using anonymous pipes ('+IntToStr(Integer(setup.hAnonRead))+' and '+IntToStr(Integer(setup.hAnonWrite))+')');
end
- else if s = '--transport' then begin
+ else if IsSwitch( sArg, '--transport', sValue) then begin
// --transport arg (=sockets) Transport: buffered, framed, http, winhttp, evhttp
- s := args[i];
- Inc( i);
-
- if s = 'buffered' then Include( setup.layered, trns_Buffered)
- else if s = 'framed' then Include( setup.layered, trns_Framed)
- else if s = 'http' then setup.endpoint := trns_MsXmlHttp
- else if s = 'winhttp' then setup.endpoint := trns_WinHttp
- else if s = 'evhttp' then setup.endpoint := trns_EvHttp // recognized, but not supported
+ if sValue = 'buffered' then Include( setup.layered, trns_Buffered)
+ else if sValue = 'framed' then Include( setup.layered, trns_Framed)
+ else if sValue = 'http' then setup.endpoint := trns_MsXmlHttp
+ else if sValue = 'winhttp' then setup.endpoint := trns_WinHttp
+ else if sValue = 'evhttp' then setup.endpoint := trns_EvHttp // recognized, but not supported
else InvalidArgs;
end
- else if s = '--protocol' then begin
+ else if IsSwitch( sArg, '--protocol', sValue) then begin
// --protocol arg (=binary) Protocol: binary, compact, json
- s := args[i];
- Inc( i);
-
- if s = 'binary' then setup.protType := prot_Binary
- else if s = 'compact' then setup.protType := prot_Compact
- else if s = 'json' then setup.protType := prot_JSON
+ if sValue = 'binary' then setup.protType := prot_Binary
+ else if sValue = 'compact' then setup.protType := prot_Compact
+ else if sValue = 'json' then setup.protType := prot_JSON
else InvalidArgs;
end
- else if s = '--ssl' then begin
+ else if IsSwitch( sArg, '--ssl', sValue) then begin
// --ssl Encrypted Transport using SSL
setup.useSSL := TRUE;
end
- else if (s = '-n') or (s = '--testloops') then begin
+ else if IsSwitch( sArg, '-n', sValue) or IsSwitch( sArg, '--testloops', sValue) then begin
// -n [ --testloops ] arg (=1) Number of Tests
- FNumIteration := StrToIntDef( args[i], 0);
- Inc( i);
+ FNumIteration := StrToIntDef( sValue, 0);
if FNumIteration <= 0
then InvalidArgs;
end
- else if (s = '-t') or (s = '--threads') then begin
+ else if IsSwitch( sArg, '-t', sValue) or IsSwitch( sArg, '--threads', sValue) then begin
// -t [ --threads ] arg (=1) Number of Test threads
- FNumThread := StrToIntDef( args[i], 0);
- Inc( i);
+ FNumThread := StrToIntDef( sValue, 0);
if FNumThread <= 0
then InvalidArgs;
end
- else if (s = '--performance') then begin
+ else if IsSwitch( sArg, '--performance', sValue) then begin
result := TPerformanceTests.Execute;
Exit;
end