This adds some tests around cloud targeting, in addition to enabling builds to use in-memory Mufiles (mostly to make testing simpler, but this is a generally useful capability to have when hosting the compiler API).
60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
package compiler
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/marapongo/mu/pkg/diag"
|
|
"github.com/marapongo/mu/pkg/errors"
|
|
)
|
|
|
|
func TestSymbolAlreadyExists(t *testing.T) {
|
|
sink := buildNoCodegen("testdata", "binder", "bad__symbol_already_exists")
|
|
|
|
// Check that the compiler complained about a duplicate symbol.
|
|
d := errors.SymbolAlreadyExists
|
|
assert.Equal(t, 1, sink.Errors(), "expected a single error")
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, "foo")),
|
|
sink.ErrorMsgs()[0])
|
|
}
|
|
|
|
func TestTypeNotFound1(t *testing.T) {
|
|
sink := buildNoCodegen("testdata", "binder", "bad__type_not_found__1")
|
|
|
|
// Check that the compiler complained about the type missisng.
|
|
d := errors.TypeNotFound
|
|
assert.Equal(t, 1, sink.Errors(), "expected a single error")
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, "something/non/existent")),
|
|
sink.ErrorMsgs()[0])
|
|
}
|
|
|
|
func TestTypeNotFound2(t *testing.T) {
|
|
sink := buildNoCodegen("testdata", "binder", "bad__type_not_found__2")
|
|
|
|
// Check that the compiler complained about the type missisng.
|
|
d := errors.TypeNotFound
|
|
assert.Equal(t, 1, sink.Errors(), "expected a single error")
|
|
assert.Equal(t,
|
|
fmt.Sprintf("%v: %v%v: %v: %v\n",
|
|
diag.DefaultSinkErrorPrefix, diag.DefaultSinkIDPrefix, d.ID, "Mu.yaml",
|
|
fmt.Sprintf(d.Message, "something/non/existent")),
|
|
sink.ErrorMsgs()[0])
|
|
}
|
|
|
|
func TestGoodPredefTypes(t *testing.T) {
|
|
sink := buildNoCodegen("testdata", "binder", "good__predef_types")
|
|
|
|
// Check that no errors are found when using predefined stack types.
|
|
assert.Equal(t, 0, sink.Errors(), "expected no errors when binding to predef types")
|
|
}
|