Skip to content

Commit

Permalink
Remove $CMSIS_BUILD_ROOT references and test structure cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
soumeh01 authored Aug 3, 2023
1 parent 851a530 commit 8b1f4cc
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 240 deletions.
19 changes: 0 additions & 19 deletions cmd/cbuild/commands/build/buildcprj_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,16 @@ package build_test
import (
"cbuild/cmd/cbuild/commands"
"os"
"runtime"
"testing"

cp "github.com/otiai10/copy"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

const testRoot = "../../../../test"

func init() {
// Prepare test data
_ = os.RemoveAll(testRoot + "/run")

var binExtension string
if runtime.GOOS == "windows" {
binExtension = ".exe"
}
cbuildgenBin := testRoot + "/run/bin/cbuildgen" + binExtension
file, _ := os.Create(cbuildgenBin)
defer file.Close()

_ = cp.Copy(testRoot+"/run/minimal.cprj", testRoot+"/run/minimal.cprj")
}

func TestBuildCPRJCommand(t *testing.T) {
assert := assert.New(t)
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin")
cprjFile := testRoot + "/run/minimal.cprj"

t.Run("multiple arguments", func(t *testing.T) {
Expand All @@ -56,7 +38,6 @@ func TestBuildCPRJCommand(t *testing.T) {

func TestPreLogConfiguration(t *testing.T) {
assert := assert.New(t)
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin")
logDir := testRoot + "/run/log"
logFile := logDir + "/test.log"
cprjFile := testRoot + "/run/minimal.cprj"
Expand Down
2 changes: 0 additions & 2 deletions cmd/cbuild/commands/list/list_contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ package list_test

import (
"cbuild/cmd/cbuild/commands"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestListContextsCommand(t *testing.T) {
assert := assert.New(t)
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin")
csolutionFile := testRoot + "/run/TestSolution/test.csolution.yml"

t.Run("No arguments", func(t *testing.T) {
Expand Down
34 changes: 0 additions & 34 deletions cmd/cbuild/commands/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,15 @@ package list_test

import (
"cbuild/cmd/cbuild/commands"
"os"
"runtime"
"testing"
"time"

cp "github.com/otiai10/copy"
"github.com/stretchr/testify/assert"
)

const testRoot = "../../../../test"

func init() {
// Prepare test data
_ = os.RemoveAll(testRoot + "/run")
time.Sleep(2 * time.Second)
_ = cp.Copy(testRoot+"/data", testRoot+"/run")

_ = os.MkdirAll(testRoot+"/run/bin", 0755)
_ = os.MkdirAll(testRoot+"/run/etc", 0755)
_ = os.MkdirAll(testRoot+"/run/packs", 0755)
_ = os.MkdirAll(testRoot+"/run/IntDir", 0755)
_ = os.MkdirAll(testRoot+"/run/OutDir", 0755)

var binExtension string
if runtime.GOOS == "windows" {
binExtension = ".exe"
}
cbuildgenBin := testRoot + "/run/bin/cbuildgen" + binExtension
file, _ := os.Create(cbuildgenBin)
defer file.Close()
csolutionBin := testRoot + "/run/bin/csolution" + binExtension
file, _ = os.Create(csolutionBin)
defer file.Close()
cpackgetBin := testRoot + "/run/bin/cpackget" + binExtension
file, _ = os.Create(cpackgetBin)
defer file.Close()

_ = cp.Copy(testRoot+"/run/test.Debug+CM0.cprj", testRoot+"/run/OutDir/test.Debug+CM0.cprj")
}

func TestListCommand(t *testing.T) {
assert := assert.New(t)
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin")

t.Run("No arguments", func(t *testing.T) {
cmd := commands.NewRootCmd()
Expand Down
2 changes: 0 additions & 2 deletions cmd/cbuild/commands/list/list_toolchains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ package list_test

import (
"cbuild/cmd/cbuild/commands"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestListToolchainsCommand(t *testing.T) {
assert := assert.New(t)
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin")
csolutionFile := testRoot + "/run/TestSolution/test.csolution.yml"

t.Run("invalid flag", func(t *testing.T) {
Expand Down
33 changes: 2 additions & 31 deletions cmd/cbuild/commands/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,22 @@ package commands_test

import (
"cbuild/cmd/cbuild/commands"
"cbuild/pkg/inittest"
"os"
"runtime"
"testing"
"time"

cp "github.com/otiai10/copy"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

const testRoot = "../../../test"

func init() {
// Prepare test data
_ = os.RemoveAll(testRoot + "/run")
time.Sleep(2 * time.Second)
_ = cp.Copy(testRoot+"/data", testRoot+"/run")

_ = os.MkdirAll(testRoot+"/run/bin", 0755)
_ = os.MkdirAll(testRoot+"/run/etc", 0755)
_ = os.MkdirAll(testRoot+"/run/packs", 0755)
_ = os.MkdirAll(testRoot+"/run/IntDir", 0755)
_ = os.MkdirAll(testRoot+"/run/OutDir", 0755)

var binExtension string
if runtime.GOOS == "windows" {
binExtension = ".exe"
}
cbuildgenBin := testRoot + "/run/bin/cbuildgen" + binExtension
file, _ := os.Create(cbuildgenBin)
defer file.Close()
csolutionBin := testRoot + "/run/bin/csolution" + binExtension
file, _ = os.Create(csolutionBin)
defer file.Close()
cpackgetBin := testRoot + "/run/bin/cpackget" + binExtension
file, _ = os.Create(cpackgetBin)
defer file.Close()

_ = cp.Copy(testRoot+"/run/test.Debug+CM0.cprj", testRoot+"/run/OutDir/test.Debug+CM0.cprj")
inittest.TestInitialization(testRoot)
}

func TestCommands(t *testing.T) {
assert := assert.New(t)
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin")
cprjFile := testRoot + "/run/minimal.cprj"
csolutionFile := testRoot + "/run/test.csolution.yml"

Expand Down Expand Up @@ -100,7 +72,6 @@ func TestCommands(t *testing.T) {

func TestPreLogConfiguration(t *testing.T) {
assert := assert.New(t)
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin")
logDir := testRoot + "/run/log"
logFile := logDir + "/test.log"

Expand Down
60 changes: 13 additions & 47 deletions pkg/builder/cproject/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ package cproject

import (
"cbuild/pkg/builder"
utils "cbuild/pkg/utils"
"cbuild/pkg/inittest"
"cbuild/pkg/utils"
"errors"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"

cp "github.com/otiai10/copy"
"github.com/stretchr/testify/assert"
)

const testRoot = "../../../test"

func init() {
inittest.TestInitialization(testRoot)
}

type RunnerMock struct{}

func (r RunnerMock) ExecuteCommand(program string, quiet bool, args ...string) (string, error) {
Expand All @@ -46,28 +49,6 @@ func (r RunnerMock) ExecuteCommand(program string, quiet bool, args ...string) (
return "", nil
}

func init() {
// Prepare test data
_ = os.RemoveAll(testRoot + "/run")
time.Sleep(2 * time.Second)
_ = cp.Copy(testRoot+"/data", testRoot+"/run")

_ = os.MkdirAll(testRoot+"/run/bin", 0755)
_ = os.MkdirAll(testRoot+"/run/etc", 0755)

var binExtension string
if runtime.GOOS == "windows" {
binExtension = ".exe"
}

cbuildgenBin := testRoot + "/run/bin/cbuildgen" + binExtension
file, _ := os.Create(cbuildgenBin)
defer file.Close()
cpackgetBin := testRoot + "/run/bin/cpackget" + binExtension
file, _ = os.Create(cpackgetBin)
defer file.Close()
}

func TestCheckCprj(t *testing.T) {
assert := assert.New(t)

Expand Down Expand Up @@ -195,27 +176,11 @@ func TestGetInternalVars(t *testing.T) {
InputFile: testRoot + "/run/minimal.cprj",
},
}
t.Run("test get internal vars, without CMSIS_BUILD_ROOT", func(t *testing.T) {
t.Run("test get internal vars", func(t *testing.T) {

_, err := b.getInternalVars()
assert.Error(err)
})

t.Run("test get internal vars, with CMSIS_BUILD_ROOT", func(t *testing.T) {
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin")
configs, err := utils.GetInstallConfigs()
assert.Nil(err)
b.InstallConfigs = configs

vars, err := b.getInternalVars()
assert.Nil(err)
assert.NotEmpty(vars.cprjPath)
assert.NotEmpty(vars.cprjFilename)
assert.NotEmpty(vars.binPath)
assert.NotEmpty(vars.etcPath)
assert.NotEmpty(vars.cbuildgenBin)
assert.NotEmpty(vars.cpackgetBin)
})
}

func TestGetJobs(t *testing.T) {
Expand Down Expand Up @@ -247,9 +212,7 @@ func TestGetJobs(t *testing.T) {

func TestBuild(t *testing.T) {
assert := assert.New(t)
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin")
configs, err := utils.GetInstallConfigs()
assert.Nil(err)
configs := inittest.GetTestConfigs(testRoot)

b := CprjBuilder{
builder.BuilderParams{
Expand All @@ -260,7 +223,11 @@ func TestBuild(t *testing.T) {
OutDir: testRoot + "/run/OutDir",
Packs: true,
},
InstallConfigs: configs,
InstallConfigs: utils.Configurations{
BinPath: configs.BinPath,
BinExtn: configs.BinExtn,
EtcPath: configs.EtcPath,
},
},
}

Expand Down Expand Up @@ -359,7 +326,6 @@ func TestBuildFail(t *testing.T) {
},
},
}
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin")

t.Run("test build cprj without packs", func(t *testing.T) {
b.Options.Packs = false
Expand Down
Loading

0 comments on commit 8b1f4cc

Please sign in to comment.