From 1cf4384da038ccccf4b90edf49183d889406e4b6 Mon Sep 17 00:00:00 2001 From: EricGrange Date: Sat, 21 Mar 2026 09:32:02 +0100 Subject: [PATCH] Fix relative path resolution for -sp and -sd and remove redundant existence check --- Source/CoverageConfiguration.pas | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/Source/CoverageConfiguration.pas b/Source/CoverageConfiguration.pas index 3f015f3..a1a4639 100644 --- a/Source/CoverageConfiguration.pas +++ b/Source/CoverageConfiguration.pas @@ -40,7 +40,7 @@ TCoverageConfiguration = class(TInterfacedObject, ICoverageConfiguration) FExcludedUnitsStrLst: TStringList; FExcludedClassPrefixesStrLst: TStringList; FExeParamsStrLst: TStrings; - FSourcePathLst: TStrings; + FSourcePathLst: TStringList; FStripFileExtension: Boolean; FEmmaOutput: Boolean; FEmmaOutput21: Boolean; @@ -211,6 +211,10 @@ constructor TCoverageConfiguration.Create(const AParameterProvider: IParameterPr FStripFileExtension := True; FSourcePathLst := TStringList.Create; + FSourcePathLst.Duplicates := dupIgnore; + FSourcePathLst.Sorted := True; + FSourcePathLst.Sorted := False; // Allow Insert(0, ...) while having duplicates ignored during initial population (though mostly for safety if Add is used later) + FEmmaOutput := False; FEmmaOutput21 := False; FSeparateMeta := False; @@ -857,8 +861,10 @@ procedure TCoverageConfiguration.ParseSourceDirectorySwitch(var AParameter: Inte if FSourceDir = '' then raise EConfigurationException.Create('Expected parameter for source directory'); + FSourceDir := MakePathAbsolute(FSourceDir, GetCurrentDir); + // Source Directory should be checked first. - FSourcePathLst.Insert(0, ExpandEnvString(FSourceDir)); + FSourcePathLst.Insert(0, FSourceDir); except on EParameterIndexException do raise EConfigurationException.Create('Expected parameter for source directory'); @@ -868,29 +874,30 @@ procedure TCoverageConfiguration.ParseSourceDirectorySwitch(var AParameter: Inte procedure TCoverageConfiguration.ParseSourcePathsSwitch(var AParameter: Integer); var SourcePathString: string; + AddedPaths: Integer; begin Inc(AParameter); + AddedPaths := 0; try SourcePathString := ParseParameter(AParameter); while SourcePathString <> '' do begin SourcePathString := MakePathAbsolute(SourcePathString, GetCurrentDir); - - if DirectoryExists(SourcePathString) then - FSourcePathLst.Add(SourcePathString); + FSourcePathLst.Add(SourcePathString); + Inc(AddedPaths); Inc(AParameter); SourcePathString := ParseParameter(AParameter); end; - if FSourcePathLst.Count = 0 then - raise EConfigurationException.Create('Expected at least one source path'); + if AddedPaths = 0 then + raise EConfigurationException.Create('Expected at least one source path after -sp'); Dec(AParameter); except on EParameterIndexException do - raise EConfigurationException.Create('Expected at least one source path'); + raise EConfigurationException.Create('Expected at least one source path after -sp'); end; end; @@ -949,7 +956,9 @@ function TCoverageConfiguration.MakePathAbsolute(const APath, ASourceFileName: s Result := ExpandEnvString(APath); if TPath.IsRelativePath(Result) then begin - RootPath := TPath.GetDirectoryName(TPath.GetFullPath(ASourceFileName)); + RootPath := TPath.GetFullPath(ASourceFileName); + if not DirectoryExists(RootPath) then + RootPath := TPath.GetDirectoryName(RootPath); Result := TPath.GetFullPath(TPath.Combine(RootPath, Result)); end; end; @@ -1144,11 +1153,9 @@ procedure TCoverageConfiguration.ParseDGroupProj(const DGroupProjFilename: TFile ItemGroup: IXMLNode; Node: IXMLNode; Project: IXMLNode; - ProjectName, Path, SearchPaths: string; + ProjectName: string; I: Integer; RootPath: TFileName; - SourcePath: TFileName; - ExeFileName: TFileName; begin RootPath := ExtractFilePath(TPath.GetFullPath(DGroupProjFilename)); Document := TXMLDocument.Create(nil);