idlize

Форк
0
65 строк · 2.0 Кб
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

16
import * as path from "path"
17
import * as fs from "fs"
18
import { assert } from "chai"
19

20
let logText: string = ""
21

22
export function log(msg: string) {
23
    logText = logText.concat(msg, "\n")
24
}
25

26
export function getLog(): string {
27
    return logText
28
}
29

30
export function filterDirname(text: string): string {
31
    // tsc AST on windows uses C:/foo/bar representation, but
32
    // __dirname on windows returns C:\foo\bar.
33
    const platformDirname = __dirname.replaceAll(path.sep, "/")
34
    return text.replaceAll(platformDirname, "DIRNAME")
35
}
36

37
export function getLogFiltered(): string {
38
    return filterDirname(logText)
39
}
40

41
export function resetLog() {
42
    logText = ""
43
}
44

45
export function cleanDumpDirectory() {
46
    fs.rmSync(`${__dirname}/dump}`, {recursive: true, force: true})
47
}
48

49
export function loadDump(name: string, kind: string, module: string): string|undefined {
50
    const dirname = __dirname
51
    const dumpFile = `${dirname}/${kind}/${name}_${module}.test.ts_dump`
52
    const dump = fs.readFileSync(dumpFile, 'utf8')
53
    return (dump && dump.includes('\r'))
54
        ? dump.replace(/[\r]/g, '')
55
        : dump
56
}
57

58
export function checkDump(name: string, module: string) {
59
    test(`Transformed ${name} dump matches the golden dump`, () => {
60
        const test = loadDump(name, "dump", module)
61
        const testFiltered = test ? filterDirname(test) : undefined
62
        const golden = loadDump(name, "golden", module)
63
        assert.equal(golden, testFiltered)
64
    })
65
}
66

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

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

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

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