Skip to content

Commit

Permalink
test: workaround wasm coverage issue
Browse files Browse the repository at this point in the history
Updates: #84
Signed-off-by: Zxilly <[email protected]>
  • Loading branch information
Zxilly committed Jun 17, 2024
1 parent de09d20 commit 41e4d53
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build js && wasm
//go:build (js && wasm) || test_js_marshaler

package entity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build js && wasm
//go:build (js && wasm) || test_js_marshaler

package entity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build js && wasm
//go:build (js && wasm) || test_js_marshaler

package entity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build js && wasm
//go:build (js && wasm) || test_js_marshaler

package entity

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build js && wasm
//go:build (js && wasm) || test_js_marshaler

package result

Expand Down
44 changes: 44 additions & 0 deletions internal/result/result_marshaler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//go:build test_js_marshaler

package result_test

import (
"bytes"
"compress/gzip"
"encoding/gob"
"os"
"path/filepath"
"testing"

"github.com/go-json-experiment/json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/Zxilly/go-size-analyzer/internal/printer"
"github.com/Zxilly/go-size-analyzer/internal/result"
)

func TestResult_MarshalJavaScript(t *testing.T) {
testdataGob, err := os.Open(filepath.Join("testdata", "result.gob.gz"))
require.NoError(t, err)

decompressedReader, err := gzip.NewReader(testdataGob)
require.NoError(t, err)

r := new(result.Result)
err = gob.NewDecoder(decompressedReader).Decode(r)
require.NoError(t, err)

jsonPrinterResult := new(bytes.Buffer)
err = printer.JSON(r, &printer.JSONOption{
HideDetail: true,
Writer: jsonPrinterResult,
})
require.NoError(t, err)

resultJSAny := r.MarshalJavaScript()
resultJSJson, err := json.Marshal(resultJSAny)
require.NoError(t, err)

assert.JSONEq(t, jsonPrinterResult.String(), string(resultJSJson))
}
Binary file modified internal/result/testdata/result.gob.gz
Binary file not shown.
179 changes: 167 additions & 12 deletions internal/result/testdata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@
"pcln_size": 109
}
],
"size": 5926,
"symbols": []
"size": 5998,
"symbols": [
{
"name": "internal/abi.(*Type).Uncommon.jump5",
"addr": 4881888,
"size": 72,
"type": "data"
}
]
},
"internal/bytealg": {
"name": "internal/bytealg",
Expand Down Expand Up @@ -257,8 +264,15 @@
"pcln_size": 436
}
],
"size": 6412,
"symbols": []
"size": 6628,
"symbols": [
{
"name": "main.goFiles.files",
"addr": 4883712,
"size": 216,
"type": "data"
}
]
},
"math": {
"name": "math",
Expand Down Expand Up @@ -390,8 +404,39 @@
"pcln_size": 4578
}
],
"size": 6460,
"symbols": []
"size": 7100,
"symbols": [
{
"name": "runtime/internal/atomic..dict.Pointer[runtime.g]",
"addr": 4882880,
"size": 128,
"type": "data"
},
{
"name": "runtime/internal/atomic..dict.Pointer[string]",
"addr": 4883008,
"size": 128,
"type": "data"
},
{
"name": "runtime/internal/atomic..dict.Pointer[func(string) func()]",
"addr": 4883136,
"size": 128,
"type": "data"
},
{
"name": "runtime/internal/atomic..dict.Pointer[func()]",
"addr": 4883264,
"size": 128,
"type": "data"
},
{
"name": "runtime/internal/atomic..dict.Pointer[runtime.spanSetBlock]",
"addr": 4883392,
"size": 128,
"type": "data"
}
]
},
"/internal/sys": {
"name": "runtime/internal/sys",
Expand Down Expand Up @@ -1019,8 +1064,111 @@
"pcln_size": 2834
}
],
"size": 563730,
"symbols": []
"size": 569373,
"symbols": [
{
"name": "runtime.printanycustomtype.jump3",
"addr": 4883520,
"size": 192,
"type": "data"
},
{
"name": "runtime.deltimer.jump7",
"addr": 4881984,
"size": 80,
"type": "data"
},
{
"name": "runtime.modtimer.jump12",
"addr": 4882080,
"size": 80,
"type": "data"
},
{
"name": "runtime.moveTimers.jump12",
"addr": 4882176,
"size": 80,
"type": "data"
},
{
"name": "runtime.adjusttimers.jump15",
"addr": 4882272,
"size": 80,
"type": "data"
},
{
"name": "runtime.runtimer.jump11",
"addr": 4882368,
"size": 80,
"type": "data"
},
{
"name": "runtime.clearDeletedTimers.jump12",
"addr": 4882464,
"size": 80,
"type": "data"
},
{
"name": "runtime.typesEqual.jump27",
"addr": 4882560,
"size": 80,
"type": "data"
},
{
"name": "runtime.typelink",
"addr": 4887936,
"size": 1256,
"type": "data"
},
{
"name": "runtime.findfunctab",
"addr": 4884992,
"size": 2633,
"type": "data"
},
{
"name": "runtime..dict.noEscapePtr[runtime.pcvalueCache]",
"addr": 4881600,
"size": 40,
"type": "data"
},
{
"name": "runtime.mainPC",
"addr": 4880832,
"size": 8,
"type": "data"
},
{
"name": "runtime.defaultGOROOT.str",
"addr": 4881536,
"size": 36,
"type": "data"
},
{
"name": "runtime.buildVersion.str",
"addr": 4880856,
"size": 10,
"type": "data"
},
{
"name": "runtime.modinfo.str",
"addr": 4883936,
"size": 233,
"type": "data"
},
{
"name": "runtime.godebugDefault.str",
"addr": 4880872,
"size": 11,
"type": "data"
},
{
"name": "runtime.textsectionmap",
"addr": 4881328,
"size": 24,
"type": "data"
}
]
},
"strconv": {
"name": "strconv",
Expand Down Expand Up @@ -1260,8 +1408,15 @@
"pcln_size": 218
}
],
"size": 85729,
"symbols": []
"size": 85737,
"symbols": [
{
"name": "time..dict.isDigit[string]",
"addr": 4880840,
"size": 8,
"type": "data"
}
]
},
"unicode": {
"name": "unicode",
Expand Down Expand Up @@ -1478,7 +1633,7 @@
"name": ".rodata",
"size": 148553,
"file_size": 148553,
"known_size": 0,
"known_size": 4683,
"offset": 544768,
"end": 693321,
"addr": 4739072,
Expand Down Expand Up @@ -1538,7 +1693,7 @@
"name": ".typelink",
"size": 1256,
"file_size": 1256,
"known_size": 0,
"known_size": 1256,
"offset": 693632,
"end": 694888,
"addr": 4887936,
Expand Down
16 changes: 6 additions & 10 deletions internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ func GetTestBinPath(t *testing.T) string {

p := filepath.Join(GetProjectRoot(), "scripts", "bins", "bin-linux-1.21-amd64")
p, err := filepath.Abs(p)
if err != nil {
t.Fatalf("failed to get absolute path of %s: %v", p, err)
}
require.NoError(t, err)

if _, err := os.Stat(p); os.IsNotExist(err) {
t.Fatalf("bin not exist: %s", p)
}
_, err = os.Stat(p)
require.NoError(t, err)

return p
}
Expand All @@ -45,10 +42,9 @@ func GetTestResult(t *testing.T) *result.Result {
r, err := internal.Analyze(path, f, uint64(f.Len()), internal.Options{
SkipDwarf: true,
SkipDisasm: true,
SkipSymbol: true,
SkipSymbol: false,
})
if err != nil {
t.Fatalf("failed to analyze %s: %v", path, err)
}
require.NoError(t, err)

return r
}
1 change: 1 addition & 0 deletions scripts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def run_unit_tests(full: bool, wasm: bool, no_embed: bool):
"-v",
"-covermode=atomic",
"-cover",
"-tags=test_js_marshaler"
"./internal/result",
f"-test.gocoverdir={unit_path}"
],
Expand Down

0 comments on commit 41e4d53

Please sign in to comment.