File: dsl_suite_test.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.15.0-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 4,112 kB
  • sloc: javascript: 59; sh: 14; makefile: 7
file content (70 lines) | stat: -rw-r--r-- 1,619 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package dsl_test

import (
	"go/ast"
	"go/parser"
	"go/token"
	"testing"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
)

func TestDSL(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "DSL Suite")
}

func ExtractSymbols(f *ast.File) []string {
	symbols := []string{}
	for _, decl := range f.Decls {
		names := []string{}
		switch v := decl.(type) {
		case *ast.FuncDecl:
			if v.Recv == nil {
				names = append(names, v.Name.Name)
			}
		case *ast.GenDecl:
			switch v.Tok {
			case token.TYPE:
				s := v.Specs[0].(*ast.TypeSpec)
				names = append(names, s.Name.Name)
			case token.CONST, token.VAR:
				s := v.Specs[0].(*ast.ValueSpec)
				for _, n := range s.Names {
					names = append(names, n.Name)
				}
			}
		}
		for _, name := range names {
			if ast.IsExported(name) {
				symbols = append(symbols, name)
			}
		}
	}
	return symbols
}

var _ = It("ensures complete coverage of the core dsl", func() {
	fset := token.NewFileSet()
	pkgs, err := parser.ParseDir(fset, "../", nil, 0)
	Ω(err).ShouldNot(HaveOccurred())
	expectedSymbols := []string{}
	for fn, file := range pkgs["ginkgo"].Files {
		if fn == "../deprecated_dsl.go" {
			continue
		}
		expectedSymbols = append(expectedSymbols, ExtractSymbols(file)...)
	}

	actualSymbols := []string{}
	for _, pkg := range []string{"core", "reporting", "decorators", "table"} {
		pkgs, err := parser.ParseDir(fset, "./"+pkg, nil, 0)
		Ω(err).ShouldNot(HaveOccurred())
		for _, file := range pkgs[pkg].Files {
			actualSymbols = append(actualSymbols, ExtractSymbols(file)...)
		}
	}

	Ω(actualSymbols).Should(ConsistOf(expectedSymbols))
})