Skip to content
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

Windows: cannot run executable found relative to current directory #284

Open
TLINDEN opened this issue Dec 18, 2024 · 8 comments
Open

Windows: cannot run executable found relative to current directory #284

TLINDEN opened this issue Dec 18, 2024 · 8 comments

Comments

@TLINDEN
Copy link

TLINDEN commented Dec 18, 2024

Howdy,

I am executing tests using testscript on a Windows VM. Works on Linux, but fails on windows.

== NAME  TestAnydb/workflow
    testscript.go:584: work=$WORK
        path=C:\Users\RUNNER~1\AppData\Local\Temp\testscript-main3726524194\bin;C:\Users\runneradmin\go\pkg\mod\golang.org\[email protected]\bin;C:\Program Files\PowerShell\7;C:\Users\runneradmin\go\bin;C:\hostedtoolcache\windows\go\1.21.13\x64\bin;C:\Program Files\MongoDB\Server\5.0\bin;C:\aliyun-cli;C:\vcpkg;C:\Program Files (x86)\NSIS\;C:\tools\zstd;C:\Program Files\Mercurial\;C:\hostedtoolcache\windows\stack\3.1.1\x64;C:\cabal\bin;C:\\ghcup\bin;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\Program Files\R\R-4.4.2\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\SeleniumWebDrivers\EdgeDriver\;C:\SeleniumWebDrivers\ChromeDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.21.13\x64\bin;C:\hostedtoolcache\windows\Python\3.9.13\x64\Scripts;C:\hostedtoolcache\windows\Python\3.9.13\x64;C:\hostedtoolcache\windows\Ruby\3.0.7\x64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.432-6\x64\bin;C:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\ProgramData\Chocolatey\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\PowerShell\7\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\WiX Toolset v3.14\bin;C:\Program Files\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Microsoft SQL Server\160\DTS\Binn\;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.7\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI\;c:\tools\php;C:\Program Files (x86)\sbt\bin;C:\Program Files\Amazon\AWSCLIV2\;C:\Program Files\Amazon\SessionManagerPlugin\bin\;C:\Program Files\Amazon\AWSSAMCLI\bin\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\LLVM\bin;C:\Users\runneradmin\.dotnet\tools;C:\Users\runneradmin\.cargo\bin;C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps
        gotraceback=system
        userprofile=/no-home
        tmp=$WORK\.tmp
        devnull=NUL
        /=\
        :=;
        $=$
        systemroot=C:\Windows
        exe=.exe
        
        # simple entry
 (0.001s)
        > exec anydb -f test.db set foo bar
        [exec: "anydb.exe": cannot run executable found relative to current directory]
        FAIL: t\workflow.txtar:2: unexpected command failure

Any help would be much appreciated!

Best,
Tom

@rogpeppe
Copy link
Owner

What happens if you do exec ./anydb -f test.db set foo bar ?
That is, does it still fail if you make the current directory explicit?

@TLINDEN
Copy link
Author

TLINDEN commented Feb 11, 2025

Yes, fails, but with executable not found this time.

> exec ./anydb -f test.db set foo bar
        [exec: "C:\\Users\\runneradmin\\AppData\\Local\\Temp\\go-test-script2745636057\\script-restore\\anydb": executable file not found in %PATH%]
        FAIL: t\restore.txtar:19: unexpected command failure

I also tried .\anydb with the same result.

@mvdan
Copy link
Collaborator

mvdan commented Feb 11, 2025

You might need to do exec ./yourprogram$exe given that go build produces binaries with .exe extensions. Executing binaries relative to the current directory this way definitely works with testscript on Windows; I do it in another project.

@TLINDEN
Copy link
Author

TLINDEN commented Feb 11, 2025

Nope:

> exec ./anydb$exe -f test.db set datum -r file.txt
        [fork/exec ./anydb.exe: The system cannot find the file specified.]
        FAIL: t\files.txtar:22: unexpected command failure

@mvdan
Copy link
Collaborator

mvdan commented Feb 11, 2025

Share a full reproducer please. Ideally a small one.

@TLINDEN
Copy link
Author

TLINDEN commented Feb 11, 2025

Will do, but tomorrow, it's midnight here .

Thanks for your time so far!

@TLINDEN
Copy link
Author

TLINDEN commented Feb 12, 2025

Ok, this branch only contains 1 script, and 2 CI jobs: one on ubuntu (for reference) and one on windows. The test script is here

And, believe it or not: this singular test works under windows. I'm baffled...

@TLINDEN
Copy link
Author

TLINDEN commented Feb 12, 2025

Ok, I found the culprit. This leads to the errors:

    - name: build
      run: go build

    - name: test
      run: make test

If I run the build as the last step:

    - name: test
      run: make test

    - name: build
      run: go build

... then it works!

So, the actual fix is to modify my Makefile like this:

modified   Makefile
@@ -70,7 +70,7 @@ install: buildlocal
 clean:
 	rm -rf $(tool) releases coverage.out
 
-test:
+test: clean
 	ANYDB_PASSWORD=test go test -v ./...

That is, in order for the testscript tests to work on windows there has to be no binary of the same name in the current directory laying around from a previous step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants