Skip to content

Commit 3e44a12

Browse files
committed
Add more test stubs and disable old tests for the Error type
Signed-off-by: Krzysztof Wilczyński <[email protected]>
1 parent 35dcd65 commit 3e44a12

File tree

4 files changed

+89
-86
lines changed

4 files changed

+89
-86
lines changed

errors_test.go

+83-84
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package magic
22

33
import (
4-
"fmt"
54
"reflect"
65
"testing"
76
)
@@ -21,86 +20,86 @@ func TestError(t *testing.T) {
2120
}(err)
2221
}
2322

24-
func TestError_Error(t *testing.T) {
25-
var v string
26-
27-
mgc, err := New()
28-
if err != nil {
29-
t.Fatalf("unable to create new Magic type: %s", err.Error())
30-
}
31-
defer mgc.Close()
32-
33-
v = "magic: an unknown error has occurred"
34-
if n := Version(); n < 518 && n >= 514 {
35-
// A few releases of libmagic were having issues.
36-
v = "magic: no magic files loaded"
37-
}
38-
39-
err = mgc.error()
40-
if ok := compareStrings(err.Error(), v); !ok {
41-
t.Errorf("value given %q, want %q", err.Error(), v)
42-
}
43-
44-
v = "the quick brown fox jumps over the lazy dog"
45-
46-
err = &Error{0, v}
47-
if ok := compareStrings(err.Error(), fmt.Sprintf("magic: %s", v)); !ok {
48-
t.Errorf("value given %q, want %q", err.Error(), v)
49-
}
50-
}
51-
52-
func TestError_Errno(t *testing.T) {
53-
var v int
54-
55-
mgc, err := New()
56-
if err != nil {
57-
t.Fatalf("unable to create new Magic type: %s", err.Error())
58-
}
59-
defer mgc.Close()
60-
61-
v = -1
62-
if n := Version(); n < 518 && n >= 514 {
63-
// A few releases of libmagic were having issues.
64-
v = 0
65-
}
66-
67-
err = mgc.error()
68-
if err.(*Error).Errno != v {
69-
t.Errorf("value given %d, want %d", err.(*Error).Errno, v)
70-
}
71-
72-
v = 42
73-
74-
err = &Error{v, ""}
75-
if err.(*Error).Errno != v {
76-
t.Errorf("value given %d, want %d", err.(*Error).Errno, v)
77-
}
78-
}
79-
80-
func TestError_Message(t *testing.T) {
81-
var v string
82-
83-
mgc, err := New()
84-
if err != nil {
85-
t.Fatalf("unable to create new Magic type: %s", err.Error())
86-
}
87-
defer mgc.Close()
88-
89-
v = "an unknown error has occurred"
90-
if n := Version(); n < 518 && n >= 514 {
91-
// A few releases of libmagic were having issues.
92-
v = "no magic files loaded"
93-
}
94-
95-
err = mgc.error()
96-
if ok := compareStrings(err.(*Error).Message, v); !ok {
97-
t.Errorf("value given %q, want %q", err.(*Error).Message, v)
98-
}
99-
100-
v = "the quick brown fox jumps over the lazy dog"
101-
102-
err = &Error{0, v}
103-
if ok := compareStrings(err.(*Error).Message, v); !ok {
104-
t.Errorf("value given %q, want %q", err.(*Error).Message, v)
105-
}
106-
}
23+
// func TestError_Error(t *testing.T) {
24+
// var v string
25+
26+
// mgc, err := New()
27+
// if err != nil {
28+
// t.Fatalf("unable to create new Magic type: %s", err.Error())
29+
// }
30+
// defer mgc.Close()
31+
32+
// v = "magic: an unknown error has occurred"
33+
// if n := Version(); n < 518 && n >= 514 {
34+
// // A few releases of libmagic were having issues.
35+
// v = "magic: no magic files loaded"
36+
// }
37+
38+
// err = mgc.error()
39+
// if ok := compareStrings(err.Error(), v); !ok {
40+
// t.Errorf("value given %q, want %q", err.Error(), v)
41+
// }
42+
43+
// v = "the quick brown fox jumps over the lazy dog"
44+
45+
// err = &Error{0, v}
46+
// if ok := compareStrings(err.Error(), fmt.Sprintf("magic: %s", v)); !ok {
47+
// t.Errorf("value given %q, want %q", err.Error(), v)
48+
// }
49+
// }
50+
51+
// func TestError_Errno(t *testing.T) {
52+
// var v int
53+
54+
// mgc, err := New()
55+
// if err != nil {
56+
// t.Fatalf("unable to create new Magic type: %s", err.Error())
57+
// }
58+
// defer mgc.Close()
59+
60+
// v = -1
61+
// if n := Version(); n < 518 && n >= 514 {
62+
// // A few releases of libmagic were having issues.
63+
// v = 0
64+
// }
65+
66+
// err = mgc.error()
67+
// if err.(*Error).Errno != v {
68+
// t.Errorf("value given %d, want %d", err.(*Error).Errno, v)
69+
// }
70+
71+
// v = 42
72+
73+
// err = &Error{v, ""}
74+
// if err.(*Error).Errno != v {
75+
// t.Errorf("value given %d, want %d", err.(*Error).Errno, v)
76+
// }
77+
// }
78+
79+
// func TestError_Message(t *testing.T) {
80+
// var v string
81+
82+
// mgc, err := New()
83+
// if err != nil {
84+
// t.Fatalf("unable to create new Magic type: %s", err.Error())
85+
// }
86+
// defer mgc.Close()
87+
88+
// v = "an unknown error has occurred"
89+
// if n := Version(); n < 518 && n >= 514 {
90+
// // A few releases of libmagic were having issues.
91+
// v = "no magic files loaded"
92+
// }
93+
94+
// err = mgc.error()
95+
// if ok := compareStrings(err.(*Error).Message, v); !ok {
96+
// t.Errorf("value given %q, want %q", err.(*Error).Message, v)
97+
// }
98+
99+
// v = "the quick brown fox jumps over the lazy dog"
100+
101+
// err = &Error{0, v}
102+
// if ok := compareStrings(err.(*Error).Message, v); !ok {
103+
// t.Errorf("value given %q, want %q", err.(*Error).Message, v)
104+
// }
105+
// }

example_package_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ func Example_closure() {
6161

6262
// func Example_disable_autoload() {
6363
// }
64+
65+
// func Example_do_not_stop_on_errors() {
66+
// }

example_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func Example_basic() {
2929
// File MIME is: image/png; charset=binary
3030
}
3131

32+
// func Example_must() {
33+
// }
34+
3235
// This example shows how to quickly find MIME type for a file.
3336
func ExampleFileType() {
3437
// The magic.FileType function will open the Magic database,

magic.go

-2
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ func (mgc *Magic) Load(files ...string) error {
363363
if err := verifyOpen(mgc); err != nil {
364364
return err
365365
}
366-
367366
// Clear paths. To be set again when the Magic
368367
// database files are successfully loaded.
369368
mgc.paths = []string{}
@@ -404,7 +403,6 @@ func (mgc *Magic) LoadBuffers(buffers ...[]byte) error {
404403
p *unsafe.Pointer
405404
s *C.size_t
406405
)
407-
408406
// Clear paths. To be set again when the Magic
409407
// database files are successfully loaded.
410408
mgc.paths = []string{}

0 commit comments

Comments
 (0)