dispatchrun / dispatch

Entrypoint of the Dispatch ecosystem.
11 stars 1 forks source link

Test Run guranteed to fail on Windows for non-existent env file. #69

Closed Tyl13 closed 2 months ago

Tyl13 commented 3 months ago

The issue has two parts to it. The first being that paths in Windows uses backslashes instead of forward slashes that is used in other operating systems. Using runtime.GOOS allows you to check if the system is windows, and you can then use a backslash instead. A small note for that is for the regex to recognize \ means that it actually needs to be \\\\. This is because it is first compiled, then parsed. The regex compiles down the four \\\\ into \\ that is correctly parsed directly as \.

The second issue is that the error message given is different on Windows. Specifically instead of being no such file or directory, the message is The system cannot find the file specified.

Two possible solutions, replacing the original assert with either:

switch runtime.GOOS {
case "windows":
    assert.Regexp(t, "Error: failed to load env file from .+\\\\dispatch\\\\cli\\\\non-existent.env: open non-existent.env: The system cannot find the file specified.\n", buff.String())
default: // "linux", "freebsd", "openbsd", "netbsd", anything not Windows
    assert.Regexp(t, "Error: failed to load env file from .+/dispatch/cli/non-existent.env: open non-existent.env: no such file or directory\n", buff.String())
}

or something like this to reduce code repetition

pathSeperator := "/"
nonExistentFileMessage := "no such file or directory"
if runtime.GOOS == "windows" {
    pathSeperator = "\\\\"
    nonExistentFileMessage = "The system cannot find the file specified."
}
assert.Regexp(t, "Error: failed to load env file from .+"+pathSeperator+"dispatch"+pathSeperator+"cli"+pathSeperator+"non-existent.env: open non-existent.env: "+nonExistentFileMessage+"\n", buff.String())
chicoxyzzy commented 3 months ago

Thank you for reporting the issue! Currently, we don't test on Windows, but this is a good suggestion. We should set up a new GitHub action to test on Windows.

I like the second solution. I think we can get a correct path using filepath.FromSlash() and only replace the message in the regular expression

chicoxyzzy commented 2 months ago

Resolved in #74 Thank you @Tyl13!