(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func TestDiffTreeToTree(t *testing.T) { |
| 69 | t.Parallel() |
| 70 | repo := createTestRepo(t) |
| 71 | defer cleanupTestRepo(t, repo) |
| 72 | |
| 73 | originalTree, newTree := createTestTrees(t, repo) |
| 74 | |
| 75 | callbackInvoked := false |
| 76 | opts := DiffOptions{ |
| 77 | NotifyCallback: func(diffSoFar *Diff, delta DiffDelta, matchedPathSpec string) error { |
| 78 | callbackInvoked = true |
| 79 | return nil |
| 80 | }, |
| 81 | OldPrefix: "x1/", |
| 82 | NewPrefix: "y1/", |
| 83 | } |
| 84 | |
| 85 | diff, err := repo.DiffTreeToTree(originalTree, newTree, &opts) |
| 86 | checkFatal(t, err) |
| 87 | if !callbackInvoked { |
| 88 | t.Fatal("callback not invoked") |
| 89 | } |
| 90 | |
| 91 | if diff == nil { |
| 92 | t.Fatal("no diff returned") |
| 93 | } |
| 94 | |
| 95 | files := make([]string, 0) |
| 96 | hunks := make([]DiffHunk, 0) |
| 97 | lines := make([]DiffLine, 0) |
| 98 | patches := make([]string, 0) |
| 99 | err = diff.ForEach(func(file DiffDelta, progress float64) (DiffForEachHunkCallback, error) { |
| 100 | patch, err := diff.Patch(len(patches)) |
| 101 | if err != nil { |
| 102 | return nil, err |
| 103 | } |
| 104 | defer patch.Free() |
| 105 | patchStr, err := patch.String() |
| 106 | if err != nil { |
| 107 | return nil, err |
| 108 | } |
| 109 | patches = append(patches, patchStr) |
| 110 | |
| 111 | files = append(files, file.OldFile.Path) |
| 112 | return func(hunk DiffHunk) (DiffForEachLineCallback, error) { |
| 113 | hunks = append(hunks, hunk) |
| 114 | return func(line DiffLine) error { |
| 115 | lines = append(lines, line) |
| 116 | return nil |
| 117 | }, nil |
| 118 | }, nil |
| 119 | }, DiffDetailLines) |
| 120 | |
| 121 | checkFatal(t, err) |
| 122 | |
| 123 | if len(files) != 1 { |
| 124 | t.Fatal("Incorrect number of files in diff") |
| 125 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…