Skip to content

[3.0][Testing] Stop the canonical path tests naming a drive letter - #9605

Merged
live627 merged 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/sapitest-any-drive
Sep 1, 2026
Merged

[3.0][Testing] Stop the canonical path tests naming a drive letter#9605
live627 merged 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/sapitest-any-drive

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

Follow-up to #9600, which fixed the Windows failure by naming C: in the path under test. That works — the drive comes from the input rather than the machine, so it passes on a runner whose checkout is on D: — but @live627 is right that a hardcoded drive letter is not the thing to leave in a test. It reads as an assumption even where it is not one, and it means nothing covers the branch that actually broke: on Windows a path that starts at the root but names no drive is rooted on the current one, and it was that step which turned /a/c into C:\a\c.

Splitting the two behaviours apart removes the need to name a drive at all.

Dot segments have nothing to do with the root, so the test named for them uses a relative path. There is no root to differ over and the whole result can be asserted exactly on either platform:

$this->assertSame('a' . $sep . 'c', Sapi::canonicalPath('a/./b/../c', false, false));

What the root is is worth covering on its own, so it gets its own test, and the drive is read from the working directory rather than assumed:

$drive = $sep === '/' ? '' : substr((string) getcwd(), 0, 2);

$this->assertSame($drive . $sep . 'a' . $sep . 'c', Sapi::canonicalPath('/a/./b/../c', false, false));

The review suggested a regex, which would also have removed the hardcoded letter. I went with an exact assertion instead because the expected value here is not "some drive" but a specific one — the drive the process is on — and assertSame says that, gives a real diff when it fails, and would still catch the original bug on POSIX, where a regex with an optional drive group would accept a stray letter. Happy to switch it if you would rather have the pattern.

Verified on both platforms. The suite is green on Linux, and I checked the Windows path by extracting canonicalPath(), substituting \ for DIRECTORY_SEPARATOR and running it with the working directory on D:, where all four assertions hold:

0 PASS expected a\c    got a\c
1 PASS expected a      got a
2 PASS expected D:\a\c got D:\a\c
3 PASS expected D:\a   got D:\a

composer lint is clean.

Issues References (Fixes|Related|Closes)

  1. Related to SapiTest fails on Windows #9595
  2. Follow-up to [3.0][Testing] Anchor the canonical path test to the root the platform actually uses #9600

Resolving dot segments has nothing to do with the root, so that test uses a
relative path and asserts the whole result exactly on either platform.

What the root is remains worth covering, since a path that starts at the root
names no drive and on Windows picks up the one the process is on. That is now
its own test, and it reads the drive from the working directory rather than
assuming the checkout is on C.

Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@live627
live627 merged commit 6be7050 into SimpleMachines:release-3.0 Sep 1, 2026
7 checks passed
@jdarwood007 jdarwood007 added this to the 3.0 Alpha 5 milestone Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants