본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    라이브러리

    std.test.assertGolden

    Compares actual text with a golden-file path.

    assertGolden(path: string, actual: string) -> ()
    수신자
    해당 없음
    최소 인자 수
    2
    최대 인자 수
    2

    Declaration and parameters

    링크

    사용 조건

    기본 포함 · 미정

    Import std.test in language mode 5.21.

    The current compiler selects std/test.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.

    수신자

    매개변수 제약

    assertGolden(path, actual) accepts two strings. Read the existing file as UTF-8 and compare the entire decoded text with actual. UTF-8 validity and text preservation follow UTF-8 decoding. Equal text returns unit without printing.

    Resolve the path using the same host path and read permission rules as filesystem text reads. For an ordinary installed CLI program, a relative path starts at the process working directory. The source file directory does not replace that directory.

    Comparison preserves every scalar and line ending. CRLF and LF differ. A final newline, a byte order mark, Unicode spelling, and an empty file remain significant. Invalid UTF-8 is a read failure.

    Evaluate the path expression and then the actual expression, once each, before reading the file. Open and read the expected text once. Release any opened resource before returning or reporting a read or comparison failure.

    The assertion needs read access. It never creates a missing golden file, replaces its contents, or enables an update mode. Write a chosen expected result explicitly through the filesystem API.

    Missing files, directories that cannot be read as text, permission denial, and invalid UTF-8 raise TPZ4007 at the assertion call. File failures identify the path and whether opening or reading failed. The host detail explains the cause and may vary by platform.

    The file failure messages have these forms.

    assertGolden failed: could not open `{path}`: {detail}
    assertGolden failed: could not read `{path}`: {detail}

    Unequal text raises TPZ4007 and stops the current test before its next statement. The message has this form.

    assertGolden failed: `{path}` did not match actual output

    Earlier argument effects remain visible after failure. Reading does not promise a snapshot across concurrent host writes. Keep the expected file unchanged while the assertion reads it.

    결과

    The declared result type is ().

    효과

    실패

    Result and effects

    링크

    Compare actual with existing UTF-8 file text exactly. A mismatch or file access failure raises TPZ4007. The assertion never updates the expected file.

    Related entries

    링크

    std.test →

    Compare existing golden text without updating it

    링크
    규칙topaz.stdlib.contract.test-golden-text.rule

    Compare existing golden text without updating it

    assertGolden(path, actual) accepts two strings. Read the existing file as UTF-8 and compare the entire decoded text with actual. UTF-8 validity and text preservation follow UTF-8 decoding. Equal text returns unit without printing.

    Resolve the path using the same host path and read permission rules as filesystem text reads. For an ordinary installed CLI program, a relative path starts at the process working directory. The source file directory does not replace that directory.

    Comparison preserves every scalar and line ending. CRLF and LF differ. A final newline, a byte order mark, Unicode spelling, and an empty file remain significant. Invalid UTF-8 is a read failure.

    Evaluate the path expression and then the actual expression, once each, before reading the file. Open and read the expected text once. Release any opened resource before returning or reporting a read or comparison failure.

    The assertion needs read access. It never creates a missing golden file, replaces its contents, or enables an update mode. Write a chosen expected result explicitly through the filesystem API.

    Missing files, directories that cannot be read as text, permission denial, and invalid UTF-8 raise TPZ4007 at the assertion call. File failures identify the path and whether opening or reading failed. The host detail explains the cause and may vary by platform.

    The file failure messages have these forms.

    assertGolden failed: could not open `{path}`: {detail}
    assertGolden failed: could not read `{path}`: {detail}

    Unequal text raises TPZ4007 and stops the current test before its next statement. The message has this form.

    assertGolden failed: `{path}` did not match actual output

    Earlier argument effects remain visible after failure. Reading does not promise a snapshot across concurrent host writes. Keep the expected file unchanged while the assertion reads it.

    이유

    An existing expected file gives the test an independent reference. Exact comparison preserves document bytes that matter to generated text, and explicit writes keep failed tests from replacing their own expectations.

    Match exact line endings and an empty golden file

    링크
    main.tpzMatch exact line endings and an empty golden file플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. test.assertGolden("expected.txt", "alpha\r\nβ\n")
    4. test.assertGolden("empty.txt", "")
    5. io.writeLine("golden text matched")
    기대 출력종료 코드 0
    golden text matched
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    expected.txtMatch exact line endings and an empty golden file플레이그라운드 열기 →
    1. alpha
    2. β
    empty.txtMatch exact line endings and an empty golden file플레이그라운드 열기 →
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. golden text matched

    Resolve a golden path from the working directory

    링크
    nested/main.tpzResolve a golden path from the working directory플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. test.assertGolden("expected.txt", "working directory\n")
    4. io.writeLine("working directory matched")
    기대 출력종료 코드 0
    working directory matched
    
    $ topaz run nested/main.tpz · 대상 제품 5.21.3
    expected.txtResolve a golden path from the working directory플레이그라운드 열기 →
    1. working directory
    nested/expected.txtResolve a golden path from the working directory플레이그라운드 열기 →
    1. source directory
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. working directory matched

    Fail when the final newline is missing from actual text

    링크
    main.tpzFail when the final newline is missing from actual text플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. io.writeLine("before")
    4. test.assertGolden("expected.txt", "line")
    5. io.writeLine("after")
    기대 출력0이 아닌 종료 코드
    before
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    expected.txtFail when the final newline is missing from actual text플레이그라운드 열기 →
    1. line
    기대 결과

    기대 결과

    거절 단계 run. 종료 코드가 0이 아닙니다.

    • TPZ4007 →

      stdlib-assert-golden-mismatch at main.tpz:5:1

    기대 표준 출력
    1. before

    Fail instead of creating a missing golden file

    링크
    main.tpzFail instead of creating a missing golden file플레이그라운드 열기 →
    1. import std.test
    2. import std.io
    3. io.writeLine("before")
    4. test.assertGolden("missing.txt", "new text")
    5. io.writeLine("after")
    기대 출력0이 아닌 종료 코드
    before
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 run. 종료 코드가 0이 아닙니다.

    • TPZ4007 →

      stdlib-assert-golden-missing at main.tpz:5:1

    기대 표준 출력
    1. before

    Fail instead of replacing invalid UTF-8 with a character

    링크
    main.tpzFail instead of replacing invalid UTF-8 with a character플레이그라운드 열기 →
    1. import std.bytes { Bytes }
    2. import std.fs
    3. import std.test
    4. import std.io
    5. let bytes = test.assertOk(Bytes.fromArray([255]))
    6. test.assertOk(fs.writeBytes("invalid.txt", bytes))
    7. io.writeLine("before")
    8. test.assertGolden("invalid.txt", "�")
    9. io.writeLine("after")
    기대 출력0이 아닌 종료 코드
    before
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 run. 종료 코드가 0이 아닙니다.

    • TPZ4007 →

      stdlib-assert-golden-invalid-utf8 at main.tpz:9:1

    기대 표준 출력
    1. before

    Diagnostics

    링크

    Assertion failed →

    메뉴

    다운로드 →