forked from moovweb/gokogiri
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils_test.go
More file actions
72 lines (57 loc) · 1.9 KB
/
utils_test.go
File metadata and controls
72 lines (57 loc) · 1.9 KB
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
71
72
package html
import (
"fmt"
"github.com/Runscope/gokogiri/help"
"io/ioutil"
"path/filepath"
"strings"
"testing"
)
func badOutput(actual string, expected string) {
fmt.Printf("Got:\n[%v]\n", actual)
fmt.Printf("Expected:\n[%v]\n", expected)
}
func getTestData(name string) (input []byte, output []byte, error string) {
var errorMessage string
offset := "\t"
inputFile := filepath.Join(name, "input.txt")
input, err := ioutil.ReadFile(inputFile)
if err != nil {
errorMessage += fmt.Sprintf("%vCouldn't read test (%v) input:\n%v\n", offset, name, offset+err.Error())
}
output, err = ioutil.ReadFile(filepath.Join(name, "output.txt"))
if err != nil {
errorMessage += fmt.Sprintf("%vCouldn't read test (%v) output:\n%v\n", offset, name, offset+err.Error())
}
return input, output, errorMessage
}
func collectTests(suite string) (names []string, error string) {
testPath := filepath.Join("tests", suite)
entries, err := ioutil.ReadDir(testPath)
if err != nil {
return nil, fmt.Sprintf("Couldn't read tests:\n%v\n", err.Error())
}
for _, entry := range entries {
if strings.HasPrefix(entry.Name(), "_") || strings.HasPrefix(entry.Name(), ".") {
continue
}
if entry.IsDir() {
names = append(names, filepath.Join(testPath, entry.Name()))
}
}
return
}
func CheckXmlMemoryLeaks(t *testing.T) {
// LibxmlCleanUpParser() should only be called once during the lifetime of the
// program, but because there's no way to know when the last test of the suite
// runs in go, we can't accurately call it strictly once, so just avoid calling
// it for now because it's known to cause crashes if called multiple times.
//println("Cleaning up parser...")
//help.LibxmlCleanUpParser()
println("Checking for libxml leaks...")
if !help.LibxmlCheckMemoryLeak() {
println("Found memory leaks!")
t.Errorf("Memory leaks: %d!!!", help.LibxmlGetMemoryAllocation())
help.LibxmlReportMemoryLeak()
}
}