Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstendb-ARM committed Nov 8, 2023
1 parent 38ab0d4 commit 6da5ed3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/cbuild/cbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func ReadCbuildgenIdx(name, outPath string, params *ParamsType) error {

params.Subsystem = append(params.Subsystem, subsystem)

// store Reference project for TZ-NS
// store Reference project for TZ
if cbuildGenIdx.ProjectType == "trustzone" {
if cbuildGen.ForProjectPart == "secure" {
secureContextName = cbuildGen.Project
Expand Down
10 changes: 1 addition & 9 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ func (t *TextBuilder) AddLine(args ...string) {
t.text += "\n"
}

func (t *TextBuilder) AddSpaces(num, tabWidth int) {
for i := int(0); i < num; i++ {
for j := int(0); j < tabWidth; j++ {
t.text += " "
}
}
}

func (t *TextBuilder) GetLine() string {
return t.text
}
Expand Down Expand Up @@ -78,7 +70,7 @@ func ConvertFilename(outPath, file, relativePathAdd string) (string, error) {
file = filepath.Clean(file)
file = filepath.ToSlash(file)

mdkarmPath := path.Join(outPath, relativePathAdd) // create the path where STCube sets it's files relative to (STM32CubeMX/MDK-ARM/)
mdkarmPath := path.Join(outPath, relativePathAdd) // create the path where STCube sets it's files relative to (./STM32CubeMX/MDK-ARM/)
file = path.Join(mdkarmPath, file)

if _, err := os.Stat(file); errors.Is(err, os.ErrNotExist) {
Expand Down
44 changes: 42 additions & 2 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,56 @@
package utils_test

import (
"os"
"path"
"testing"

"github.com/open-cmsis-pack/generator-bridge/internal/utils"
"github.com/stretchr/testify/assert"
)

var testDir string = "./Testing"

func TestAddLine(t *testing.T) {
var text utils.TextBuilder

text.AddLine("A line")
assert.Equal(t, "A line\n", text.GetLine())
expected := "A line\n"
result := text.GetLine()
assert.Equal(t, expected, result)

text.AddLine("A second line")
assert.Equal(t, "A line\nA second line\n", text.GetLine())
result = text.GetLine()
expected += "A second line\n"
assert.Equal(t, expected, result)
}

func TestAddQuotes(t *testing.T) {
text := "Test"
expected := "\"" + text + "\""
result := utils.AddQuotes(text)
assert.Equal(t, expected, result)
}

func TestFileExists(t *testing.T) {

result := utils.DirExists(testDir)
expected := true
assert.Equal(t, expected, result)

filename := path.Join(testDir, "fileexists.txt")
result = utils.FileExists(filename)
expected = false
assert.Equal(t, expected, result)

text := "Hello, World"
os.WriteFile(filename, []byte(text), 0755)

Check failure on line 53 in internal/utils/utils_test.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `os.WriteFile` is not checked (errcheck)
result = utils.FileExists(filename)
expected = false
assert.Equal(t, expected, result)
}

func Init() {
os.MkdirAll(testDir, 0755)

Check failure on line 60 in internal/utils/utils_test.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `os.MkdirAll` is not checked (errcheck)

}

0 comments on commit 6da5ed3

Please sign in to comment.