From ac593ad9463e01ff28fd79f98d691c5a4d266105 Mon Sep 17 00:00:00 2001 From: dmkjfs Date: Fri, 31 Oct 2025 03:15:53 +0300 Subject: [PATCH 1/2] update testdata --- testdata/results.json | 8 ++++---- testdata/somedir/controllers/main_test.go | 7 +++++++ testdata/somedir/{main.rs => main_test.rs} | 0 testdata/tests/controllers/main_test.go | 7 +++++++ 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 testdata/somedir/controllers/main_test.go rename testdata/somedir/{main.rs => main_test.rs} (100%) create mode 100644 testdata/tests/controllers/main_test.go diff --git a/testdata/results.json b/testdata/results.json index 3c94ab4..6a9206c 100644 --- a/testdata/results.json +++ b/testdata/results.json @@ -1,13 +1,13 @@ { "Languages": { - "Go": { "Files": 1, "LOC": 8 }, + "Go": { "Files": 3, "LOC": 24 }, "Python": { "Files": 2, "LOC": 4 }, "Rust": { "Files": 2, "LOC": 8 }, "C++": { "Files": 2, "LOC": 8 } }, "Components": { - "Tests": { "Files": 3, "LOC": 10 }, - "Controllers": { "Files": 2, "LOC": 8 } + "Tests": { "Files": 6, "LOC": 30 }, + "Controllers": { "Files": 4, "LOC": 24 } }, - "Total": { "Files": 7, "LOC": 28 } + "Total": { "Files": 9, "LOC": 44 } } diff --git a/testdata/somedir/controllers/main_test.go b/testdata/somedir/controllers/main_test.go new file mode 100644 index 0000000..b7d2a32 --- /dev/null +++ b/testdata/somedir/controllers/main_test.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello, World!") +} diff --git a/testdata/somedir/main.rs b/testdata/somedir/main_test.rs similarity index 100% rename from testdata/somedir/main.rs rename to testdata/somedir/main_test.rs diff --git a/testdata/tests/controllers/main_test.go b/testdata/tests/controllers/main_test.go new file mode 100644 index 0000000..b7d2a32 --- /dev/null +++ b/testdata/tests/controllers/main_test.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello, World!") +} From 6530c0801bb801ca245636c3eb839a79c55f36e4 Mon Sep 17 00:00:00 2001 From: dmkjfs Date: Fri, 31 Oct 2025 03:16:27 +0300 Subject: [PATCH 2/2] check for error, add err details --- main_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/main_test.go b/main_test.go index 965dec4..c9cd177 100644 --- a/main_test.go +++ b/main_test.go @@ -1,6 +1,7 @@ package statloc_test import ( + "fmt" "os" "path/filepath" "testing" @@ -23,18 +24,24 @@ func (s *MainSuite) SetupSuite() { } func (s *MainSuite) TestGetStatistics() { + _, err := core.GetStatistics("non_existing_dir") + + assert.NotNil(s.T(), err) + var pathError *core.PathError + assert.ErrorAs(s.T(), err, &pathError) + response, err := core.GetStatistics("testdata") assert.Nil(s.T(), err) assert.NotPanics(s.T(), func() {core.GetStatistics("testdata")}) //nolint:errcheck for title, item := range s.results.Components { - assert.Equal(s.T(), item.LOC, response.Components[title].LOC) - assert.Equal(s.T(), item.Files, response.Components[title].Files) + assert.Equal(s.T(), item.LOC, response.Components[title].LOC, fmt.Sprintf("Item title: %s", title)) + assert.Equal(s.T(), item.Files, response.Components[title].Files, fmt.Sprintf("Item title: %s", title)) } for title, item := range s.results.Languages{ - assert.Equal(s.T(), item.LOC, response.Languages[title].LOC) - assert.Equal(s.T(), item.Files, response.Languages[title].Files) + assert.Equal(s.T(), item.LOC, response.Languages[title].LOC, fmt.Sprintf("Item title: %s", title)) + assert.Equal(s.T(), item.Files, response.Languages[title].Files, fmt.Sprintf("Item title: %s", title)) } assert.Equal(s.T(), s.results.Total.LOC, response.Total.LOC) assert.Equal(s.T(), s.results.Total.Files, response.Total.Files)