Skip to content

Commit 2f5728b

Browse files
committed
cedar-go: add code coverage enforcement to CI
Also, add some dummy statements to otherwise empty functions so that they're counted for code coverage purposes. Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
1 parent 922a4e8 commit 2f5728b

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

.github/workflows/build_and_test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ jobs:
1919
run: go build -v ./...
2020

2121
- name: Test
22-
run: go test ./...
22+
run: go test -coverprofile=coverage.out ./...
2323

2424
- name: Lint
2525
uses: golangci/golangci-lint-action@v7
2626

2727
- name: Fuzz
2828
run: mkdir -p testdata && go test -fuzz=FuzzParse -fuzztime 60s && go test -fuzz=FuzzTokenize -fuzztime 60s
29+
30+
- name: Coverage check
31+
run: go tool cover -func=coverage.out | sed 's/%$//' | awk '{ if ($3 < 100.0) { printf "Insufficient code coverage for %s\n", $0; failed=1 } } END { exit failed }'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
tmp/
33
.DS_Store
4+
coverage.out

x/exp/ast/node.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ type StrOpNode struct {
2121
Value types.String
2222
}
2323

24-
func (n StrOpNode) isNode() {}
24+
func (n StrOpNode) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation{}
2525

2626
type BinaryNode struct {
2727
Left, Right IsNode
2828
}
2929

30-
func (n BinaryNode) isNode() {}
30+
func (n BinaryNode) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation{}
3131

3232
type NodeTypeIfThenElse struct {
3333
If, Then, Else IsNode
3434
}
3535

36-
func (n NodeTypeIfThenElse) isNode() {}
36+
func (n NodeTypeIfThenElse) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation
3737

3838
type NodeTypeOr struct{ BinaryNode }
3939

@@ -74,14 +74,14 @@ type NodeTypeLike struct {
7474
Value types.Pattern
7575
}
7676

77-
func (n NodeTypeLike) isNode() {}
77+
func (n NodeTypeLike) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation{}
7878

7979
type NodeTypeIs struct {
8080
Left IsNode
8181
EntityType types.EntityType
8282
}
8383

84-
func (n NodeTypeIs) isNode() {}
84+
func (n NodeTypeIs) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation{}
8585

8686
type NodeTypeIsIn struct {
8787
NodeTypeIs
@@ -106,7 +106,7 @@ type UnaryNode struct {
106106
Arg IsNode
107107
}
108108

109-
func (n UnaryNode) isNode() {}
109+
func (n UnaryNode) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation{}
110110

111111
type NodeTypeNegate struct{ UnaryNode }
112112
type NodeTypeNot struct{ UnaryNode }
@@ -120,7 +120,7 @@ type NodeTypeExtensionCall struct {
120120
Args []IsNode
121121
}
122122

123-
func (n NodeTypeExtensionCall) isNode() {}
123+
func (n NodeTypeExtensionCall) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation{}
124124

125125
func stripNodes(args []Node) []IsNode {
126126
if args == nil {
@@ -170,7 +170,7 @@ type NodeValue struct {
170170
Value types.Value
171171
}
172172

173-
func (n NodeValue) isNode() {}
173+
func (n NodeValue) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation{}
174174

175175
type RecordElementNode struct {
176176
Key types.String
@@ -181,19 +181,19 @@ type NodeTypeRecord struct {
181181
Elements []RecordElementNode
182182
}
183183

184-
func (n NodeTypeRecord) isNode() {}
184+
func (n NodeTypeRecord) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation{}
185185

186186
type NodeTypeSet struct {
187187
Elements []IsNode
188188
}
189189

190-
func (n NodeTypeSet) isNode() {}
190+
func (n NodeTypeSet) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation{}
191191

192192
type NodeTypeVariable struct {
193193
Name types.String
194194
}
195195

196-
func (n NodeTypeVariable) isNode() {}
196+
func (n NodeTypeVariable) isNode() { _ = 0 } // No-op statement injected for code coverage instrumentation{}
197197

198198
type IsNode interface {
199199
isNode()

x/exp/ast/scope.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,19 @@ type IsResourceScopeNode interface {
106106

107107
type ScopeNode struct{}
108108

109-
func (n ScopeNode) isScope() {}
109+
func (n ScopeNode) isScope() { _ = 0 } // No-op statement injected for code coverage instrumentation
110110

111111
type PrincipalScopeNode struct{}
112112

113-
func (n PrincipalScopeNode) isPrincipalScope() {}
113+
func (n PrincipalScopeNode) isPrincipalScope() { _ = 0 } // No-op statement injected for code coverage instrumentation
114114

115115
type ActionScopeNode struct{}
116116

117-
func (n ActionScopeNode) isActionScope() {}
117+
func (n ActionScopeNode) isActionScope() { _ = 0 } // No-op statement injected for code coverage instrumentation
118118

119119
type ResourceScopeNode struct{}
120120

121-
func (n ResourceScopeNode) isResourceScope() {}
121+
func (n ResourceScopeNode) isResourceScope() { _ = 0 } // No-op statement injected for code coverage instrumentation
122122

123123
type ScopeTypeAll struct {
124124
ScopeNode

0 commit comments

Comments
 (0)