Turn program gen NYIs into diagnostic errors (#4794)

This commit is contained in:
Evan Boyle 2020-06-10 10:21:53 -07:00 committed by GitHub
parent b77ec919d4
commit 45a901d3e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 5 deletions

View file

@ -2,6 +2,9 @@ CHANGELOG
=========
## HEAD (Unreleased)
- Turn program generation NYIs into diagnostic errors
[#4794](https://github.com/pulumi/pulumi/pull/4794)
- Improve dev version detection logic
[#4732](https://github.com/pulumi/pulumi/pull/4732)

View file

@ -17,8 +17,6 @@ package dotnet
import (
"bytes"
"fmt"
"github.com/pulumi/pulumi/pkg/v2/codegen/schema"
"github.com/pulumi/pulumi/sdk/v2/go/common/util/contract"
"io"
"strings"
@ -28,6 +26,8 @@ import (
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2/model"
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2/model/format"
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2/syntax"
"github.com/pulumi/pulumi/pkg/v2/codegen/schema"
"github.com/pulumi/pulumi/sdk/v2/go/common/util/contract"
)
type generator struct {
@ -468,5 +468,11 @@ func (g *generator) genOutputProperty(w io.Writer, v *hcl2.OutputVariable) {
}
func (g *generator) genNYI(w io.Writer, reason string, vs ...interface{}) {
message := fmt.Sprintf("not yet implemented: %s", fmt.Sprintf(reason, vs...))
g.diagnostics = append(g.diagnostics, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: message,
Detail: message,
})
g.Fgenf(w, "\"TODO: %s\"", fmt.Sprintf(reason, vs...))
}

View file

@ -4,8 +4,10 @@ import (
"bytes"
"io/ioutil"
"path/filepath"
"strings"
"testing"
"github.com/hashicorp/hcl/v2"
"github.com/stretchr/testify/assert"
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2"
@ -26,6 +28,11 @@ func TestGenProgram(t *testing.T) {
continue
}
expectNYIDiags := false
if filepath.Base(f.Name()) == "aws-s3-folder.pp" {
expectNYIDiags = true
}
t.Run(f.Name(), func(t *testing.T) {
path := filepath.Join(testdataPath, f.Name())
contents, err := ioutil.ReadFile(path)
@ -56,8 +63,18 @@ func TestGenProgram(t *testing.T) {
files, diags, err := GenerateProgram(program)
assert.NoError(t, err)
if expectNYIDiags {
var tmpDiags hcl.Diagnostics
for _, d := range diags {
if !strings.HasPrefix(d.Summary, "not yet implemented") {
tmpDiags = append(tmpDiags, d)
}
}
diags = tmpDiags
}
if diags.HasErrors() {
t.Fatalf("failed to bind program: %v", diags)
t.Fatalf("failed to generate program: %v", diags)
}
assert.Equal(t, string(expected), string(files["MyStack.cs"]))
})

View file

@ -630,6 +630,12 @@ func (g *generator) lowerExpression(expr model.Expression, typ model.Type, isInp
}
func (g *generator) genNYI(w io.Writer, reason string, vs ...interface{}) {
message := fmt.Sprintf("not yet implemented: %s", fmt.Sprintf(reason, vs...))
g.diagnostics = append(g.diagnostics, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: message,
Detail: message,
})
g.Fgenf(w, "\"TODO: %s\"", fmt.Sprintf(reason, vs...))
}

View file

@ -365,5 +365,11 @@ func (g *generator) genOutputVariable(w io.Writer, v *hcl2.OutputVariable) {
}
func (g *generator) genNYI(w io.Writer, reason string, vs ...interface{}) {
message := fmt.Sprintf("not yet implemented: %s", fmt.Sprintf(reason, vs...))
g.diagnostics = append(g.diagnostics, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: message,
Detail: message,
})
g.Fgenf(w, "(() => throw new Error(%q))()", fmt.Sprintf(reason, vs...))
}

View file

@ -4,8 +4,10 @@ import (
"bytes"
"io/ioutil"
"path/filepath"
"strings"
"testing"
"github.com/hashicorp/hcl/v2"
"github.com/stretchr/testify/assert"
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2"
@ -26,6 +28,11 @@ func TestGenProgram(t *testing.T) {
continue
}
expectNYIDiags := false
if filepath.Base(f.Name()) == "aws-s3-folder.pp" {
expectNYIDiags = true
}
t.Run(f.Name(), func(t *testing.T) {
path := filepath.Join(testdataPath, f.Name())
contents, err := ioutil.ReadFile(path)
@ -56,8 +63,17 @@ func TestGenProgram(t *testing.T) {
files, diags, err := GenerateProgram(program)
assert.NoError(t, err)
if expectNYIDiags {
var tmpDiags hcl.Diagnostics
for _, d := range diags {
if !strings.HasPrefix(d.Summary, "not yet implemented") {
tmpDiags = append(tmpDiags, d)
}
}
diags = tmpDiags
}
if diags.HasErrors() {
t.Fatalf("failed to bind program: %v", diags)
t.Fatalf("failed to generate program: %v", diags)
}
assert.Equal(t, string(expected), string(files["index.ts"]))
})

View file

@ -366,5 +366,11 @@ func (g *generator) genOutputVariable(w io.Writer, v *hcl2.OutputVariable) {
}
func (g *generator) genNYI(w io.Writer, reason string, vs ...interface{}) {
message := fmt.Sprintf("not yet implemented: %s", fmt.Sprintf(reason, vs...))
g.diagnostics = append(g.diagnostics, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: message,
Detail: message,
})
g.Fgenf(w, "(lambda: raise Exception(%q))()", fmt.Sprintf(reason, vs...))
}

View file

@ -4,8 +4,10 @@ import (
"bytes"
"io/ioutil"
"path/filepath"
"strings"
"testing"
"github.com/hashicorp/hcl/v2"
"github.com/stretchr/testify/assert"
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2"
@ -26,6 +28,11 @@ func TestGenProgram(t *testing.T) {
continue
}
expectNYIDiags := false
if filepath.Base(f.Name()) == "aws-s3-folder.pp" {
expectNYIDiags = true
}
t.Run(f.Name(), func(t *testing.T) {
path := filepath.Join(testdataPath, f.Name())
contents, err := ioutil.ReadFile(path)
@ -56,8 +63,17 @@ func TestGenProgram(t *testing.T) {
files, diags, err := GenerateProgram(program)
assert.NoError(t, err)
if expectNYIDiags {
var tmpDiags hcl.Diagnostics
for _, d := range diags {
if !strings.HasPrefix(d.Summary, "not yet implemented") {
tmpDiags = append(tmpDiags, d)
}
}
diags = tmpDiags
}
if diags.HasErrors() {
t.Fatalf("failed to bind program: %v", diags)
t.Fatalf("failed to generate program: %v", diags)
}
assert.Equal(t, string(expected), string(files["__main__.py"]))
})