dongying6659 2017-06-26 17:27
浏览 34

从%APPDATA%运行单元测试

I am trying to run some of my Go unit tests using "go test" but the test executable is built and run from my machine's %APPDATA%/local/temp directory. My PC has IT enforcement which blocks any unrecognized executable from being run other than from a pre-sanctioned directory (i.e C:/dev/projects"). All my Go source code are in that directory, including my *_test.go files. Is there a way to tell the Go test module to build and run from the current directory?

  • 写回答

1条回答 默认 最新

  • dongnvwang8591 2017-06-26 18:41
    关注

    Yes you can.

    Setting temp directory before executing the go test. By default temp directory environment variable gets evaluated in the order of TMP, TEMP, USERPROFILE, Windows directory; refer to msdn doc.

    Basically it complies the go test under given temp directory and execute it.

    C:\> cd dev\projects\src\mygotest
    C:\dev\projects\src\mygotest>echo %CD%
    C:\dev\projects\src\mygotest
    
    C:\dev\projects\src\mygotest>set TMP=%CD%
    
    C:\dev\projects\src\mygotest>go test -x
    WORK=C:\dev\projects\src\mygotest\go-build306298926
    mkdir -p $WORK\mygotest\_test\
    mkdir -p $WORK\mygotest\_test\_obj_test\
    cd C:\dev\projects\src\mygotest
    "C:\\Go\\pkg\\tool\\windows_amd64\\compile.exe" -o "C:\\dev\\projects\\src\\mygotest\\go-build306298926\\mygotest\\_test\\mygotest.a" -trimpath "C:\\dev\\projects\\src\\mygotest\\go-build306298926" -p main -complete -buildid 86cb7a423d355c7468ad98c4f8bffe77b68d2265 -D _/C_/dev/projects/src/mygotest -I "C:\\dev\\projects\\src\\mygotest\\go-build306298926" -pack "C:\\dev\\projects\\src\\mygotest\\sample.go" "C:\\dev\\projects\\src\\mygotest\\sample_test.go"
    cd $WORK\mygotest\_test
    "C:\\Go\\pkg\\tool\\windows_amd64\\compile.exe" -o "C:\\dev\\projects\\src\\mygotest\\go-build306298926\\mygotest\\_test\\main.a" -trimpath "C:\\dev\\projects\\src\\mygotest\\go-build306298926" -p main -complete -D "" -I "C:\\dev\\projects\\src\\mygotest\\go-build306298926\\mygotest\\_test" -I "C:\\dev\\projects\\src\\mygotest\\go-build306298926" -pack "C:\\dev\\projects\\src\\mygotest\\go-build306298926\\mygotest\\_test\\_testmain.go"
    cd .
    "C:\\Go\\pkg\\tool\\windows_amd64\\link.exe" -o "C:\\dev\\projects\\src\\mygotest\\go-build306298926\\mygotest\\_test\\mygotest.test.exe" -L "C:\\dev\\projects\\src\\mygotest\\go-build306298926\\mygotest\\_test" -L "C:\\dev\\projects\\src\\mygotest\\go-build306298926" -w -extld=gcc -buildmode=exe "C:\\dev\\projects\\src\\mygotest\\go-build306298926\\mygotest\\_test\\main.a"
    $WORK\mygotest\_test\mygotest.test.exe
    Hello, playground
    PASS
    ok      mygotest        0.526s
    
    C:\dev\projects\src\mygotest>
    

    Note: TMP set to current terminal session only, it doesn't affect system environment variable.

    Important thing to note from above test output is WORK=C:\dev\projects\src\mygotest\go-build306298926.

    Happy testing!

    评论

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答