1
1
package errgoengine_test
2
2
3
3
import (
4
- "context"
5
4
"testing"
6
5
7
6
lib "github.com/nedpals/errgoengine"
8
7
testutils "github.com/nedpals/errgoengine/test_utils"
9
8
)
10
9
11
- type TestAnalyzer struct {}
12
-
13
- func (TestAnalyzer ) FallbackSymbol () lib.Symbol {
14
- return nil
15
- }
16
-
17
- func (TestAnalyzer ) FindSymbol (string ) lib.Symbol { return nil }
18
-
19
- func (TestAnalyzer ) AnalyzeNode (context.Context , lib.SyntaxNode ) lib.Symbol {
20
- return nil
21
- }
22
-
23
- func (TestAnalyzer ) AnalyzeImport (lib.ImportParams ) lib.ResolvedImport {
24
- return lib.ResolvedImport {}
25
- }
26
-
27
- var testLanguage = & lib.Language {
28
- Name : "TestLang" ,
29
- FilePatterns : []string {".test" },
30
- StackTracePattern : `\sin (?P<symbol>\S+) at (?P<path>\S+):(?P<position>\d+)` ,
31
- LocationConverter : func (ctx lib.LocationConverterContext ) lib.Location {
32
- return lib.Location {
33
- DocumentPath : ctx .Path ,
34
- StartPos : lib.Position {0 , 0 , 0 },
35
- EndPos : lib.Position {0 , 0 , 0 },
36
- }
37
- },
38
- AnalyzerFactory : func (cd * lib.ContextData ) lib.LanguageAnalyzer {
39
- return TestAnalyzer {}
40
- },
41
- }
42
-
43
10
func emptyExplainFn (cd * lib.ContextData , gen * lib.ExplainGenerator ) {}
44
11
func emptyBugFixFn (cd * lib.ContextData , gen * lib.BugFixGenerator ) {}
45
12
46
13
func setupTemplate (template lib.ErrorTemplate ) (* lib.CompiledErrorTemplate , error ) {
47
14
errorTemplates := lib.ErrorTemplates {}
48
- return errorTemplates .Add (testLanguage , template )
15
+ return errorTemplates .Add (lib . TestLanguage , template )
49
16
}
50
17
51
18
func TestErrorTemplate (t * testing.T ) {
@@ -62,7 +29,7 @@ func TestErrorTemplate(t *testing.T) {
62
29
}
63
30
64
31
testutils .Equals (t , tmp .Name , "SampleError" )
65
- testutils .Equals (t , tmp .Language , testLanguage )
32
+ testutils .Equals (t , tmp .Language , lib . TestLanguage )
66
33
testutils .Equals (t , tmp .Pattern .String (), `(?m)^This is a sample error(?P<stacktrace>(?:.|\s)*)$` )
67
34
testutils .Equals (t , tmp .StackTraceRegex ().String (), `(?m)\sin (?P<symbol>\S+) at (?P<path>\S+):(?P<position>\d+)` )
68
35
testutils .ExpectNil (t , tmp .StackTracePattern )
@@ -82,7 +49,7 @@ func TestErrorTemplate(t *testing.T) {
82
49
}
83
50
84
51
testutils .Equals (t , tmp .Name , "SampleError2" )
85
- testutils .Equals (t , tmp .Language , testLanguage )
52
+ testutils .Equals (t , tmp .Language , lib . TestLanguage )
86
53
testutils .Equals (t , tmp .Pattern .String (), `(?m)^This is a sample error with stack trace(?P<stacktrace>(?:.|\s)*)$` )
87
54
testutils .Equals (t , tmp .StackTraceRegex ().String (), `(?P<symbol>\S+):(?P<path>\S+):(?P<position>\d+)` )
88
55
})
@@ -100,7 +67,7 @@ func TestErrorTemplate(t *testing.T) {
100
67
}
101
68
102
69
testutils .Equals (t , tmp .Name , "SampleError3" )
103
- testutils .Equals (t , tmp .Language , testLanguage )
70
+ testutils .Equals (t , tmp .Language , lib . TestLanguage )
104
71
testutils .Equals (t , tmp .Pattern .String (), `(?m)^Stack trace in middle (?P<stacktrace>(?:.|\s)*)test$` )
105
72
testutils .ExpectNil (t , tmp .StackTracePattern )
106
73
})
@@ -118,7 +85,7 @@ func TestStackTraceRegex(t *testing.T) {
118
85
t .Fatal (err )
119
86
}
120
87
121
- testutils .Equals (t , tmp .StackTraceRegex ().String (), "(?m)" + testLanguage .StackTracePattern )
88
+ testutils .Equals (t , tmp .StackTraceRegex ().String (), "(?m)" + lib . TestLanguage .StackTracePattern )
122
89
})
123
90
124
91
t .Run ("With custom stack trace" , func (t * testing.T ) {
0 commit comments