idlize

Форк
0
55 строк · 2.1 Кб
1
/*
2
 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * you may not use this file except in compliance with the License.
5
 * You may obtain a copy of the License at
6
 *
7
 * http://www.apache.org/licenses/LICENSE-2.0
8
 *
9
 * Unless required by applicable law or agreed to in writing, software
10
 * distributed under the License is distributed on an "AS IS" BASIS,
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 * See the License for the specific language governing permissions and
13
 * limitations under the License.
14
 */
15
import * as path from "path";
16
import * as fs from "fs";
17
import { assert } from "chai";
18
let logText: string = "";
19
export function log(msg: string) {
20
    logText = logText.concat(msg, "\n");
21
}
22
export function getLog(): string {
23
    return logText;
24
}
25
export function filterDirname(text: string): string {
26
    // tsc AST on windows uses C:/foo/bar representation, but
27
    // __dirname on windows returns C:\foo\bar.
28
    const platformDirname = __dirname.replaceAll(path.sep, "/");
29
    return text.replaceAll(platformDirname, "DIRNAME");
30
}
31
export function getLogFiltered(): string {
32
    return filterDirname(logText);
33
}
34
export function resetLog() {
35
    logText = "";
36
}
37
export function cleanDumpDirectory() {
38
    fs.rmSync(`${__dirname}/dump}`, { recursive: true, force: true });
39
}
40
export function loadDump(name: string, kind: string, module: string): string | undefined {
41
    const dirname = __dirname;
42
    const dumpFile = `${dirname}/${kind}/${name}_${module}.test.ts_dump`;
43
    const dump = fs.readFileSync(dumpFile, 'utf8');
44
    return (dump && dump.includes('\r'))
45
        ? dump.replace(/[\r]/g, '')
46
        : dump;
47
}
48
export function checkDump(name: string, module: string) {
49
    test(`Transformed ${name} dump matches the golden dump`, () => {
50
        const test = loadDump(name, "dump", module);
51
        const testFiltered = test ? filterDirname(test) : undefined;
52
        const golden = loadDump(name, "golden", module);
53
        assert.equal(golden, testFiltered);
54
    });
55
}
56

57

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.