test: approach of getting goroot

This commit is contained in:
Reinaldy Rafli 2021-10-27 22:59:40 +07:00
parent 5061b1c29c
commit 8df9913bb7
No known key found for this signature in database
GPG Key ID: CFDB9400255D8CB6
2 changed files with 12 additions and 20 deletions

View File

@ -3,23 +3,6 @@ name: CI
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
build-test:
name: Build test
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.16.x, 1.17.x]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Build
run: go build .
coverage: coverage:
name: Coverage name: Coverage
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -3,6 +3,8 @@ package decrr_test
import ( import (
"errors" "errors"
"os" "os"
"os/exec"
"strings"
"testing" "testing"
"github.com/aldy505/decrr" "github.com/aldy505/decrr"
@ -13,11 +15,18 @@ func TestWrap(t *testing.T) {
w := decrr.Wrap(x) w := decrr.Wrap(x)
wd, _ := os.Getwd() wd, _ := os.Getwd()
cmd, err := exec.Command("bash", "-c", "go env | grep GOROOT").CombinedOutput()
if err != nil {
t.Error(err)
}
gt := strings.Replace(strings.Replace(strings.Replace(string(cmd), "GOROOT=", "", 1), "\"", "", 2), "\n", "", -1)
var expected string var expected string
expected += "why does a chicken cross the road?\n\n" expected += "why does a chicken cross the road?\n\n"
expected += "github.com/aldy505/decrr_test.TestWrap " + wd + "/decrr_test.go:13\n" expected += "github.com/aldy505/decrr_test.TestWrap " + wd + "/decrr_test.go:15\n"
expected += "testing.tRunner /usr/local/go/src/testing/testing.go:1259\n" expected += "testing.tRunner " + gt + "/src/testing/testing.go:1259\n"
expected += "runtime.goexit /usr/local/go/src/runtime/asm_amd64.s:1581" expected += "runtime.goexit " + gt + "/src/runtime/asm_amd64.s:1581"
if w.Error() != expected { if w.Error() != expected {
t.Error("different than expected:", w.Error(), "\nexpected:", expected) t.Error("different than expected:", w.Error(), "\nexpected:", expected)