MCPcopy Create free account
hub / github.com/dolthub/doltgresql / main

Function main

testing/generation/function_coverage/main.go:36–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34}
35
36func main() {
37 initialization.Initialize(nil, doltgresservercfg.DefaultServerConfig())
38 rootFolder, err := utils.GetRootFolder()
39 if err != nil {
40 fmt.Printf("%s\n", err.Error())
41 return
42 }
43 rootFolder = rootFolder.MoveRoot("testing/generation/function_coverage")
44
45 // Sort the strings for determinism, since range iteration on maps is non-deterministic
46 functionNames := make([]string, 0, len(framework.Catalog))
47 for functionName := range framework.Catalog {
48 functionNames = append(functionNames, functionName)
49 }
50 sort.Strings(functionNames)
51
52 for _, functionName := range functionNames {
53 var assertions []Assertion
54
55 utils.PrintSectionMarker(functionName, '+', 80)
56
57 FunctionLoop:
58 for _, function := range framework.Catalog[functionName] {
59 var literalGeneratorParams []utils.StatementGenerator
60 literalGeneratorParams = append(literalGeneratorParams, utils.Text(functionName+"("))
61 for i, paramType := range function.GetParameters() {
62 if i > 0 {
63 literalGeneratorParams = append(literalGeneratorParams, utils.Text(", "))
64 }
65 if generator, ok := valueMappings[paramType.ID]; ok {
66 literalGeneratorParams = append(literalGeneratorParams, generator)
67 } else {
68 fmt.Printf("missing support for functions with the parameter type: `%s`\n", paramType.String())
69 continue FunctionLoop
70 }
71 }
72 literalGeneratorParams = append(literalGeneratorParams, utils.Text(")"))
73 literalGenerator := utils.Collection(
74 utils.Text("SELECT"),
75 utils.Collection(literalGeneratorParams...),
76 utils.Text(";"),
77 )
78
79 randomInts, err := utils.GenerateRandomInts(500, literalGenerator.Permutations())
80 if err != nil {
81 fmt.Println(err.Error())
82 continue FunctionLoop
83 }
84 for _, randomInt := range randomInts {
85 literalGenerator.SetConsumeIterations(randomInt)
86 assertion := Assertion{
87 Stmt: literalGenerator.String(),
88 Error: false,
89 }
90 result, _, err := QueryPostgres(assertion.Stmt)
91 if err != nil {
92 assertion.Error = true
93 } else {

Callers

nothing calls this directly

Calls 15

InitializeFunction · 0.92
GetRootFolderFunction · 0.92
PrintSectionMarkerFunction · 0.92
TextFunction · 0.92
CollectionFunction · 0.92
GenerateRandomIntsFunction · 0.92
QueryPostgresFunction · 0.85
GenerateTestsFunction · 0.85
PrintfMethod · 0.80
GetParametersMethod · 0.65
StringMethod · 0.65
PermutationsMethod · 0.65

Tested by

no test coverage detected