Skip to content

Commit

Permalink
test: add analyze warn test
Browse files Browse the repository at this point in the history
Signed-off-by: Zxilly <[email protected]>
  • Loading branch information
Zxilly committed Jul 6, 2024
1 parent 3720b2f commit cc5490f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/diff/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package diff

import (
"io"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"

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

Expand Down Expand Up @@ -43,5 +47,29 @@ func TestDiffJSONAndBinary(t *testing.T) {
}

func TestDifferentAnalyzer(t *testing.T) {
dir := t.TempDir()
first := filepath.Join(dir, "first")
second := filepath.Join(dir, "second")

createFile := func(name string, analyzers []entity.Analyzer) {
f, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
require.NoError(t, err)
defer func() {
require.NoError(t, f.Close())
}()

r := commonResult{
Analyzers: analyzers,
}

require.NoError(t, printer.JSON(r, f, &printer.JSONOption{}))
}

createFile(first, []entity.Analyzer{entity.AnalyzerDwarf, entity.AddrSourceSymbol})
createFile(second, []entity.Analyzer{entity.AnalyzerDisasm})

require.Error(t, Diff(io.Discard, DOptions{
OldTarget: first,
NewTarget: second,
}))
}

0 comments on commit cc5490f

Please sign in to comment.