Files
yoga/gentest/gentest-validate.ts
Nick Gerleman f023702f75 Make gentest-validate more graceful of different file organization (#1672)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1672

This reworks `gentest-validate`, to be more resilient to changes like D58307002, which cause [validation failures](https://github.com/facebook/yoga/actions/runs/9653979292/job/26627690870) on the intrinsic sizing testing change, which currently causes failure due to the file traversal code not handling the presence of directories.

Differential Revision: D58987293
2024-06-24 21:47:01 -07:00

48 lines
1.2 KiB
TypeScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import * as fs from 'node:fs/promises';
import {dirname} from 'path';
import {fileURLToPath} from 'url';
import signedsource from 'signedsource';
import {glob} from 'glob';
const yogaRootDir = dirname(dirname(fileURLToPath(import.meta.url)));
const signedSourcePattern = new RegExp(
`${'@'}generated (?:SignedSource<<([a-f0-9]{32})>>)`,
);
const filesToValidate = await glob(
[
'tests/generated/**/*.{h,cpp}',
'javascript/tests/generated/**/*.test.ts',
'java/tests/com/facebook/yoga/**/*.java',
],
{
cwd: yogaRootDir,
},
);
console.log(`Found ${filesToValidate.length} files to validate`);
for (const file of filesToValidate) {
const content = await fs.readFile(`${yogaRootDir}/${file}`, 'utf8');
if (signedSourcePattern.test(content)) {
console.log(`Checking ${file}`);
const validSignature = signedsource.verifySignature(content);
if (!validSignature) {
console.error(`Invalid signature "${file}"`);
process.exitCode = 1;
}
} else {
console.log(`Skipped ${file}`);
}
}