-
Notifications
You must be signed in to change notification settings - Fork 3
fix(intl): discover the installed ICU version at runtime instead of a hardcoded max #908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+296
−21
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d4be3cf
fix(intl): discover the installed ICU version at runtime instead of a…
frostney ec2c15c
refactor(intl): make ICU version-discovery helpers platform-independent
frostney 5a7f32b
fix(intl): also discover ICU through LD_LIBRARY_PATH directories
frostney d22fb67
Merge remote-tracking branch 'origin/main' into icu-dynamic-version-d…
frostney acec0e3
test(intl): use a path-safe separator in the ICU dir-list fixture
frostney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| { Unit tests for the platform-independent ICU version discovery helpers in | ||
| source/shared/ICU.pas. | ||
|
|
||
| The Linux loader must pick up whatever ICU major is installed — including | ||
| versions newer than any the engine has seen before, and ICU reachable only via | ||
| LD_LIBRARY_PATH — with no code change. The version parsing and the directory | ||
| scans are pure string and directory logic with no platform dependency, so they | ||
| run on every platform and are pinned here, including majors above the old | ||
| hard-coded 76 ceiling. } | ||
|
|
||
| program ICU.Test; | ||
|
|
||
| {$I Shared.inc} | ||
|
|
||
| uses | ||
| SysUtils, | ||
|
|
||
| ICU, | ||
| TestingPascalLibrary; | ||
|
|
||
| const | ||
| I18N_BASE = 'libicui18n.so'; | ||
|
|
||
| type | ||
| TICUTests = class(TTestSuite) | ||
| private | ||
| procedure TestParseMajorVersion; | ||
| procedure TestHighestInDirHasNoCap; | ||
| procedure TestHighestInDirListAcrossPaths; | ||
| public | ||
| procedure SetupTests; override; | ||
| end; | ||
|
|
||
| procedure TouchFile(const APath: string); | ||
| var | ||
| Handle: THandle; | ||
| begin | ||
| Handle := FileCreate(APath); | ||
| if Handle = THandle(-1) then | ||
| raise Exception.CreateFmt('Failed to create test fixture file: %s', [APath]); | ||
| FileClose(Handle); | ||
| end; | ||
|
|
||
| function MakeTempDir(const APrefix: string): string; | ||
| begin | ||
| Result := GetTempFileName(GetTempDir, APrefix); | ||
| DeleteFile(Result); | ||
| if not ForceDirectories(Result) then | ||
| raise Exception.CreateFmt('Failed to create test fixture directory: %s', [Result]); | ||
| end; | ||
|
|
||
| procedure TICUTests.SetupTests; | ||
| begin | ||
| Test('ParseICUSoMajorVersion extracts the major from a versioned SONAME', | ||
| TestParseMajorVersion); | ||
| Test('HighestICUMajorVersionInDir returns the newest present major, uncapped', | ||
| TestHighestInDirHasNoCap); | ||
| Test('HighestICUMajorVersionInDirList scans every dir and skips empty segments', | ||
| TestHighestInDirListAcrossPaths); | ||
| end; | ||
|
|
||
| procedure TICUTests.TestParseMajorVersion; | ||
| begin | ||
| Expect<Integer>(ParseICUSoMajorVersion('libicui18n.so.77', I18N_BASE)).ToBe(77); | ||
| Expect<Integer>(ParseICUSoMajorVersion('libicui18n.so.100', I18N_BASE)).ToBe(100); | ||
| Expect<Integer>(ParseICUSoMajorVersion('libicui18n.so.76.1', I18N_BASE)).ToBe(76); | ||
| Expect<Integer>(ParseICUSoMajorVersion('libicui18n.so.70', I18N_BASE)).ToBe(70); | ||
| // No numeric version, or an unrelated SONAME, yields 0. | ||
| Expect<Integer>(ParseICUSoMajorVersion('libicui18n.so', I18N_BASE)).ToBe(0); | ||
| Expect<Integer>(ParseICUSoMajorVersion('libicui18n.so.', I18N_BASE)).ToBe(0); | ||
| Expect<Integer>(ParseICUSoMajorVersion('libicui18n.so.x', I18N_BASE)).ToBe(0); | ||
| Expect<Integer>(ParseICUSoMajorVersion('libicuuc.so.76', I18N_BASE)).ToBe(0); | ||
| end; | ||
|
|
||
| procedure TICUTests.TestHighestInDirHasNoCap; | ||
| var | ||
| Dir: string; | ||
| begin | ||
| Dir := MakeTempDir('gicu'); | ||
| try | ||
| // No ICU library present. | ||
| Expect<Integer>(HighestICUMajorVersionInDir(Dir, I18N_BASE)).ToBe(0); | ||
|
|
||
| // A spread of majors, including ones above the old hard-coded 76 ceiling. | ||
| TouchFile(IncludeTrailingPathDelimiter(Dir) + 'libicui18n.so.74'); | ||
| TouchFile(IncludeTrailingPathDelimiter(Dir) + 'libicui18n.so.76'); | ||
| TouchFile(IncludeTrailingPathDelimiter(Dir) + 'libicui18n.so.77'); | ||
| TouchFile(IncludeTrailingPathDelimiter(Dir) + 'libicui18n.so.100'); | ||
| // A non-i18n SONAME and an unrelated file must be ignored. | ||
| TouchFile(IncludeTrailingPathDelimiter(Dir) + 'libicuuc.so.100'); | ||
| TouchFile(IncludeTrailingPathDelimiter(Dir) + 'unrelated.txt'); | ||
|
|
||
| Expect<Integer>(HighestICUMajorVersionInDir(Dir, I18N_BASE)).ToBe(100); | ||
| finally | ||
| DeleteFile(IncludeTrailingPathDelimiter(Dir) + 'libicui18n.so.74'); | ||
| DeleteFile(IncludeTrailingPathDelimiter(Dir) + 'libicui18n.so.76'); | ||
| DeleteFile(IncludeTrailingPathDelimiter(Dir) + 'libicui18n.so.77'); | ||
| DeleteFile(IncludeTrailingPathDelimiter(Dir) + 'libicui18n.so.100'); | ||
| DeleteFile(IncludeTrailingPathDelimiter(Dir) + 'libicuuc.so.100'); | ||
| DeleteFile(IncludeTrailingPathDelimiter(Dir) + 'unrelated.txt'); | ||
| RemoveDir(Dir); | ||
| end; | ||
| end; | ||
|
|
||
| procedure TICUTests.TestHighestInDirListAcrossPaths; | ||
| var | ||
| DirA, DirB: string; | ||
| begin | ||
| DirA := MakeTempDir('gicua'); | ||
| DirB := MakeTempDir('gicub'); | ||
| try | ||
| TouchFile(IncludeTrailingPathDelimiter(DirA) + 'libicui18n.so.76'); | ||
| TouchFile(IncludeTrailingPathDelimiter(DirB) + 'libicui18n.so.99'); | ||
|
|
||
| // Use '|' as the list separator, not ':'. The generated temp paths are | ||
| // absolute and on Windows contain a drive-letter colon, which a ':' | ||
| // separator would wrongly split. The production caller passes ':' for | ||
| // LD_LIBRARY_PATH; the separator is a parameter, so the split logic under | ||
| // test is identical either way. | ||
| Expect<Integer>(HighestICUMajorVersionInDirList( | ||
| DirA + '|' + DirB + '|', '|', I18N_BASE)).ToBe(99); | ||
| // An empty list discovers nothing. | ||
| Expect<Integer>(HighestICUMajorVersionInDirList('', '|', I18N_BASE)).ToBe(0); | ||
| finally | ||
| DeleteFile(IncludeTrailingPathDelimiter(DirA) + 'libicui18n.so.76'); | ||
| DeleteFile(IncludeTrailingPathDelimiter(DirB) + 'libicui18n.so.99'); | ||
| RemoveDir(DirA); | ||
| RemoveDir(DirB); | ||
| end; | ||
| end; | ||
|
|
||
| begin | ||
| TestRunnerProgram.AddSuite(TICUTests.Create('ICU')); | ||
| TestRunnerProgram.Run; | ||
|
|
||
| ExitCode := TestResultToExitCode; | ||
| end. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.