mirror of
https://github.com/burrowers/garble.git
synced 2025-09-26 20:01:16 +08:00
start testing on GitHub Actions
No windows yet, because a few portability issues remain.
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# To prevent CRLF breakages on Windows for fragile files, like testdata.
|
||||
* -text
|
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
github: mvdan
|
18
.github/workflows/test.yml
vendored
Normal file
18
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
on: [push, pull_request]
|
||||
name: Test
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.13.x]
|
||||
platform: [ubuntu-latest, macos-latest]
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v1
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v1
|
||||
- name: Test
|
||||
run: go test ./...
|
@@ -2,7 +2,7 @@
|
||||
|
||||
GO111MODULE=on go get mvdan.cc/garble
|
||||
|
||||
Obfuscate a Go build.
|
||||
Obfuscate a Go build. Requires Go 1.13 or later.
|
||||
|
||||
garble build [build flags] [packages]
|
||||
|
||||
|
7
main.go
7
main.go
@@ -101,11 +101,16 @@ func main1() int {
|
||||
// If we recognise an argument, we're not running within -toolexec.
|
||||
switch args[0] {
|
||||
case "build":
|
||||
execPath, err := os.Executable()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return 1
|
||||
}
|
||||
goArgs := []string{
|
||||
"build",
|
||||
"-a",
|
||||
"-trimpath",
|
||||
"-toolexec=" + os.Args[0],
|
||||
"-toolexec=" + execPath,
|
||||
}
|
||||
goArgs = append(goArgs, args[1:]...)
|
||||
|
||||
|
11
main_test.go
11
main_test.go
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/rogpeppe/go-internal/testscript"
|
||||
@@ -32,12 +33,22 @@ func TestScripts(t *testing.T) {
|
||||
if err := os.Mkdir(bindir, 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
binfile := filepath.Join(bindir, "garble")
|
||||
if runtime.GOOS == "windows" {
|
||||
binfile += ".exe"
|
||||
}
|
||||
if err := os.Symlink(os.Args[0], filepath.Join(bindir, "garble")); err != nil {
|
||||
return err
|
||||
}
|
||||
env.Vars = append(env.Vars, fmt.Sprintf("PATH=%s%c%s", bindir, filepath.ListSeparator, os.Getenv("PATH")))
|
||||
env.Vars = append(env.Vars, "TESTSCRIPT_COMMAND=garble")
|
||||
|
||||
// GitHub Actions doesn't define %LocalAppData% on
|
||||
// Windows, which breaks $GOCACHE. Set it ourselves.
|
||||
if runtime.GOOS == "windows" {
|
||||
env.Vars = append(env.Vars, fmt.Sprintf(`LOCALAPPDATA=%s\appdata`, env.WorkDir))
|
||||
}
|
||||
|
||||
for _, name := range [...]string{
|
||||
"HOME",
|
||||
"USERPROFILE", // $HOME for windows
|
||||
|
14
testdata/scripts/basic.txt
vendored
14
testdata/scripts/basic.txt
vendored
@@ -1,14 +1,12 @@
|
||||
# TODO: make this script run on mac and windows
|
||||
|
||||
# Check that the program works as expected without garble.
|
||||
exec go build main.go
|
||||
exec ./main
|
||||
cmp stderr main.stderr
|
||||
|
||||
# The default build includes DWARF and the symbol table.
|
||||
exec readelf --section-headers main
|
||||
stdout 'debug_info'
|
||||
stdout '\.symtab'
|
||||
[!windows] [exec:readelf] exec readelf --section-headers main$exe
|
||||
[!windows] [exec:readelf] stdout 'debug_info'
|
||||
[!windows] [exec:readelf] stdout '\.symtab'
|
||||
|
||||
# The default build includes full non-trimmed paths, as well as our names.
|
||||
bingrep main$exe ${WORK@R} 'globalVar' 'globalFunc'
|
||||
@@ -22,9 +20,9 @@ exec go build -a -trimpath -toolexec=garble main.go
|
||||
exec ./main
|
||||
cmp stderr main.stderr
|
||||
|
||||
exec readelf --section-headers main
|
||||
! stdout 'debug_info'
|
||||
! stdout '\.symtab'
|
||||
[!windows] [exec:readelf] exec readelf --section-headers main$exe
|
||||
[!windows] [exec:readelf] ! stdout 'debug_info'
|
||||
[!windows] [exec:readelf] ! stdout '\.symtab'
|
||||
|
||||
! bingrep main$exe ${WORK@R} 'globalVar' 'globalFunc'
|
||||
|
||||
|
Reference in New Issue
Block a user