Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/entry-points.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/actions-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from "./actions-util";
import { computeAutomationID } from "./api-client";
import { EnvVar } from "./environment";
import { getRunnerLogger } from "./logging";
import { RecordingLogger, setupTests } from "./testing-utils";
import { initializeEnvironment, withTmpDir } from "./util";

Expand Down Expand Up @@ -238,7 +237,7 @@ test.serial("fixCodeQualityCategory", (t) => {
GITHUB_EVENT_NAME: "dynamic",
},
() => {
const logger = getRunnerLogger(true);
const logger = new RecordingLogger();

// Categories that should get adjusted.
t.is(fixCodeQualityCategory(logger, "/language:c#"), "/language:csharp");
Expand Down
11 changes: 5 additions & 6 deletions src/analyses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
supportedAnalysisKinds,
} from "./analyses";
import { EnvVar } from "./environment";
import { getRunnerLogger } from "./logging";
import {
createFeatures,
RecordingLogger,
Expand Down Expand Up @@ -65,7 +64,7 @@ test.serial(
.withArgs("analysis-kinds")
.returns("code-scanning,code-quality");
const result = await getAnalysisKinds(
getRunnerLogger(true),
new RecordingLogger(),
features,
true,
);
Expand Down Expand Up @@ -139,7 +138,7 @@ test.serial(
const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput");
optionalInputStub.withArgs("quality-queries").returns("code-quality");
const result = await getAnalysisKinds(
getRunnerLogger(true),
new RecordingLogger(),
features,
true,
);
Expand All @@ -155,7 +154,7 @@ test.serial(
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
requiredInputStub.withArgs("analysis-kinds").returns("no-such-thing");
await t.throwsAsync(
getAnalysisKinds(getRunnerLogger(true), features, true),
getAnalysisKinds(new RecordingLogger(), features, true),
);
},
);
Expand All @@ -181,7 +180,7 @@ for (let i = 0; i < analysisKinds.length; i++) {
.withArgs("analysis-kinds")
.returns([analysisKind, otherAnalysis].join(","));
const result = await getAnalysisKinds(
getRunnerLogger(true),
new RecordingLogger(),
features,
true,
);
Expand All @@ -199,7 +198,7 @@ for (let i = 0; i < analysisKinds.length; i++) {
.withArgs("analysis-kinds")
.returns([analysisKind, otherAnalysis].join(","));
await t.throwsAsync(
getAnalysisKinds(getRunnerLogger(true), features, true),
getAnalysisKinds(new RecordingLogger(), features, true),
{
instanceOf: ConfigurationError,
message: `${analysisKind} and ${otherAnalysis} cannot be enabled at the same time`,
Expand Down
4 changes: 2 additions & 2 deletions src/analyze.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import { defaultSuites } from "./config/db-config";
import { Feature } from "./feature-flags";
import * as gitUtils from "./git-utils";
import { BuiltInLanguage } from "./languages";
import { getRunnerLogger } from "./logging";
import {
setupTests,
setupActionsVars,
createFeatures,
createTestConfig,
RecordingLogger,
callee,
} from "./testing-utils";
import * as uploadLib from "./upload-lib";
Expand Down Expand Up @@ -195,7 +195,7 @@ test.serial("status report fields", async (t) => {
undefined,
codeql,
config,
getRunnerLogger(true),
new RecordingLogger(),
createFeatures([Feature.QaTelemetryEnabled]),
);
t.deepEqual(Object.keys(statusReport).sort(), [
Expand Down
4 changes: 2 additions & 2 deletions src/artifact-scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
scanArtifactsForTokens,
TokenType,
} from "./artifact-scanner";
import { getRunnerLogger } from "./logging";
import {
checkExpectedLogMessages,
getRecordingLogger,
LoggedMessage,
makeTestToken,
RecordingLogger,
} from "./testing-utils";

test("makeTestToken", (t) => {
Expand Down Expand Up @@ -121,7 +121,7 @@ for (const { type, value, checkPattern } of testTokens) {
}

test("scanArtifactsForTokens handles files without tokens", async (t) => {
const logger = getRunnerLogger(true);
const logger = new RecordingLogger();
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "scanner-test-"));

try {
Expand Down
5 changes: 2 additions & 3 deletions src/cli/output-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import path from "path";

import test from "ava";

import { getRunnerLogger } from "../logging";
import { setupTests } from "../testing-utils";
import { RecordingLogger, setupTests } from "../testing-utils";
import * as util from "../util";

import { getCachedCodeQlVersion } from "./output-cache";

setupTests(test);

const logger = getRunnerLogger(true);
const logger = new RecordingLogger();

test.serial(
"getCachedCodeQlVersion reuses a version persisted by an earlier step",
Expand Down
31 changes: 16 additions & 15 deletions src/codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import type { Config } from "./config-utils";
import * as defaults from "./defaults.json";
import { DocUrl } from "./doc-url";
import { BuiltInLanguage } from "./languages";
import { getRunnerLogger } from "./logging";
import { ToolsSource } from "./setup-codeql";
import {
setupTests,
Expand All @@ -34,6 +33,8 @@ import {
makeVersionInfo,
createTestConfig,
makeMacro,
getCodeQLForTesting,
RecordingLogger,
} from "./testing-utils";
import { ToolsDownloadStatusReport } from "./tools-download";
import * as util from "./util";
Expand Down Expand Up @@ -102,7 +103,7 @@ async function installIntoToolcache({
undefined, // otherLanguagePacksReason
false, // useOverlayAwareDefaultCliVersion
createFeatures([]),
getRunnerLogger(true),
new RecordingLogger(),
false,
);
}
Expand Down Expand Up @@ -140,7 +141,7 @@ function mockApiDetails(apiDetails: Required<GitHubApiDetails>) {
}

async function stubCodeql(): Promise<codeql.CodeQL> {
const codeqlObject = await codeql.getCodeQLForTesting();
const codeqlObject = await getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.17.6"));
sinon
.stub(codeqlObject, "isTracedLanguage")
Expand Down Expand Up @@ -176,7 +177,7 @@ test.serial(
undefined, // otherLanguagePacksReason
false, // useOverlayAwareDefaultCliVersion
features,
getRunnerLogger(true),
new RecordingLogger(),
false,
);

Expand Down Expand Up @@ -212,7 +213,7 @@ test.serial(
undefined, // otherLanguagePacksReason
false, // useOverlayAwareDefaultCliVersion
features,
getRunnerLogger(true),
new RecordingLogger(),
false,
);

Expand Down Expand Up @@ -252,7 +253,7 @@ test.serial(
undefined, // otherLanguagePacksReason
false, // useOverlayAwareDefaultCliVersion
features,
getRunnerLogger(true),
new RecordingLogger(),
false,
);
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
Expand Down Expand Up @@ -362,7 +363,7 @@ for (const {
undefined, // otherLanguagePacksReason
false, // useOverlayAwareDefaultCliVersion
features,
getRunnerLogger(true),
new RecordingLogger(),
false,
);
t.assert(toolcache.find("CodeQL", expectedToolcacheVersion));
Expand Down Expand Up @@ -405,7 +406,7 @@ for (const toolcacheVersion of [
undefined, // otherLanguagePacksReason
false, // useOverlayAwareDefaultCliVersion
features,
getRunnerLogger(true),
new RecordingLogger(),
false,
);
t.is(
Expand Down Expand Up @@ -450,7 +451,7 @@ test.serial(
undefined, // otherLanguagePacksReason
false, // useOverlayAwareDefaultCliVersion
features,
getRunnerLogger(true),
new RecordingLogger(),
false,
);
t.deepEqual(result.toolsVersion, "0.0.0-20200601");
Expand Down Expand Up @@ -497,7 +498,7 @@ test.serial(
undefined, // otherLanguagePacksReason
false, // useOverlayAwareDefaultCliVersion
features,
getRunnerLogger(true),
new RecordingLogger(),
false,
);
t.deepEqual(result.toolsVersion, defaults.cliVersion);
Expand Down Expand Up @@ -537,7 +538,7 @@ test.serial(
undefined, // otherLanguagePacksReason
false, // useOverlayAwareDefaultCliVersion
features,
getRunnerLogger(true),
new RecordingLogger(),
false,
);
t.deepEqual(result.toolsVersion, defaults.cliVersion);
Expand Down Expand Up @@ -579,7 +580,7 @@ test.serial(
undefined, // otherLanguagePacksReason
false, // useOverlayAwareDefaultCliVersion
features,
getRunnerLogger(true),
new RecordingLogger(),
false,
);

Expand Down Expand Up @@ -664,7 +665,7 @@ const injectedConfigMacro = makeMacro({
tempDir,
};
thisStubConfig.computedConfig = generateCodeScanningConfig(
getRunnerLogger(true),
new RecordingLogger(),
thisStubConfig.originalUserInput,
augmentationProperties,
);
Expand Down Expand Up @@ -1039,7 +1040,7 @@ test.serial("runTool summarizes autobuilder errors", async (t) => {
[2019-09-18 12:00:01] [autobuild] A non-error message
`;
stubToolRunnerConstructor(1, stderr);
const codeqlObject = await codeql.getCodeQLForTesting();
const codeqlObject = await getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.17.6"));
sinon.stub(codeqlObject, "resolveExtractor").resolves("/path/to/extractor");
// io throws because of the test CodeQL object.
Expand Down Expand Up @@ -1095,7 +1096,7 @@ test.serial("runTool recognizes fatal internal errors", async (t) => {
com.semmle.util.exception.CatastrophicError: An error occurred while evaluating ControlFlowGraph::ControlFlow::Root.isRootOf/1#dispred#f610e6ed/2@86282cc8
Severe disk cache trouble (corruption or out of space) at /home/runner/work/_temp/codeql_databases/go/db-go/default/cache/pages/28/33.pack: Failed to write item to disk`;
stubToolRunnerConstructor(1, stderr);
const codeqlObject = await codeql.getCodeQLForTesting();
const codeqlObject = await getCodeQLForTesting();
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.17.6"));
sinon.stub(codeqlObject, "resolveExtractor").resolves("/path/to/extractor");
// io throws because of the test CodeQL object.
Expand Down
16 changes: 2 additions & 14 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from "./feature-flags";
import { isAnalyzingDefaultBranch } from "./git-utils";
import { Language } from "./languages";
import { getRunnerLogger, Logger } from "./logging";
import type { Logger } from "./logging";
import { writeBaseDatabaseOidsFile, writeOverlayChangesFile } from "./overlay";
import { OverlayDatabaseMode } from "./overlay/overlay-database-mode";
import * as setupCodeql from "./setup-codeql";
Expand Down Expand Up @@ -486,18 +486,6 @@ export function createStubCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
};
}

/**
* Get a real, newly created CodeQL instance for testing. The instance refers to
* a non-existent placeholder codeql command, so tests that use this function
* should also stub the toolrunner.ToolRunner constructor.
*/
export async function getCodeQLForTesting(
cmd = "codeql-for-testing",
logger: Logger = getRunnerLogger(true),
): Promise<CodeQL> {
return getCodeQLForCmd(logger, cmd, false);
}

/**
* Return a CodeQL object for CodeQL CLI access.
*
Expand All @@ -506,7 +494,7 @@ export async function getCodeQLForTesting(
* version requirement. Must be set to true outside tests.
* @returns A new CodeQL object
*/
async function getCodeQLForCmd(
export async function getCodeQLForCmd(
logger: Logger,
cmd: string,
checkVersion: boolean,
Expand Down
Loading
Loading