Skip to content

Commit

Permalink
Merge branch 'main' into rmuller/fix-nested-types
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller committed Mar 12, 2021
2 parents 2504ec0 + 7006e11 commit a0d9c13
Show file tree
Hide file tree
Showing 48 changed files with 2,989 additions and 2,673 deletions.
5 changes: 5 additions & 0 deletions gh-pages/content/assets/stylesheets/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,8 @@ kbd {
.md-typeset a {
color: #5b79a0;
}

/* Required so compliance table is fully visible */
.md-content {
overflow: initial;
}
244 changes: 119 additions & 125 deletions gh-pages/content/specification/6-compliance-report.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
},
"devDependencies": {
"@jest/types": "^26.6.2",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"all-contributors-cli": "^6.20.0",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.0.0",
"eslint": "^7.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint-import-resolver-node": "^0.3.4",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"jest-circus": "^26.6.3",
"jest-config": "^26.6.3",
"jest-expect-message": "^1.0.2",
"lerna": "^3.22.1",
"lerna": "^4.0.0",
"prettier": "^2.2.1",
"standard-version": "^9.1.1",
"ts-jest": "^26.5.2",
"ts-jest": "^26.5.3",
"ts-node": "^9.1.1",
"typescript": "~3.9.9"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/dotnet-runtime-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@jsii/dotnet-runtime": "^0.0.0",
"@types/node": "^10.17.54",
"@types/node": "^10.17.55",
"jsii-calc": "^3.20.120",
"jsii-pacmak": "^0.0.0",
"typescript": "~3.9.9"
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/dotnet-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"devDependencies": {
"@jsii/runtime": "^0.0.0",
"@types/node": "^10.17.54",
"@types/node": "^10.17.55",
"@types/semver": "^7.3.4",
"jsii-build-tools": "^0.0.0",
"semver": "^7.3.4",
Expand Down
53 changes: 52 additions & 1 deletion packages/@jsii/go-runtime-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,55 @@ This directory contains compliance tests for the go language bindings.

## Usage

`yarn build && yarn test`
Build & run Go compliance tests:

```shell
$ cd packages/@jsii/go-runtime-test
$ yarn build && yarn test
```

Produce complaince report:

```shell
$ cd tools/jsii-compliance
$ yarn report
```

## Writing a Test

Let's say we want to implement a test named "nameOfTest".

Add a method under `compliance_test.go` with the following signature:

```go
func (suite *ComplianceSuite) TestNameOfTest()
```

Within this method, write your test.

To indicate that a test is **not applicable** for Go, use the `suite.NotApplicableTest(reason)`:

```go
func (suite *ComplianceSuite) TestCreateObjectAndCtorOverloads() {
suite.NotApplicableTest("Golang does not have overloaded functions so the genearated class only has a single New function")
}
```

To indicate that Go is **not compliant yet** in a specific case, use the
`suite.FailTest(url, reason)` where `url` is the URL of the github issue and
`reason` is the reason why this test is failing:

```go
suite.FailTest("https://github.com/aws/jsii/issues/1234", "subclasssing is not yet supported in go")
```

You can also use the `suite.T()` to add assertions. Bear in mind that if an
assertion fails, the build won't pass, so this shouldn't be used if you want to
report that a feature is missing (use `suite.FailTest()` instead).

For example:

```go
t := suite.T()
t.Errorf("Expected length of empty map to be 0. Got: %d", len(actual))
```
80 changes: 80 additions & 0 deletions packages/@jsii/go-runtime-test/project/compliance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package tests

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"io/ioutil"
"strings"
)

type ComplianceSuite struct {
suite.Suite
_report map[string]map[string]string
}

func (suite *ComplianceSuite) SetupSuite() {
suite._report = map[string]map[string]string{}
}

func (suite *ComplianceSuite) TearDownSuite() {
report, err := json.MarshalIndent(suite._report, "", " ")

if err != nil {
suite.FailNowf("Failed marshalling _report: %s", err.Error())
}
err = ioutil.WriteFile("./compliance-report.json", report, 0644)
if err != nil {
suite.FailNowf("Failed writing _report: %s", err.Error())
}
}

func (suite *ComplianceSuite) Assert() *assert.Assertions {
return assert.New(suite.T())
}

func (suite* ComplianceSuite) reportForTest() map[string]string {
fullName := suite.T().Name()
testName := strings.Split(fullName, "/")[1]
name := strings.Replace(testName, "Test", "", 1)

if val, ok := suite._report[name]; ok {
return val
}

val := map[string]string{}
suite._report[name] = val
return val
}

func (suite *ComplianceSuite) BeforeTest(suiteName, testName string) {
suite.reportForTest()["status"] = "success"
}

func (suite *ComplianceSuite) skipWithStatus(status string, reason string, url string) {
t := suite.T()

report := suite.reportForTest()

report["status"] = status
if reason != "" {
report["reason"] = reason
}

if url != "" {
report["url"] = url
}

t.Skipf("%s: %s", status, reason)
}

// FailTest will report this test as failing with the URL of the github issue that
// reports the bug or missing feature
func (suite *ComplianceSuite) FailTest(reason string, issueUrl string) {
suite.skipWithStatus("failure", reason, issueUrl)
}

// NotApplicableTest will report this compliance test as N/A for this language
func (suite *ComplianceSuite) NotApplicableTest(reason string) {
suite.skipWithStatus("n/a", reason, "")
}
Loading

0 comments on commit a0d9c13

Please sign in to comment.