Skip to content

Commit

Permalink
minor changes to test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanBoltonMN committed Mar 9, 2023
1 parent 3aed503 commit 3a93014
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
14 changes: 6 additions & 8 deletions src/test/scripts/createBenchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as path from "path";

import { ArrayUtils, DefaultSettings, Settings, Task, TaskUtils } from "../../powerquery-parser";
import { BenchmarkTraceManager, NoOpTraceManagerInstance } from "../../powerquery-parser/common/trace";
import { TestConstants, TestFileUtils, TestResourceUtils } from "../testUtils";
import { TestConstants, TestFileUtils, TestResourceUtils, TestUtils } from "../testUtils";
import { TestResource } from "../testUtils/resourceUtils";

const BenchmarkDirectory: string = path.join(__dirname, "benchmark");
Expand Down Expand Up @@ -49,10 +49,6 @@ function jsonStringify(value: unknown): string {
return JSON.stringify(value, undefined, 4);
}

function zFill(currentValue: number, upperBound: number): string {
return currentValue.toString().padStart(Math.ceil(Math.log10(upperBound + 1)), "0");
}

function createParserSummaryDurations(
resourceSummaries: ReadonlyArray<ResourceSummary>,
filterOutOutliers: boolean,
Expand Down Expand Up @@ -99,15 +95,17 @@ async function main(): Promise<void> {
for (let resourceIndex: number = 0; resourceIndex < numResources; resourceIndex += 1) {
const { fileContents, filePath, resourceName }: TestResource = ArrayUtils.assertGet(resources, resourceIndex);

console.log(`Starting resource ${zFill(resourceIndex + 1, numResources)} out of ${numResources}: ${filePath}`);
console.log(
`Starting resource ${TestUtils.zFill(resourceIndex + 1, numResources)} out of ${numResources}: ${filePath}`,
);

for (const [parserName, parser] of TestConstants.ParserByParserName.entries()) {
let failedToParse: boolean = false;
const durations: number[] = [];

for (let iteration: number = 0; iteration < IterationsPerFile; iteration += 1) {
console.log(
`\tIteration ${zFill(
`\tIteration ${TestUtils.zFill(
iteration + 1,
IterationsPerFile,
)} out of ${IterationsPerFile} using ${parserName}`,
Expand Down Expand Up @@ -144,7 +142,7 @@ async function main(): Promise<void> {
"traces",
parserName,
resourceName,
`iteration_${zFill(iteration, IterationsPerFile)}.log`,
`iteration_${TestUtils.zFill(iteration, IterationsPerFile)}.log`,
),
contents,
);
Expand Down
17 changes: 13 additions & 4 deletions src/test/scripts/createNodeDump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import * as path from "path";

import { Assert, DefaultSettings, Settings, Task, TaskUtils } from "../../powerquery-parser";
import { ArrayUtils, Assert, DefaultSettings, Settings, Task, TaskUtils } from "../../powerquery-parser";
import { Ast, AstUtils } from "../../powerquery-parser/language";
import {
NodeIdMap,
Expand All @@ -13,7 +13,7 @@ import {
XorNodeKind,
XorNodeUtils,
} from "../../powerquery-parser/parser";
import { TestConstants, TestFileUtils, TestResourceUtils } from "../testUtils";
import { TestConstants, TestFileUtils, TestResourceUtils, TestUtils } from "../testUtils";
import { TestResource } from "../testUtils/resourceUtils";

const OutputDirectory: string = path.join(__dirname, "nodeDump");
Expand Down Expand Up @@ -45,8 +45,17 @@ async function main(): Promise<void> {
parser,
};

for (const resource of resources) {
console.log(`Starting ${resource.filePath} using ${parserName}`);
const numResources: number = resources.length;

for (let index: number = 0; index < numResources; index += 1) {
const resource: TestResource = ArrayUtils.assertGet(resources, index);

console.log(
`Starting ${resource.filePath} using ${parserName} (${TestUtils.zFill(
index + 1,
numResources,
)} out of ${numResources})`,
);

// eslint-disable-next-line no-await-in-loop
const nodeDump: TNodeDump = await lexParseDump(settings, resource);
Expand Down
1 change: 1 addition & 0 deletions src/test/testUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * as TestAssertUtils from "./assertUtils";
export * as TestConstants from "./testConstants";
export * as TestFileUtils from "./fileUtils";
export * as TestResourceUtils from "./resourceUtils";
export * as TestUtils from "./testHelperUtils";
6 changes: 6 additions & 0 deletions src/test/testUtils/testHelperUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export function zFill(currentValue: number, upperBound: number): string {
return currentValue.toString().padStart(Math.ceil(Math.log10(upperBound + 1)), "0");
}

0 comments on commit 3a93014

Please sign in to comment.