fileutils_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. package fileutils
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "path"
  6. "path/filepath"
  7. "runtime"
  8. "strings"
  9. "testing"
  10. )
  11. // CopyFile with invalid src
  12. func TestCopyFileWithInvalidSrc(t *testing.T) {
  13. tempFolder, err := ioutil.TempDir("", "docker-fileutils-test")
  14. defer os.RemoveAll(tempFolder)
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. bytes, err := CopyFile("/invalid/file/path", path.Join(tempFolder, "dest"))
  19. if err == nil {
  20. t.Fatal("Should have fail to copy an invalid src file")
  21. }
  22. if bytes != 0 {
  23. t.Fatal("Should have written 0 bytes")
  24. }
  25. }
  26. // CopyFile with invalid dest
  27. func TestCopyFileWithInvalidDest(t *testing.T) {
  28. tempFolder, err := ioutil.TempDir("", "docker-fileutils-test")
  29. defer os.RemoveAll(tempFolder)
  30. if err != nil {
  31. t.Fatal(err)
  32. }
  33. src := path.Join(tempFolder, "file")
  34. err = ioutil.WriteFile(src, []byte("content"), 0740)
  35. if err != nil {
  36. t.Fatal(err)
  37. }
  38. bytes, err := CopyFile(src, path.Join(tempFolder, "/invalid/dest/path"))
  39. if err == nil {
  40. t.Fatal("Should have fail to copy an invalid src file")
  41. }
  42. if bytes != 0 {
  43. t.Fatal("Should have written 0 bytes")
  44. }
  45. }
  46. // CopyFile with same src and dest
  47. func TestCopyFileWithSameSrcAndDest(t *testing.T) {
  48. tempFolder, err := ioutil.TempDir("", "docker-fileutils-test")
  49. defer os.RemoveAll(tempFolder)
  50. if err != nil {
  51. t.Fatal(err)
  52. }
  53. file := path.Join(tempFolder, "file")
  54. err = ioutil.WriteFile(file, []byte("content"), 0740)
  55. if err != nil {
  56. t.Fatal(err)
  57. }
  58. bytes, err := CopyFile(file, file)
  59. if err != nil {
  60. t.Fatal(err)
  61. }
  62. if bytes != 0 {
  63. t.Fatal("Should have written 0 bytes as it is the same file.")
  64. }
  65. }
  66. // CopyFile with same src and dest but path is different and not clean
  67. func TestCopyFileWithSameSrcAndDestWithPathNameDifferent(t *testing.T) {
  68. tempFolder, err := ioutil.TempDir("", "docker-fileutils-test")
  69. defer os.RemoveAll(tempFolder)
  70. if err != nil {
  71. t.Fatal(err)
  72. }
  73. testFolder := path.Join(tempFolder, "test")
  74. err = os.MkdirAll(testFolder, 0740)
  75. if err != nil {
  76. t.Fatal(err)
  77. }
  78. file := path.Join(testFolder, "file")
  79. sameFile := testFolder + "/../test/file"
  80. err = ioutil.WriteFile(file, []byte("content"), 0740)
  81. if err != nil {
  82. t.Fatal(err)
  83. }
  84. bytes, err := CopyFile(file, sameFile)
  85. if err != nil {
  86. t.Fatal(err)
  87. }
  88. if bytes != 0 {
  89. t.Fatal("Should have written 0 bytes as it is the same file.")
  90. }
  91. }
  92. func TestCopyFile(t *testing.T) {
  93. tempFolder, err := ioutil.TempDir("", "docker-fileutils-test")
  94. defer os.RemoveAll(tempFolder)
  95. if err != nil {
  96. t.Fatal(err)
  97. }
  98. src := path.Join(tempFolder, "src")
  99. dest := path.Join(tempFolder, "dest")
  100. ioutil.WriteFile(src, []byte("content"), 0777)
  101. ioutil.WriteFile(dest, []byte("destContent"), 0777)
  102. bytes, err := CopyFile(src, dest)
  103. if err != nil {
  104. t.Fatal(err)
  105. }
  106. if bytes != 7 {
  107. t.Fatalf("Should have written %d bytes but wrote %d", 7, bytes)
  108. }
  109. actual, err := ioutil.ReadFile(dest)
  110. if err != nil {
  111. t.Fatal(err)
  112. }
  113. if string(actual) != "content" {
  114. t.Fatalf("Dest content was '%s', expected '%s'", string(actual), "content")
  115. }
  116. }
  117. // Reading a symlink to a directory must return the directory
  118. func TestReadSymlinkedDirectoryExistingDirectory(t *testing.T) {
  119. // TODO Windows: Port this test
  120. if runtime.GOOS == "windows" {
  121. t.Skip("Needs porting to Windows")
  122. }
  123. var err error
  124. if err = os.Mkdir("/tmp/testReadSymlinkToExistingDirectory", 0777); err != nil {
  125. t.Errorf("failed to create directory: %s", err)
  126. }
  127. if err = os.Symlink("/tmp/testReadSymlinkToExistingDirectory", "/tmp/dirLinkTest"); err != nil {
  128. t.Errorf("failed to create symlink: %s", err)
  129. }
  130. var path string
  131. if path, err = ReadSymlinkedDirectory("/tmp/dirLinkTest"); err != nil {
  132. t.Fatalf("failed to read symlink to directory: %s", err)
  133. }
  134. if path != "/tmp/testReadSymlinkToExistingDirectory" {
  135. t.Fatalf("symlink returned unexpected directory: %s", path)
  136. }
  137. if err = os.Remove("/tmp/testReadSymlinkToExistingDirectory"); err != nil {
  138. t.Errorf("failed to remove temporary directory: %s", err)
  139. }
  140. if err = os.Remove("/tmp/dirLinkTest"); err != nil {
  141. t.Errorf("failed to remove symlink: %s", err)
  142. }
  143. }
  144. // Reading a non-existing symlink must fail
  145. func TestReadSymlinkedDirectoryNonExistingSymlink(t *testing.T) {
  146. var path string
  147. var err error
  148. if path, err = ReadSymlinkedDirectory("/tmp/test/foo/Non/ExistingPath"); err == nil {
  149. t.Fatalf("error expected for non-existing symlink")
  150. }
  151. if path != "" {
  152. t.Fatalf("expected empty path, but '%s' was returned", path)
  153. }
  154. }
  155. // Reading a symlink to a file must fail
  156. func TestReadSymlinkedDirectoryToFile(t *testing.T) {
  157. // TODO Windows: Port this test
  158. if runtime.GOOS == "windows" {
  159. t.Skip("Needs porting to Windows")
  160. }
  161. var err error
  162. var file *os.File
  163. if file, err = os.Create("/tmp/testReadSymlinkToFile"); err != nil {
  164. t.Fatalf("failed to create file: %s", err)
  165. }
  166. file.Close()
  167. if err = os.Symlink("/tmp/testReadSymlinkToFile", "/tmp/fileLinkTest"); err != nil {
  168. t.Errorf("failed to create symlink: %s", err)
  169. }
  170. var path string
  171. if path, err = ReadSymlinkedDirectory("/tmp/fileLinkTest"); err == nil {
  172. t.Fatalf("ReadSymlinkedDirectory on a symlink to a file should've failed")
  173. }
  174. if path != "" {
  175. t.Fatalf("path should've been empty: %s", path)
  176. }
  177. if err = os.Remove("/tmp/testReadSymlinkToFile"); err != nil {
  178. t.Errorf("failed to remove file: %s", err)
  179. }
  180. if err = os.Remove("/tmp/fileLinkTest"); err != nil {
  181. t.Errorf("failed to remove symlink: %s", err)
  182. }
  183. }
  184. func TestWildcardMatches(t *testing.T) {
  185. match, _ := Matches("fileutils.go", []string{"*"})
  186. if match != true {
  187. t.Errorf("failed to get a wildcard match, got %v", match)
  188. }
  189. }
  190. // A simple pattern match should return true.
  191. func TestPatternMatches(t *testing.T) {
  192. match, _ := Matches("fileutils.go", []string{"*.go"})
  193. if match != true {
  194. t.Errorf("failed to get a match, got %v", match)
  195. }
  196. }
  197. // An exclusion followed by an inclusion should return true.
  198. func TestExclusionPatternMatchesPatternBefore(t *testing.T) {
  199. match, _ := Matches("fileutils.go", []string{"!fileutils.go", "*.go"})
  200. if match != true {
  201. t.Errorf("failed to get true match on exclusion pattern, got %v", match)
  202. }
  203. }
  204. // A folder pattern followed by an exception should return false.
  205. func TestPatternMatchesFolderExclusions(t *testing.T) {
  206. match, _ := Matches("docs/README.md", []string{"docs", "!docs/README.md"})
  207. if match != false {
  208. t.Errorf("failed to get a false match on exclusion pattern, got %v", match)
  209. }
  210. }
  211. // A folder pattern followed by an exception should return false.
  212. func TestPatternMatchesFolderWithSlashExclusions(t *testing.T) {
  213. match, _ := Matches("docs/README.md", []string{"docs/", "!docs/README.md"})
  214. if match != false {
  215. t.Errorf("failed to get a false match on exclusion pattern, got %v", match)
  216. }
  217. }
  218. // A folder pattern followed by an exception should return false.
  219. func TestPatternMatchesFolderWildcardExclusions(t *testing.T) {
  220. match, _ := Matches("docs/README.md", []string{"docs/*", "!docs/README.md"})
  221. if match != false {
  222. t.Errorf("failed to get a false match on exclusion pattern, got %v", match)
  223. }
  224. }
  225. // A pattern followed by an exclusion should return false.
  226. func TestExclusionPatternMatchesPatternAfter(t *testing.T) {
  227. match, _ := Matches("fileutils.go", []string{"*.go", "!fileutils.go"})
  228. if match != false {
  229. t.Errorf("failed to get false match on exclusion pattern, got %v", match)
  230. }
  231. }
  232. // A filename evaluating to . should return false.
  233. func TestExclusionPatternMatchesWholeDirectory(t *testing.T) {
  234. match, _ := Matches(".", []string{"*.go"})
  235. if match != false {
  236. t.Errorf("failed to get false match on ., got %v", match)
  237. }
  238. }
  239. // A single ! pattern should return an error.
  240. func TestSingleExclamationError(t *testing.T) {
  241. _, err := Matches("fileutils.go", []string{"!"})
  242. if err == nil {
  243. t.Errorf("failed to get an error for a single exclamation point, got %v", err)
  244. }
  245. }
  246. // A string preceded with a ! should return true from Exclusion.
  247. func TestExclusion(t *testing.T) {
  248. exclusion := exclusion("!")
  249. if !exclusion {
  250. t.Errorf("failed to get true for a single !, got %v", exclusion)
  251. }
  252. }
  253. // Matches with no patterns
  254. func TestMatchesWithNoPatterns(t *testing.T) {
  255. matches, err := Matches("/any/path/there", []string{})
  256. if err != nil {
  257. t.Fatal(err)
  258. }
  259. if matches {
  260. t.Fatalf("Should not have match anything")
  261. }
  262. }
  263. // Matches with malformed patterns
  264. func TestMatchesWithMalformedPatterns(t *testing.T) {
  265. matches, err := Matches("/any/path/there", []string{"["})
  266. if err == nil {
  267. t.Fatal("Should have failed because of a malformed syntax in the pattern")
  268. }
  269. if matches {
  270. t.Fatalf("Should not have match anything")
  271. }
  272. }
  273. // Test lots of variants of patterns & strings
  274. func TestMatches(t *testing.T) {
  275. // TODO Windows: Port this test
  276. if runtime.GOOS == "windows" {
  277. t.Skip("Needs porting to Windows")
  278. }
  279. tests := []struct {
  280. pattern string
  281. text string
  282. pass bool
  283. }{
  284. {"**", "file", true},
  285. {"**", "file/", true},
  286. {"**/", "file", true}, // weird one
  287. {"**/", "file/", true},
  288. {"**", "/", true},
  289. {"**/", "/", true},
  290. {"**", "dir/file", true},
  291. {"**/", "dir/file", true},
  292. {"**", "dir/file/", true},
  293. {"**/", "dir/file/", true},
  294. {"**/**", "dir/file", true},
  295. {"**/**", "dir/file/", true},
  296. {"dir/**", "dir/file", true},
  297. {"dir/**", "dir/file/", true},
  298. {"dir/**", "dir/dir2/file", true},
  299. {"dir/**", "dir/dir2/file/", true},
  300. {"**/dir2/*", "dir/dir2/file", true},
  301. {"**/dir2/*", "dir/dir2/file/", false},
  302. {"**/dir2/**", "dir/dir2/dir3/file", true},
  303. {"**/dir2/**", "dir/dir2/dir3/file/", true},
  304. {"**file", "file", true},
  305. {"**file", "dir/file", true},
  306. {"**/file", "dir/file", true},
  307. {"**file", "dir/dir/file", true},
  308. {"**/file", "dir/dir/file", true},
  309. {"**/file*", "dir/dir/file", true},
  310. {"**/file*", "dir/dir/file.txt", true},
  311. {"**/file*txt", "dir/dir/file.txt", true},
  312. {"**/file*.txt", "dir/dir/file.txt", true},
  313. {"**/file*.txt*", "dir/dir/file.txt", true},
  314. {"**/**/*.txt", "dir/dir/file.txt", true},
  315. {"**/**/*.txt2", "dir/dir/file.txt", false},
  316. {"**/*.txt", "file.txt", true},
  317. {"**/**/*.txt", "file.txt", true},
  318. {"a**/*.txt", "a/file.txt", true},
  319. {"a**/*.txt", "a/dir/file.txt", true},
  320. {"a**/*.txt", "a/dir/dir/file.txt", true},
  321. {"a/*.txt", "a/dir/file.txt", false},
  322. {"a/*.txt", "a/file.txt", true},
  323. {"a/*.txt**", "a/file.txt", true},
  324. {"a[b-d]e", "ae", false},
  325. {"a[b-d]e", "ace", true},
  326. {"a[b-d]e", "aae", false},
  327. {"a[^b-d]e", "aze", true},
  328. {".*", ".foo", true},
  329. {".*", "foo", false},
  330. {"abc.def", "abcdef", false},
  331. {"abc.def", "abc.def", true},
  332. {"abc.def", "abcZdef", false},
  333. {"abc?def", "abcZdef", true},
  334. {"abc?def", "abcdef", false},
  335. {"a\\*b", "a*b", true},
  336. {"a\\", "a", false},
  337. {"a\\", "a\\", false},
  338. {"a\\\\", "a\\", true},
  339. {"**/foo/bar", "foo/bar", true},
  340. {"**/foo/bar", "dir/foo/bar", true},
  341. {"**/foo/bar", "dir/dir2/foo/bar", true},
  342. {"abc/**", "abc", false},
  343. {"abc/**", "abc/def", true},
  344. {"abc/**", "abc/def/ghi", true},
  345. {"**/.foo", ".foo", true},
  346. {"**/.foo", "bar.foo", false},
  347. }
  348. for _, test := range tests {
  349. res, _ := regexpMatch(test.pattern, test.text)
  350. if res != test.pass {
  351. t.Fatalf("Failed: %v - res:%v", test, res)
  352. }
  353. }
  354. }
  355. // An empty string should return true from Empty.
  356. func TestEmpty(t *testing.T) {
  357. empty := empty("")
  358. if !empty {
  359. t.Errorf("failed to get true for an empty string, got %v", empty)
  360. }
  361. }
  362. func TestCleanPatterns(t *testing.T) {
  363. cleaned, _, _, _ := CleanPatterns([]string{"docs", "config"})
  364. if len(cleaned) != 2 {
  365. t.Errorf("expected 2 element slice, got %v", len(cleaned))
  366. }
  367. }
  368. func TestCleanPatternsStripEmptyPatterns(t *testing.T) {
  369. cleaned, _, _, _ := CleanPatterns([]string{"docs", "config", ""})
  370. if len(cleaned) != 2 {
  371. t.Errorf("expected 2 element slice, got %v", len(cleaned))
  372. }
  373. }
  374. func TestCleanPatternsExceptionFlag(t *testing.T) {
  375. _, _, exceptions, _ := CleanPatterns([]string{"docs", "!docs/README.md"})
  376. if !exceptions {
  377. t.Errorf("expected exceptions to be true, got %v", exceptions)
  378. }
  379. }
  380. func TestCleanPatternsLeadingSpaceTrimmed(t *testing.T) {
  381. _, _, exceptions, _ := CleanPatterns([]string{"docs", " !docs/README.md"})
  382. if !exceptions {
  383. t.Errorf("expected exceptions to be true, got %v", exceptions)
  384. }
  385. }
  386. func TestCleanPatternsTrailingSpaceTrimmed(t *testing.T) {
  387. _, _, exceptions, _ := CleanPatterns([]string{"docs", "!docs/README.md "})
  388. if !exceptions {
  389. t.Errorf("expected exceptions to be true, got %v", exceptions)
  390. }
  391. }
  392. func TestCleanPatternsErrorSingleException(t *testing.T) {
  393. _, _, _, err := CleanPatterns([]string{"!"})
  394. if err == nil {
  395. t.Errorf("expected error on single exclamation point, got %v", err)
  396. }
  397. }
  398. func TestCleanPatternsFolderSplit(t *testing.T) {
  399. _, dirs, _, _ := CleanPatterns([]string{"docs/config/CONFIG.md"})
  400. if dirs[0][0] != "docs" {
  401. t.Errorf("expected first element in dirs slice to be docs, got %v", dirs[0][1])
  402. }
  403. if dirs[0][1] != "config" {
  404. t.Errorf("expected first element in dirs slice to be config, got %v", dirs[0][1])
  405. }
  406. }
  407. func TestCreateIfNotExistsDir(t *testing.T) {
  408. tempFolder, err := ioutil.TempDir("", "docker-fileutils-test")
  409. if err != nil {
  410. t.Fatal(err)
  411. }
  412. defer os.RemoveAll(tempFolder)
  413. folderToCreate := filepath.Join(tempFolder, "tocreate")
  414. if err := CreateIfNotExists(folderToCreate, true); err != nil {
  415. t.Fatal(err)
  416. }
  417. fileinfo, err := os.Stat(folderToCreate)
  418. if err != nil {
  419. t.Fatalf("Should have create a folder, got %v", err)
  420. }
  421. if !fileinfo.IsDir() {
  422. t.Fatalf("Should have been a dir, seems it's not")
  423. }
  424. }
  425. func TestCreateIfNotExistsFile(t *testing.T) {
  426. tempFolder, err := ioutil.TempDir("", "docker-fileutils-test")
  427. if err != nil {
  428. t.Fatal(err)
  429. }
  430. defer os.RemoveAll(tempFolder)
  431. fileToCreate := filepath.Join(tempFolder, "file/to/create")
  432. if err := CreateIfNotExists(fileToCreate, false); err != nil {
  433. t.Fatal(err)
  434. }
  435. fileinfo, err := os.Stat(fileToCreate)
  436. if err != nil {
  437. t.Fatalf("Should have create a file, got %v", err)
  438. }
  439. if fileinfo.IsDir() {
  440. t.Fatalf("Should have been a file, seems it's not")
  441. }
  442. }
  443. // These matchTests are stolen from go's filepath Match tests.
  444. type matchTest struct {
  445. pattern, s string
  446. match bool
  447. err error
  448. }
  449. var matchTests = []matchTest{
  450. {"abc", "abc", true, nil},
  451. {"*", "abc", true, nil},
  452. {"*c", "abc", true, nil},
  453. {"a*", "a", true, nil},
  454. {"a*", "abc", true, nil},
  455. {"a*", "ab/c", false, nil},
  456. {"a*/b", "abc/b", true, nil},
  457. {"a*/b", "a/c/b", false, nil},
  458. {"a*b*c*d*e*/f", "axbxcxdxe/f", true, nil},
  459. {"a*b*c*d*e*/f", "axbxcxdxexxx/f", true, nil},
  460. {"a*b*c*d*e*/f", "axbxcxdxe/xxx/f", false, nil},
  461. {"a*b*c*d*e*/f", "axbxcxdxexxx/fff", false, nil},
  462. {"a*b?c*x", "abxbbxdbxebxczzx", true, nil},
  463. {"a*b?c*x", "abxbbxdbxebxczzy", false, nil},
  464. {"ab[c]", "abc", true, nil},
  465. {"ab[b-d]", "abc", true, nil},
  466. {"ab[e-g]", "abc", false, nil},
  467. {"ab[^c]", "abc", false, nil},
  468. {"ab[^b-d]", "abc", false, nil},
  469. {"ab[^e-g]", "abc", true, nil},
  470. {"a\\*b", "a*b", true, nil},
  471. {"a\\*b", "ab", false, nil},
  472. {"a?b", "a☺b", true, nil},
  473. {"a[^a]b", "a☺b", true, nil},
  474. {"a???b", "a☺b", false, nil},
  475. {"a[^a][^a][^a]b", "a☺b", false, nil},
  476. {"[a-ζ]*", "α", true, nil},
  477. {"*[a-ζ]", "A", false, nil},
  478. {"a?b", "a/b", false, nil},
  479. {"a*b", "a/b", false, nil},
  480. {"[\\]a]", "]", true, nil},
  481. {"[\\-]", "-", true, nil},
  482. {"[x\\-]", "x", true, nil},
  483. {"[x\\-]", "-", true, nil},
  484. {"[x\\-]", "z", false, nil},
  485. {"[\\-x]", "x", true, nil},
  486. {"[\\-x]", "-", true, nil},
  487. {"[\\-x]", "a", false, nil},
  488. {"[]a]", "]", false, filepath.ErrBadPattern},
  489. {"[-]", "-", false, filepath.ErrBadPattern},
  490. {"[x-]", "x", false, filepath.ErrBadPattern},
  491. {"[x-]", "-", false, filepath.ErrBadPattern},
  492. {"[x-]", "z", false, filepath.ErrBadPattern},
  493. {"[-x]", "x", false, filepath.ErrBadPattern},
  494. {"[-x]", "-", false, filepath.ErrBadPattern},
  495. {"[-x]", "a", false, filepath.ErrBadPattern},
  496. {"\\", "a", false, filepath.ErrBadPattern},
  497. {"[a-b-c]", "a", false, filepath.ErrBadPattern},
  498. {"[", "a", false, filepath.ErrBadPattern},
  499. {"[^", "a", false, filepath.ErrBadPattern},
  500. {"[^bc", "a", false, filepath.ErrBadPattern},
  501. {"a[", "a", false, filepath.ErrBadPattern}, // was nil but IMO its wrong
  502. {"a[", "ab", false, filepath.ErrBadPattern},
  503. {"*x", "xxx", true, nil},
  504. }
  505. func errp(e error) string {
  506. if e == nil {
  507. return "<nil>"
  508. }
  509. return e.Error()
  510. }
  511. // TestMatch test's our version of filepath.Match, called regexpMatch.
  512. func TestMatch(t *testing.T) {
  513. for _, tt := range matchTests {
  514. pattern := tt.pattern
  515. s := tt.s
  516. if runtime.GOOS == "windows" {
  517. if strings.Index(pattern, "\\") >= 0 {
  518. // no escape allowed on windows.
  519. continue
  520. }
  521. pattern = filepath.Clean(pattern)
  522. s = filepath.Clean(s)
  523. }
  524. ok, err := regexpMatch(pattern, s)
  525. if ok != tt.match || err != tt.err {
  526. t.Fatalf("Match(%#q, %#q) = %v, %q want %v, %q", pattern, s, ok, errp(err), tt.match, errp(tt.err))
  527. }
  528. }
  529. }