diff --git a/.gitignore b/.gitignore index 8870665a92..3328954f32 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,4 @@ data.json *.sarif -unit.xml -unit_embed.xml -unit_wasm.xml \ No newline at end of file +unit*.xml \ No newline at end of file diff --git a/internal/entity/file_normal.go b/internal/entity/file_normal.go index 2e9c76a9f4..9d201badc0 100644 --- a/internal/entity/file_normal.go +++ b/internal/entity/file_normal.go @@ -1,4 +1,4 @@ -//go:build !js && !wasm +//go:build (!js && !wasm) || test_js_marshaler package entity diff --git a/internal/result/result_marshaler_test.go b/internal/result/result_marshaler_test.go index c10e8d20b9..9bdd3deb56 100644 --- a/internal/result/result_marshaler_test.go +++ b/internal/result/result_marshaler_test.go @@ -5,40 +5,38 @@ package result_test import ( "bytes" "compress/gzip" + _ "embed" "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/entity" "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) +//go:embed testdata/result.gob.gz +var testdataGob2 []byte - decompressedReader, err := gzip.NewReader(testdataGob) +func TestResultMarshalJavaScriptCross(t *testing.T) { + decompressedReader, err := gzip.NewReader(bytes.NewBuffer(testdataGob2)) 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, - }) + jsonPrinterResult, err := json.Marshal(r, + json.DefaultOptionsV2(), + json.Deterministic(true), + json.WithMarshalers(entity.FileMarshalerCompact)) require.NoError(t, err) resultJSAny := r.MarshalJavaScript() resultJSJson, err := json.Marshal(resultJSAny) require.NoError(t, err) - assert.JSONEq(t, jsonPrinterResult.String(), string(resultJSJson)) + assert.JSONEq(t, string(jsonPrinterResult), string(resultJSJson)) } diff --git a/scripts/tests.py b/scripts/tests.py index e0fd6765b5..73d59dba28 100644 --- a/scripts/tests.py +++ b/scripts/tests.py @@ -34,10 +34,11 @@ def run_unit_tests(full: bool, wasm: bool, no_embed: bool): "go", "test", "-v", - "-covermode=atomic", + "-covermode=set", "-cover", "-tags=embed", "./...", + "-args", f"-test.gocoverdir={unit_path}" ], text=True, @@ -67,9 +68,10 @@ def run_unit_tests(full: bool, wasm: bool, no_embed: bool): "go", "test", "-v", - "-covermode=atomic", + "-covermode=set", "-cover", "./internal/webui", + "-args", f"-test.gocoverdir={unit_path}" ], text=True, @@ -132,10 +134,11 @@ def run_unit_tests(full: bool, wasm: bool, no_embed: bool): "go", "test", "-v", - "-covermode=atomic", + "-covermode=set", "-cover", - "-tags=test_js_marshaler" + "-coverpkg=./..." "./internal/result", + "-args", f"-test.gocoverdir={unit_path}" ], text=True, @@ -308,11 +311,12 @@ def get_parser() -> ArgumentParser: run_unit_tests(args.unit_full, args.unit_wasm, args.unit_embed) - with build_gsa() as gsa: - if args.integration_example: - run_integration_tests("example", gsa) - if args.integration_real: - run_integration_tests("real", gsa) + if args.integration_example or args.integration_real: + with build_gsa() as gsa: + if args.integration_example: + run_integration_tests("example", gsa) + if args.integration_real: + run_integration_tests("real", gsa) merge_covdata() diff --git a/scripts/tool/gsa.py b/scripts/tool/gsa.py index 8b948f95ed..e716cd6694 100644 --- a/scripts/tool/gsa.py +++ b/scripts/tool/gsa.py @@ -20,7 +20,7 @@ def build_gsa(): "build", "-buildmode=exe", # since windows use pie by default "-cover", - "-covermode=atomic", + "-covermode=set", "-tags", "embed,profiler", "-o", @@ -37,9 +37,10 @@ def build_gsa(): shutil.copyfile(temp_binary, os.path.join(get_project_root(), "results", "gsa")) - yield temp_binary + shutil.rmtree(os.path.dirname(temp_binary)) + @contextlib.contextmanager def build_pgo_gsa():