Skip to content

Commit

Permalink
More unit tests (#156)
Browse files Browse the repository at this point in the history
* New tests

* Shouldn't pass func name in tests because t.Name() exists

* Fix regression bug with parameter passing

* ParamTokens shouldn't null on space

* Simple parser test

* Add $var test to parser

* Varible tests in parser
  • Loading branch information
lmorg committed Sep 19, 2019
1 parent 7db15bc commit 9b0c51d
Show file tree
Hide file tree
Showing 67 changed files with 885 additions and 243 deletions.
4 changes: 2 additions & 2 deletions builtins/core/httpclient/get_test.go
Expand Up @@ -9,7 +9,7 @@ import (

// TestGet tests the get function
func TestGet(t *testing.T) {
count.Tests(t, 1, "TestGet")
count.Tests(t, 1)

lang.InitEnv()
addr := StartHTTPServer(t)
Expand All @@ -26,7 +26,7 @@ func TestGet(t *testing.T) {

// TestGetFile tests the getfile function
func TestGetFile(t *testing.T) {
count.Tests(t, 1, "TestGetFile")
count.Tests(t, 1)

lang.InitEnv()
addr := StartHTTPServer(t)
Expand Down
2 changes: 1 addition & 1 deletion builtins/core/httpclient/post_test.go
Expand Up @@ -9,7 +9,7 @@ import (

// TestPost tests the post function
func TestPost(t *testing.T) {
count.Tests(t, 1, "TestPost")
count.Tests(t, 1)

lang.InitEnv()
addr := StartHTTPServer(t)
Expand Down
30 changes: 0 additions & 30 deletions builtins/core/httpclient/server_test.go
Expand Up @@ -33,36 +33,6 @@ func (h testHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

/*
func StartHTTPServer(t *testing.T) (addr string) {
c := make(chan string)
go testHTTPServer(t, c)
addr = <-c
return
}
func testHTTPServer(t *testing.T, c chan string) {
var (
port int32
addr string
err error
)
for i := 0; i < 10; i++ {
port = atomic.AddInt32(&testPort, 1)
addr = fmt.Sprintf("%s:%d", testHost, port)
go func() {
err = http.ListenAndServe(addr, testHTTPHandler{})
}()
time.Sleep(100 * time.Millisecond)
if err == nil {
c <- addr
return
}
}
}
*/

func StartHTTPServer(t *testing.T) string {
var (
port int32
Expand Down
6 changes: 3 additions & 3 deletions builtins/core/mkarray/case_test.go
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestGetCase(t *testing.T) {
count.Tests(t, 4, "TestGetCase")
count.Tests(t, 4)

if getCase("foobar") != caseLower {
t.Error("`foobar` not being detected as lower case")
Expand All @@ -27,7 +27,7 @@ func TestGetCase(t *testing.T) {
}

func TestSetCase(t *testing.T) {
count.Tests(t, 3, "TestSetCase")
count.Tests(t, 3)

input := "foobar"

Expand Down Expand Up @@ -62,7 +62,7 @@ func TestSetCase(t *testing.T) {
// TestOptimisedSetCase checks that nobody tries to "bug fix" the setCase()
// function with lowercasing already lowercased elements
func TestOptimisedSetCase(t *testing.T) {
count.Tests(t, 2, "TestOptimisedSetCase")
count.Tests(t, 2)

input := "fooBar"

Expand Down
2 changes: 1 addition & 1 deletion builtins/core/mkarray/consts_test.go
Expand Up @@ -11,7 +11,7 @@ func TestConsts(t *testing.T) {
for i, m := range mapRanges {
for element := range m {

count.Tests(t, len(m), "TestConsts")
count.Tests(t, len(m))

if element != strings.ToLower(element) {
t.Errorf("mapRange contains a non-lowercase element")
Expand Down
4 changes: 2 additions & 2 deletions builtins/core/modules/git_test.go
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestGitInstalled(t *testing.T) {
count.Tests(t, 1, "TestGitInstalled")
count.Tests(t, 1)

if which.Which("git") == "" {
t.Log("`git` isn't installed or not in $PATH")
Expand All @@ -23,7 +23,7 @@ func TestGitUriParser(t *testing.T) {
"https://github.com/lmorg/murex-module-murex-dev.git",
}

count.Tests(t, len(URIs), "TestGitUriParser")
count.Tests(t, len(URIs))

expected := "murex-module-murex-dev"

Expand Down
2 changes: 2 additions & 0 deletions builtins/core/runtime/runtime_test.go
Expand Up @@ -19,6 +19,8 @@ func TestRangeByIndex(t *testing.T) {
}

func marshalHelp(t *testing.T) string {
t.Helper()

b, err := json.Marshal(help(), false)
if err != nil {
t.Errorf("Cannot marshal help(): %s", err)
Expand Down
4 changes: 2 additions & 2 deletions builtins/core/typemgmt/variables_test.go
Expand Up @@ -31,7 +31,7 @@ func VariableTests(tests []Test, t *testing.T) {
t.Fatalf("Aborting test because unable to set env: %s", err)
}

count.Tests(t, len(tests)*2, "VariableTests")
count.Tests(t, len(tests)*2)

defaults.Defaults(lang.InitConf, false)
lang.InitEnv()
Expand Down Expand Up @@ -82,7 +82,7 @@ func UnSetTests(unsetter string, tests []string, t *testing.T) {
t.Fatalf("Aborting test because unable to set env: %s", err)
}

count.Tests(t, len(tests)*2, "UnSetTests")
count.Tests(t, len(tests)*2)

defaults.Defaults(lang.InitConf, false)
lang.InitEnv()
Expand Down
4 changes: 2 additions & 2 deletions builtins/core_test.go
Expand Up @@ -16,12 +16,12 @@ var sourceFile map[string]string

// TestCoreDocs tests documentation has been written for core builtins
func __TestCoreDocs(t *testing.T) {
count.Tests(t, 1, "TestCoreDocs")
count.Tests(t, 1)
test.Exists(t, gopath.Source([]string{"builtins"})+"docgen_test.go")

path := gopath.Source([]string{"builtins", "docs"})

count.Tests(t, len(lang.GoFunctions)*2, "TestCoreDocs")
count.Tests(t, len(lang.GoFunctions)*2)
for name := range lang.GoFunctions {
syn := docs.Synonym[name]
if syn == "" {
Expand Down
2 changes: 1 addition & 1 deletion builtins/types/example/marshal_test.go
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestMarshal(t *testing.T) {
count.Tests(t, 1, "TestMarshal")
count.Tests(t, 1)

lang.InitEnv()
fork := lang.ShellProcess.Fork(lang.F_NO_STDOUT)
Expand Down
2 changes: 1 addition & 1 deletion builtins/types/example/unmarshal_test.go
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestUnmarshal(t *testing.T) {
count.Tests(t, 1, "TestUnmarshal")
count.Tests(t, 1)

lang.InitEnv()
fork := lang.ShellProcess.Fork(lang.F_CREATE_STDIN)
Expand Down
4 changes: 2 additions & 2 deletions builtins/types/json/json_test.go
Expand Up @@ -57,7 +57,7 @@ func TestArrayWriter(t *testing.T) {
}

func TestMarshalArrayString(t *testing.T) {
count.Tests(t, 1, "TestMarshalArrayString")
count.Tests(t, 1)

input := []string{"e", "d", "c", "b", "a"} // lets prove the output retains sorting
output := `["e","d","c","b","a"]`
Expand All @@ -80,7 +80,7 @@ func TestMarshalArrayString(t *testing.T) {
}

func TestMarshalArrayInt(t *testing.T) {
count.Tests(t, 1, "TestMarshalArrayInt")
count.Tests(t, 1)

input := []int{5, 4, 3, 2, 1} // lets prove the output retains sorting
output := `[5,4,3,2,1]`
Expand Down
2 changes: 1 addition & 1 deletion builtins/types/toml/toml_test.go
Expand Up @@ -29,7 +29,7 @@ import (
}*/

func TestArrayWriter(t *testing.T) {
count.Tests(t, 1, "TestArrayWriter")
count.Tests(t, 1)

stdout := streams.NewStdin()

Expand Down
2 changes: 1 addition & 1 deletion config/app_test.go
Expand Up @@ -11,7 +11,7 @@ import (
func TestConsts(t *testing.T) {
rx := regexp.MustCompile(`[0-9]+\.[0-9]+\.[0-9]+ ( (ALPHA|BETA|RC[0-9]))?`)

count.Tests(t, 2, "TestConsts")
count.Tests(t, 2)

if AppName == "" {
t.Error("AppName isn't valid")
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Expand Up @@ -9,7 +9,7 @@ import (

// TestConfig tests the config structure
func TestConfig(t *testing.T) {
count.Tests(t, 2, "TestConfig")
count.Tests(t, 2)

conf := NewConfiguration()

Expand Down
2 changes: 1 addition & 1 deletion config/defaults/defaults_test.go
Expand Up @@ -9,7 +9,7 @@ import (

// TestDefaultProfileNotEmpty tests the defaults exist
func TestDefaultProfileNotEmpty(t *testing.T) {
count.Tests(t, 1, "TestDefaultProfileNotEmpty")
count.Tests(t, 1)

s := string(DefaultMurexProfile())
if strings.TrimSpace(s) == "" {
Expand Down
6 changes: 3 additions & 3 deletions config/profile/module_test.go
Expand Up @@ -71,7 +71,7 @@ func testCreateModuleStruct() (posix, plan9, windows Module, err error) {
}

func TestIsDisabled(t *testing.T) {
count.Tests(t, 3, "TestIsDisabled")
count.Tests(t, 3)

disabled = []string{
"foo",
Expand All @@ -97,7 +97,7 @@ func TestPath(t *testing.T) {
t.Skipf("Unable to get current working directory: %s", err)
}

count.Tests(t, 2, "TestPath")
count.Tests(t, 2)

path := m.Path()

Expand Down Expand Up @@ -126,7 +126,7 @@ func TestValidate(t *testing.T) {
t.Skip("Unable to stat path. Skipping this test until murex is run for the first time")
}

count.Tests(t, 6, "TestValidate")
count.Tests(t, 6)

autocomplete.GlobalExes = map[string]bool{
"sh": true,
Expand Down
4 changes: 2 additions & 2 deletions debug/badmutex_test.go
Expand Up @@ -12,7 +12,7 @@ import (
// TestBadMutex proves our test bad mutex (used to help diagnose locking faults)
// does not lock
func TestBadMutex(t *testing.T) {
count.Tests(t, 1, "TestBadMutex")
count.Tests(t, 1)

var (
m BadMutex // if we swap this for sync.Mutex the error should be raised
Expand All @@ -37,7 +37,7 @@ func TestBadMutex(t *testing.T) {

// TestGoodMutex proves our bad mutex test works
func TestGoodMutex(t *testing.T) {
count.Tests(t, 1, "TestGoodMutex")
count.Tests(t, 1)

var (
m sync.Mutex // if we swap this for sync.Mutex the error should be raised
Expand Down
4 changes: 2 additions & 2 deletions defaults_test.go
Expand Up @@ -12,7 +12,7 @@ import (

// TestDefaultConfigExists tests the Default() function populates *config.Config
func TestDefaultConfigExists(t *testing.T) {
count.Tests(t, 1, "TestDefaultConfigExists")
count.Tests(t, 1)

conf := config.NewConfiguration()

Expand All @@ -26,7 +26,7 @@ func TestDefaultConfigExists(t *testing.T) {

// TestDefaultProfileCompiles test the builtin murex_profile compiles
func TestDefaultProfileCompiles(t *testing.T) {
count.Tests(t, 1, "TestDefaultProfileCompiles")
count.Tests(t, 1)

defaults.Defaults(lang.InitConf, false)
lang.InitEnv()
Expand Down
2 changes: 1 addition & 1 deletion gen/gen_test.go
Expand Up @@ -20,7 +20,7 @@ func (l logger) Write(b []byte) (int, error) {
// TestDocgenConfigTemplates tests the config YAML and template files are all
// valid and the project can render
func TestDocgenConfigTemplates(t *testing.T) {
count.Tests(t, 1, "TestDocgenConfigTemplates")
count.Tests(t, 1)

if _, err := os.Stat("gen/docgen.yaml"); os.IsNotExist(err) {
os.Chdir("..")
Expand Down
6 changes: 4 additions & 2 deletions gen/website/footer.html
Expand Up @@ -2,8 +2,10 @@

<div id="build-spec">
This site is rebuilt weekly, the content is automatically generated from <em>murex</em>'s source code.
Last built on $DATE against commit <span id="commit-hash-short">$COMMITHASHSHORT</span><span id="commit-hash-long">$COMMITHASHLONG</span>.
Downloadable <em>murex</em> binaries are also built weekly. Current version is $MUREXVERSION which has been verified against $MUREXTESTS unit tests.
Last built on $DATE against commit <span id="commit-hash-short">$COMMITHASHSHORT</span><span
id="commit-hash-long">$COMMITHASHLONG</span>.
Downloadable <em>murex</em> binaries are also built weekly. Current version is $MUREXVERSION which has been verified
against $MUREXTESTS tests.
</div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion lang/parser.go
Expand Up @@ -456,7 +456,7 @@ func parser(block []rune) (nodes astNodes, pErr ParserError) {
pUpdate(r)
case braceCount > 0:
pUpdate(r)
case !scanFuncName:
case !scanFuncName && last != ' ' && last != ':':
node.ParamTokens = append(node.ParamTokens, make([]parameters.ParamToken, 1))
pCount++
pToken = &node.ParamTokens[pCount][0]
Expand Down
5 changes: 0 additions & 5 deletions lang/parser_np_test.go → lang/parser_namedp_test.go
Expand Up @@ -6,11 +6,6 @@ import (
"github.com/lmorg/murex/lang/proc/parameters"
)

type parserTestConditions struct {
Block string
Expected astNodes
}

func TestParserNamedPiped1(t *testing.T) {
pipeParams := [][]parameters.ParamToken{{{
Key: "<pipe>",
Expand Down

0 comments on commit 9b0c51d

Please sign in to comment.