[3.0][Testing] Anchor the canonical path test to the root the platform actually uses - #9600
Conversation
An absolute path is rooted differently on each platform: a leading separator on POSIX, a drive letter on Windows. Naming the root in the path under test keeps the assertion about the dot segments rather than about the machine the suite happens to run on. Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
|
This assertion should probably be a regex so that it can accept any drive letter. |
|
Agreed, and #9605 does that. The hardcoded So rather than a regex I split the two behaviours. Resolving dot segments has nothing to do with the root, so that test uses a relative path and asserts the whole result exactly. What the root is gets its own test, reading the drive from the working directory. No letter is named anywhere, and the branch that caused #9595 is now under test. A regex would also have removed the letter; I went with the exact assertion because the expected value is a specific drive rather than any drive, and it gives a diff on failure. Say the word if you would rather have the pattern. |
Description
SapiTest::testCanonicalPathResolvesDotSegments()asserted a POSIX-only result, so it failed on Windows withC:\a\cwhere it expected/a/c.The production code is right. On Windows,
canonicalPath('/a/./b/../c')normalises the separators and then falls into the "Windows relative path" branch: a path that starts at the root but names no drive is rooted on the current drive, sogetcwd()'s drive letter is prepended.C:\a\cis the correct canonical form of\a\cthere, andrealpath()would say the same thing. The test simply baked in the shape an absolute path has on one platform.Naming the root in the path under test takes the DOS-style-path branch on Windows instead, so the result no longer depends on which drive the checkout happens to sit on:
The assertion is then about the dot segments, which is what the test is named for, rather than about the machine running it.
Verified by extracting the function body, substituting
\forDIRECTORY_SEPARATORand running it: the old assertions produceC:\a\candC:\aexactly as reported, and the new ones hold. The suite is green on Linux, andcomposer lintis clean.The rest of
tests/Unit/has no other case of this. The remaining'/...'literals are URL routes rather than file paths, andLangTestcomparescanonicalPath()output againstcanonicalPath()output, so both sides move together.Issues References (Fixes|Related|Closes)
SapiTestfails on Windows #9595