Skip to content

Commit cc17bed

Browse files
committed
Move diff-range computation tests
1 parent 91ec0ed commit cc17bed

File tree

2 files changed

+202
-201
lines changed

2 files changed

+202
-201
lines changed

src/analyze.test.ts

Lines changed: 0 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as path from "path";
44
import test from "ava";
55
import * as sinon from "sinon";
66

7-
import * as actionsUtil from "./actions-util";
87
import { CodeQuality, CodeScanning } from "./analyses";
98
import {
109
runQueries,
@@ -13,7 +12,6 @@ import {
1312
addSarifExtension,
1413
} from "./analyze";
1514
import { createStubCodeQL } from "./codeql";
16-
import { exportedForTesting } from "./diff-informed-analysis-utils";
1715
import { Feature } from "./feature-flags";
1816
import { KnownLanguage } from "./languages";
1917
import { getRunnerLogger } from "./logging";
@@ -131,204 +129,6 @@ test("status report fields", async (t) => {
131129
});
132130
});
133131

134-
function runGetDiffRanges(changes: number, patch: string[] | undefined): any {
135-
sinon
136-
.stub(actionsUtil, "getRequiredInput")
137-
.withArgs("checkout_path")
138-
.returns("/checkout/path");
139-
return exportedForTesting.getDiffRanges(
140-
{
141-
filename: "test.txt",
142-
changes,
143-
patch: patch?.join("\n"),
144-
},
145-
getRunnerLogger(true),
146-
);
147-
}
148-
149-
test("getDiffRanges: file unchanged", async (t) => {
150-
const diffRanges = runGetDiffRanges(0, undefined);
151-
t.deepEqual(diffRanges, []);
152-
});
153-
154-
test("getDiffRanges: file diff too large", async (t) => {
155-
const diffRanges = runGetDiffRanges(1000000, undefined);
156-
t.deepEqual(diffRanges, [
157-
{
158-
path: "/checkout/path/test.txt",
159-
startLine: 0,
160-
endLine: 0,
161-
},
162-
]);
163-
});
164-
165-
test("getDiffRanges: diff thunk with single addition range", async (t) => {
166-
const diffRanges = runGetDiffRanges(2, [
167-
"@@ -30,6 +50,8 @@",
168-
" a",
169-
" b",
170-
" c",
171-
"+1",
172-
"+2",
173-
" d",
174-
" e",
175-
" f",
176-
]);
177-
t.deepEqual(diffRanges, [
178-
{
179-
path: "/checkout/path/test.txt",
180-
startLine: 53,
181-
endLine: 54,
182-
},
183-
]);
184-
});
185-
186-
test("getDiffRanges: diff thunk with single deletion range", async (t) => {
187-
const diffRanges = runGetDiffRanges(2, [
188-
"@@ -30,8 +50,6 @@",
189-
" a",
190-
" b",
191-
" c",
192-
"-1",
193-
"-2",
194-
" d",
195-
" e",
196-
" f",
197-
]);
198-
t.deepEqual(diffRanges, []);
199-
});
200-
201-
test("getDiffRanges: diff thunk with single update range", async (t) => {
202-
const diffRanges = runGetDiffRanges(2, [
203-
"@@ -30,7 +50,7 @@",
204-
" a",
205-
" b",
206-
" c",
207-
"-1",
208-
"+2",
209-
" d",
210-
" e",
211-
" f",
212-
]);
213-
t.deepEqual(diffRanges, [
214-
{
215-
path: "/checkout/path/test.txt",
216-
startLine: 53,
217-
endLine: 53,
218-
},
219-
]);
220-
});
221-
222-
test("getDiffRanges: diff thunk with addition ranges", async (t) => {
223-
const diffRanges = runGetDiffRanges(2, [
224-
"@@ -30,7 +50,9 @@",
225-
" a",
226-
" b",
227-
" c",
228-
"+1",
229-
" c",
230-
"+2",
231-
" d",
232-
" e",
233-
" f",
234-
]);
235-
t.deepEqual(diffRanges, [
236-
{
237-
path: "/checkout/path/test.txt",
238-
startLine: 53,
239-
endLine: 53,
240-
},
241-
{
242-
path: "/checkout/path/test.txt",
243-
startLine: 55,
244-
endLine: 55,
245-
},
246-
]);
247-
});
248-
249-
test("getDiffRanges: diff thunk with mixed ranges", async (t) => {
250-
const diffRanges = runGetDiffRanges(2, [
251-
"@@ -30,7 +50,7 @@",
252-
" a",
253-
" b",
254-
" c",
255-
"-1",
256-
" d",
257-
"-2",
258-
"+3",
259-
" e",
260-
" f",
261-
"+4",
262-
"+5",
263-
" g",
264-
" h",
265-
" i",
266-
]);
267-
t.deepEqual(diffRanges, [
268-
{
269-
path: "/checkout/path/test.txt",
270-
startLine: 54,
271-
endLine: 54,
272-
},
273-
{
274-
path: "/checkout/path/test.txt",
275-
startLine: 57,
276-
endLine: 58,
277-
},
278-
]);
279-
});
280-
281-
test("getDiffRanges: multiple diff thunks", async (t) => {
282-
const diffRanges = runGetDiffRanges(2, [
283-
"@@ -30,6 +50,8 @@",
284-
" a",
285-
" b",
286-
" c",
287-
"+1",
288-
"+2",
289-
" d",
290-
" e",
291-
" f",
292-
"@@ -130,6 +150,8 @@",
293-
" a",
294-
" b",
295-
" c",
296-
"+1",
297-
"+2",
298-
" d",
299-
" e",
300-
" f",
301-
]);
302-
t.deepEqual(diffRanges, [
303-
{
304-
path: "/checkout/path/test.txt",
305-
startLine: 53,
306-
endLine: 54,
307-
},
308-
{
309-
path: "/checkout/path/test.txt",
310-
startLine: 153,
311-
endLine: 154,
312-
},
313-
]);
314-
});
315-
316-
test("getDiffRanges: no diff context lines", async (t) => {
317-
const diffRanges = runGetDiffRanges(2, ["@@ -30 +50,2 @@", "+1", "+2"]);
318-
t.deepEqual(diffRanges, [
319-
{
320-
path: "/checkout/path/test.txt",
321-
startLine: 50,
322-
endLine: 51,
323-
},
324-
]);
325-
});
326-
327-
test("getDiffRanges: malformed thunk header", async (t) => {
328-
const diffRanges = runGetDiffRanges(2, ["@@ 30 +50,2 @@", "+1", "+2"]);
329-
t.deepEqual(diffRanges, undefined);
330-
});
331-
332132
test("resolveQuerySuiteAlias", (t) => {
333133
// default query suite names should resolve to something language-specific ending in `.qls`.
334134
for (const suite of defaultSuites) {

0 commit comments

Comments
 (0)