Status Checks

buildtest will record state of each test which can be PASS or FAIL. By default a 0 exit code is PASS and anything else is a FAIL. The status property can be used to determine how test will report its state. Currently, we can match state based on the following:

returncode: Return Code Matching

buildtest can report PASS/FAIL based on returncode, by default a 0 exit code is PASS and everything else is FAIL. The returncode can be a list of exit codes to match. In this example we have four tests called exit1_fail, exit1_pass, returncode_list_mismatch and returncode_int_match. We expect exit1_fail and returncode_mismatch to FAIL while exit1_pass and returncode_int_match will PASS.

buildspecs:

  exit1_fail:
    executor: generic.local.bash
    type: script
    description: exit 1 by default is FAIL
    tags: [tutorials, fail]
    run: exit 1

  exit1_pass:
    executor: generic.local.bash
    type: script
    description: report exit 1 as PASS
    run: exit 1
    tags: [tutorials, pass]
    status:
      returncode: [1]

  returncode_list_mismatch:
    executor: generic.local.bash
    type: script
    description: exit 2 failed since it failed to match returncode 1
    run: exit 2
    tags: [tutorials, fail]
    status:
      returncode: [1, 3]

  returncode_int_match:
    executor: generic.local.bash
    type: script
    description: exit 128 matches returncode 128
    run: exit 128
    tags: [tutorials, pass]
    status:
      returncode: 128

Let’s build this test and pay close attention to the status column in output.

buildtest build -b tutorials/test_status/pass_returncode.yml
$ buildtest build -b tutorials/test_status/pass_returncode.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:11                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/pass_returncode.yml                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/pass_returncode.yml: VALID
Total builder objects created: 4
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ exit1_fa │ script │ generic. │ None     │ None  │ None  │ exit 1   │ /home/d │
│ il/4d6ae │        │ local.ba │          │       │       │ by       │ ocs/che │
│ ecd      │        │ sh       │          │       │       │ default  │ ckouts/ │
│          │        │          │          │       │       │ is FAIL  │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ pass_re │
│          │        │          │          │       │       │          │ turncod │
│          │        │          │          │       │       │          │ e.yml   │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ exit1_pa │ script │ generic. │ None     │ None  │ None  │ report   │ /home/d │
│ ss/c9b9d │        │ local.ba │          │       │       │ exit 1   │ ocs/che │
│ 708      │        │ sh       │          │       │       │ as PASS  │ ckouts/ │
│          │        │          │          │       │       │          │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ pass_re │
│          │        │          │          │       │       │          │ turncod │
│          │        │          │          │       │       │          │ e.yml   │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ returnco │ script │ generic. │ None     │ None  │ None  │ exit 2   │ /home/d │
│ de_list_ │        │ local.ba │          │       │       │ failed   │ ocs/che │
│ mismatch │        │ sh       │          │       │       │ since it │ ckouts/ │
│ /f4ce87e │        │          │          │       │       │ failed   │ readthe │
│ 0        │        │          │          │       │       │ to match │ docs.or │
│          │        │          │          │       │       │ returnco │ g/user_ │
│          │        │          │          │       │       │ de 1     │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ pass_re │
│          │        │          │          │       │       │          │ turncod │
│          │        │          │          │       │       │          │ e.yml   │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ returnco │ script │ generic. │ None     │ None  │ None  │ exit 128 │ /home/d │
│ de_int_m │        │ local.ba │          │       │       │ matches  │ ocs/che │
│ atch/dc8 │        │ sh       │          │       │       │ returnco │ ckouts/ │
│ 4b05a    │        │          │          │       │       │ de 128   │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ pass_re │
│          │        │          │          │       │       │          │ turncod │
│          │        │          │          │       │       │          │ e.yml   │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
exit1_fail/4d6aeecd: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/exit1_fail/4d6aeecd
exit1_pass/c9b9d708: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/exit1_pass/c9b9d708
returncode_list_mismatch/f4ce87e0: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/returncode_list_mismatch/f4ce87e0
returncode_int_match/dc84b05a: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/returncode_int_match/dc84b05a
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
exit1_fail/4d6aeecd does not have any dependencies adding test to queue
exit1_pass/c9b9d708 does not have any dependencies adding test to queue
returncode_list_mismatch/f4ce87e0 does not have any dependencies adding test to queue
returncode_int_match/dc84b05a does not have any dependencies adding test to queue
      Builders Eligible to Run       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ exit1_fail/4d6aeecd               │
│ exit1_pass/c9b9d708               │
│ returncode_list_mismatch/f4ce87e0 │
│ returncode_int_match/dc84b05a     │
└───────────────────────────────────┘
exit1_fail/4d6aeecd: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/exit1_fail/4d6aeecd/stage
exit1_fail/4d6aeecd: Running Test via command: bash exit1_fail_build.sh
exit1_fail/4d6aeecd: failed to submit job with returncode: 1
──────────────────── Error Message for exit1_fail/4d6aeecd ─────────────────────

exit1_fail/4d6aeecd: Detected failure in running test, will attempt to retry test: 1 times
exit1_fail/4d6aeecd: Run - 1/1
exit1_fail/4d6aeecd: Running Test via command: bash exit1_fail_build.sh
exit1_fail/4d6aeecd: failed to submit job with returncode: 1
exit1_fail/4d6aeecd: Test completed in 0.01417 seconds with returncode: 1
exit1_fail/4d6aeecd: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/exit1_fail/4d6aeecd/exit1_fail.out
exit1_fail/4d6aeecd: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/exit1_fail/4d6aeecd/exit1_fail.err
exit1_pass/c9b9d708: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/exit1_pass/c9b9d708/stage
exit1_pass/c9b9d708: Running Test via command: bash exit1_pass_build.sh
exit1_pass/c9b9d708: failed to submit job with returncode: 1
──────────────────── Error Message for exit1_pass/c9b9d708 ─────────────────────

exit1_pass/c9b9d708: Detected failure in running test, will attempt to retry test: 1 times
exit1_pass/c9b9d708: Run - 1/1
exit1_pass/c9b9d708: Running Test via command: bash exit1_pass_build.sh
exit1_pass/c9b9d708: failed to submit job with returncode: 1
exit1_pass/c9b9d708: Test completed in 0.013611 seconds with returncode: 1
exit1_pass/c9b9d708: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/exit1_pass/c9b9d708/exit1_pass.out
exit1_pass/c9b9d708: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/exit1_pass/c9b9d708/exit1_pass.err
exit1_pass/c9b9d708: Checking returncode - 1 is matched in list [1]
returncode_list_mismatch/f4ce87e0: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/returncode_list_mismatch/f4ce87e0/stage
returncode_list_mismatch/f4ce87e0: Running Test via command: bash returncode_list_mismatch_build.sh
returncode_list_mismatch/f4ce87e0: failed to submit job with returncode: 2
───────────── Error Message for returncode_list_mismatch/f4ce87e0 ──────────────

returncode_list_mismatch/f4ce87e0: Detected failure in running test, will attempt to retry test: 1 times
returncode_list_mismatch/f4ce87e0: Run - 1/1
returncode_list_mismatch/f4ce87e0: Running Test via command: bash returncode_list_mismatch_build.sh
returncode_list_mismatch/f4ce87e0: failed to submit job with returncode: 2
returncode_list_mismatch/f4ce87e0: Test completed in 0.013947 seconds with returncode: 2
returncode_list_mismatch/f4ce87e0: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/returncode_list_mismatch/f4ce87e0/returncode_list_mismatch.out
returncode_list_mismatch/f4ce87e0: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/returncode_list_mismatch/f4ce87e0/returncode_list_mismatch.err
returncode_list_mismatch/f4ce87e0: Checking returncode - 2 is matched in list [1, 3]
returncode_int_match/dc84b05a: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/returncode_int_match/dc84b05a/stage
returncode_int_match/dc84b05a: Running Test via command: bash returncode_int_match_build.sh
returncode_int_match/dc84b05a: failed to submit job with returncode: 128
─────────────── Error Message for returncode_int_match/dc84b05a ────────────────

returncode_int_match/dc84b05a: Detected failure in running test, will attempt to retry test: 1 times
returncode_int_match/dc84b05a: Run - 1/1
returncode_int_match/dc84b05a: Running Test via command: bash returncode_int_match_build.sh
returncode_int_match/dc84b05a: failed to submit job with returncode: 128
returncode_int_match/dc84b05a: Test completed in 0.01379 seconds with returncode: 128
returncode_int_match/dc84b05a: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/returncode_int_match/dc84b05a/returncode_int_match.out
returncode_int_match/dc84b05a: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/pass_returncode/returncode_int_match/dc84b05a/returncode_int_match.err
returncode_int_match/dc84b05a: Checking returncode - 128 is matched in list [128]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ returncode_int_match/dc │ generic.local.bash │ PASS   │ 128        │ 0.014   │
│ 84b05a                  │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ exit1_fail/4d6aeecd     │ generic.local.bash │ FAIL   │ 1          │ 0.014   │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ returncode_list_mismatc │ generic.local.bash │ FAIL   │ 2          │ 0.014   │
│ h/f4ce87e0              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ exit1_pass/c9b9d708     │ generic.local.bash │ PASS   │ 1          │ 0.014   │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 2/4 Percentage: 50.000%
Failed Tests: 2/4 Percentage: 50.000%


Adding 4 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_dce5ou_0.log

The returncode field can be an integer or list of integers but it may not accept duplicate values. If you specify a list of exit codes, buildtest will check actual returncode with list of expected returncodes specified by returncode field.

Shown below are examples of invalid returncodes:

# empty list is not allowed
returncode: []

# floating point is not accepted in list
returncode: [1, 1.5]

# floating point not accepted
returncode: 1.5

# duplicates are not allowed
returncode: [1, 2, 5, 5]

regex: Regular Expression on stdout/stderr

buildtest can configure PASS/FAIL of test based on regular expression on output or error file. This can be useful if you are expecting a certain output from the test as pose to returncode check.

In this example we introduce, the regex field which is part of status that expects a regular expression via exp. The stream property must be stdout or stderr which indicates buildtest will read output or error file and apply regular expression. If there is a match, buildtest will record the test state as PASS otherwise it will be a FAIL. In this example, we have four tests that will apply two regular expression on output file and two regular expression on error file.

buildspecs:
  status_regex_stdout_pass:
    executor: generic.local.bash
    type: script
    tags: [system]
    description: Pass test based on regular expression
    run: echo "PASS"
    status:
      regex:
        stream: stdout
        exp: "^(PASS)$"

  status_regex_stdout_fail:
    executor: generic.local.bash
    type: script
    tags: [system]
    description: Pass test based on regular expression
    run: echo "FAIL"
    status:
      regex:
        stream: stdout
        exp: "^(123FAIL)$"

  status_regex_stderr_pass:
    executor: generic.local.bash
    type: script
    tags: [system]
    description: Pass test based on regular expression
    run: echo "PASS" 1>&2
    status:
      regex:
        stream: stderr
        exp: '^(PASS)$'

  status_regex_stderr_fail:
    executor: generic.local.bash
    type: script
    tags: [system]
    description: Pass test based on regular expression
    run: echo "FAIL" 1>&2
    status:
      regex:
        stream: stderr
        exp: "^(123FAIL)$"

Now if we run this test, we will see first test will pass while second one will fail even though the returncode is a 0. Take a close look at the status property

buildtest build -b tutorials/test_status/status_regex.yml
$ buildtest build -b tutorials/test_status/status_regex.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:11                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/status_regex.yml                                       ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/status_regex.yml: VALID
Total builder objects created: 4
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ status_r │ script │ generic. │ None     │ None  │ None  │ Pass     │ /home/d │
│ egex_std │        │ local.ba │          │       │       │ test     │ ocs/che │
│ out_pass │        │ sh       │          │       │       │ based on │ ckouts/ │
│ /ecffee6 │        │          │          │       │       │ regular  │ readthe │
│ e        │        │          │          │       │       │ expressi │ docs.or │
│          │        │          │          │       │       │ on       │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ status_ │
│          │        │          │          │       │       │          │ regex.y │
│          │        │          │          │       │       │          │ ml      │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ status_r │ script │ generic. │ None     │ None  │ None  │ Pass     │ /home/d │
│ egex_std │        │ local.ba │          │       │       │ test     │ ocs/che │
│ out_fail │        │ sh       │          │       │       │ based on │ ckouts/ │
│ /f59731b │        │          │          │       │       │ regular  │ readthe │
│ a        │        │          │          │       │       │ expressi │ docs.or │
│          │        │          │          │       │       │ on       │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ status_ │
│          │        │          │          │       │       │          │ regex.y │
│          │        │          │          │       │       │          │ ml      │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ status_r │ script │ generic. │ None     │ None  │ None  │ Pass     │ /home/d │
│ egex_std │        │ local.ba │          │       │       │ test     │ ocs/che │
│ err_pass │        │ sh       │          │       │       │ based on │ ckouts/ │
│ /43baae1 │        │          │          │       │       │ regular  │ readthe │
│ 6        │        │          │          │       │       │ expressi │ docs.or │
│          │        │          │          │       │       │ on       │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ status_ │
│          │        │          │          │       │       │          │ regex.y │
│          │        │          │          │       │       │          │ ml      │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ status_r │ script │ generic. │ None     │ None  │ None  │ Pass     │ /home/d │
│ egex_std │        │ local.ba │          │       │       │ test     │ ocs/che │
│ err_fail │        │ sh       │          │       │       │ based on │ ckouts/ │
│ /d78f577 │        │          │          │       │       │ regular  │ readthe │
│ f        │        │          │          │       │       │ expressi │ docs.or │
│          │        │          │          │       │       │ on       │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ status_ │
│          │        │          │          │       │       │          │ regex.y │
│          │        │          │          │       │       │          │ ml      │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
status_regex_stdout_pass/ecffee6e: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stdout_pass/ecffee6e
status_regex_stdout_fail/f59731ba: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stdout_fail/f59731ba
status_regex_stderr_pass/43baae16: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stderr_pass/43baae16
status_regex_stderr_fail/d78f577f: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stderr_fail/d78f577f
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
status_regex_stderr_pass/43baae16 does not have any dependencies adding test to queue
status_regex_stdout_fail/f59731ba does not have any dependencies adding test to queue
status_regex_stderr_fail/d78f577f does not have any dependencies adding test to queue
status_regex_stdout_pass/ecffee6e does not have any dependencies adding test to queue
      Builders Eligible to Run       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ status_regex_stderr_pass/43baae16 │
│ status_regex_stdout_fail/f59731ba │
│ status_regex_stderr_fail/d78f577f │
│ status_regex_stdout_pass/ecffee6e │
└───────────────────────────────────┘
status_regex_stderr_pass/43baae16: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stderr_pass/43baae16/stage
status_regex_stderr_pass/43baae16: Running Test via command: bash status_regex_stderr_pass_build.sh
status_regex_stderr_pass/43baae16: Test completed in 0.005958 seconds with returncode: 0
status_regex_stderr_pass/43baae16: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stderr_pass/43baae16/status_regex_stderr_pass.out
status_regex_stderr_pass/43baae16: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stderr_pass/43baae16/status_regex_stderr_pass.err
status_regex_stderr_pass/43baae16: performing regular expression - '^(PASS)$' on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stderr_pass/43baae16/status_regex_stderr_pass.err
status_regex_stderr_pass/43baae16: Regular Expression Match - Success!
status_regex_stdout_fail/f59731ba: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stdout_fail/f59731ba/stage
status_regex_stdout_fail/f59731ba: Running Test via command: bash status_regex_stdout_fail_build.sh
status_regex_stdout_fail/f59731ba: Test completed in 0.005614 seconds with returncode: 0
status_regex_stdout_fail/f59731ba: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stdout_fail/f59731ba/status_regex_stdout_fail.out
status_regex_stdout_fail/f59731ba: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stdout_fail/f59731ba/status_regex_stdout_fail.err
status_regex_stdout_fail/f59731ba: performing regular expression - '^(123FAIL)$' on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stdout_fail/f59731ba/status_regex_stdout_fail.out
status_regex_stdout_fail/f59731ba: Regular Expression Match - Failed!
status_regex_stderr_fail/d78f577f: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stderr_fail/d78f577f/stage
status_regex_stderr_fail/d78f577f: Running Test via command: bash status_regex_stderr_fail_build.sh
status_regex_stderr_fail/d78f577f: Test completed in 0.00549 seconds with returncode: 0
status_regex_stderr_fail/d78f577f: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stderr_fail/d78f577f/status_regex_stderr_fail.out
status_regex_stderr_fail/d78f577f: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stderr_fail/d78f577f/status_regex_stderr_fail.err
status_regex_stderr_fail/d78f577f: performing regular expression - '^(123FAIL)$' on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stderr_fail/d78f577f/status_regex_stderr_fail.err
status_regex_stderr_fail/d78f577f: Regular Expression Match - Failed!
status_regex_stdout_pass/ecffee6e: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stdout_pass/ecffee6e/stage
status_regex_stdout_pass/ecffee6e: Running Test via command: bash status_regex_stdout_pass_build.sh
status_regex_stdout_pass/ecffee6e: Test completed in 0.005246 seconds with returncode: 0
status_regex_stdout_pass/ecffee6e: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stdout_pass/ecffee6e/status_regex_stdout_pass.out
status_regex_stdout_pass/ecffee6e: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stdout_pass/ecffee6e/status_regex_stdout_pass.err
status_regex_stdout_pass/ecffee6e: performing regular expression - '^(PASS)$' on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/status_regex/status_regex_stdout_pass/ecffee6e/status_regex_stdout_pass.out
status_regex_stdout_pass/ecffee6e: Regular Expression Match - Success!
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ status_regex_stderr_fai │ generic.local.bash │ FAIL   │ 0          │ 0.005   │
│ l/d78f577f              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ status_regex_stdout_fai │ generic.local.bash │ FAIL   │ 0          │ 0.006   │
│ l/f59731ba              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ status_regex_stderr_pas │ generic.local.bash │ PASS   │ 0          │ 0.006   │
│ s/43baae16              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ status_regex_stdout_pas │ generic.local.bash │ PASS   │ 0          │ 0.005   │
│ s/ecffee6e              │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 2/4 Percentage: 50.000%
Failed Tests: 2/4 Percentage: 50.000%


Adding 4 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_r86pgeb9.log

file_regex: Regular Expression on files

In the previous example, we applied regular expression on output or error file; however, you may want to apply regular expression on arbitrary files. This can be done by specifying file_regex property. The file_regex property is an array of assertions, where each assertion must have filename and exp property. The filename property is the path to filename and exp is the regular expression you want to apply.

In this example, we have three tests that make use of file_regex property. The first test will perform a regular expression on multiple file names. The second test will attempt to check on a directory name which is not supported since regular expression must be applied to file name. The third test will show that variable expansion and environment variable expansion is supported.

buildspecs:
  regex_on_multiple_files:
    type: script
    executor: generic.local.bash
    description: Test regex on multiple files
    run: |
      echo "Hello" > hello.txt
      buildtest --help > buildtest_help.txt
    status:
      file_regex:
        - file: hello.txt
          exp: '^(Hello)$'
        - file: buildtest_help.txt
          exp: '^(usage: buildtest)'

  regex_on_directory_not_supported:
    type: script
    executor: generic.local.bash
    description: Test regex on directory is not supported
    run: |
      mkdir -p hello
      echo "Hello" > hello/hello.txt
    status:
      file_regex:
        - file: hello
          exp: '^(Hello)$'

  file_expansion_supported:
    type: script
    executor: generic.local.bash
    description: Test regex with variable and shell expansion
    run: |
      echo "Hello" > $BUILDTEST_ROOT/hello.txt
      echo "Hello" > $HOME/hello.txt
    status:
      file_regex:
        - file: $BUILDTEST_ROOT/hello.txt
          exp: '^(Hello)$'
        - file: ~/hello.txt
          exp: '^(Hello)$'

We can build this test by running the following command:

buildtest build -b tutorials/test_status/regex_on_filename.yml
$ buildtest build -b tutorials/test_status/regex_on_filename.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:12                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/regex_on_filename.yml                                  ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/regex_on_filename.yml: VALID
Total builder objects created: 3
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ regex_on │ script │ generic. │ None     │ None  │ None  │ Test     │ /home/d │
│ _multipl │        │ local.ba │          │       │       │ regex on │ ocs/che │
│ e_files/ │        │ sh       │          │       │       │ multiple │ ckouts/ │
│ f0bc6620 │        │          │          │       │       │ files    │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ regex_o │
│          │        │          │          │       │       │          │ n_filen │
│          │        │          │          │       │       │          │ ame.yml │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ regex_on │ script │ generic. │ None     │ None  │ None  │ Test     │ /home/d │
│ _directo │        │ local.ba │          │       │       │ regex on │ ocs/che │
│ ry_not_s │        │ sh       │          │       │       │ director │ ckouts/ │
│ upported │        │          │          │       │       │ y is not │ readthe │
│ /bd09389 │        │          │          │       │       │ supporte │ docs.or │
│ a        │        │          │          │       │       │ d        │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ regex_o │
│          │        │          │          │       │       │          │ n_filen │
│          │        │          │          │       │       │          │ ame.yml │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ file_exp │ script │ generic. │ None     │ None  │ None  │ Test     │ /home/d │
│ ansion_s │        │ local.ba │          │       │       │ regex    │ ocs/che │
│ upported │        │ sh       │          │       │       │ with     │ ckouts/ │
│ /9ac7bc2 │        │          │          │       │       │ variable │ readthe │
│ 1        │        │          │          │       │       │ and      │ docs.or │
│          │        │          │          │       │       │ shell    │ g/user_ │
│          │        │          │          │       │       │ expansio │ builds/ │
│          │        │          │          │       │       │ n        │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ regex_o │
│          │        │          │          │       │       │          │ n_filen │
│          │        │          │          │       │       │          │ ame.yml │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
regex_on_multiple_files/f0bc6620: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/f0bc6620
regex_on_directory_not_supported/bd09389a: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_directory_not_supported/bd09389a
file_expansion_supported/9ac7bc21: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/file_expansion_supported/9ac7bc21
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
regex_on_directory_not_supported/bd09389a does not have any dependencies adding test to queue
file_expansion_supported/9ac7bc21 does not have any dependencies adding test to queue
regex_on_multiple_files/f0bc6620 does not have any dependencies adding test to queue
          Builders Eligible to Run           
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                                   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ regex_on_directory_not_supported/bd09389a │
│ file_expansion_supported/9ac7bc21         │
│ regex_on_multiple_files/f0bc6620          │
└───────────────────────────────────────────┘
regex_on_directory_not_supported/bd09389a: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_directory_not_supported/bd09389a/stage
regex_on_directory_not_supported/bd09389a: Running Test via command: bash regex_on_directory_not_supported_build.sh
regex_on_directory_not_supported/bd09389a: Test completed in 0.007114 seconds with returncode: 0
regex_on_directory_not_supported/bd09389a: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_directory_not_supported/bd09389a/regex_on_directory_not_supported.out
regex_on_directory_not_supported/bd09389a: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_directory_not_supported/bd09389a/regex_on_directory_not_supported.err
regex_on_directory_not_supported/bd09389a: File: /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_directory_not_supported/bd09389a/stage/hello is not a file
file_expansion_supported/9ac7bc21: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/file_expansion_supported/9ac7bc21/stage
file_expansion_supported/9ac7bc21: Running Test via command: bash file_expansion_supported_build.sh
file_expansion_supported/9ac7bc21: Test completed in 0.005432 seconds with returncode: 0
file_expansion_supported/9ac7bc21: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/file_expansion_supported/9ac7bc21/file_expansion_supported.out
file_expansion_supported/9ac7bc21: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/file_expansion_supported/9ac7bc21/file_expansion_supported.err
file_expansion_supported/9ac7bc21: Performing regex expression '^(Hello)$' on file /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/hello.txt
file_expansion_supported/9ac7bc21: Regular expression on file /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/hello.txt is a MATCH!
file_expansion_supported/9ac7bc21: Performing regex expression '^(Hello)$' on file /home/docs/hello.txt
file_expansion_supported/9ac7bc21: Regular expression on file /home/docs/hello.txt is a MATCH!
regex_on_multiple_files/f0bc6620: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/f0bc6620/stage
regex_on_multiple_files/f0bc6620: Running Test via command: bash regex_on_multiple_files_build.sh
regex_on_multiple_files/f0bc6620: Test completed in 0.459627 seconds with returncode: 0
regex_on_multiple_files/f0bc6620: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/f0bc6620/regex_on_multiple_files.out
regex_on_multiple_files/f0bc6620: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/f0bc6620/regex_on_multiple_files.err
regex_on_multiple_files/f0bc6620: Performing regex expression '^(Hello)$' on file /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/f0bc6620/stage/hello.txt
regex_on_multiple_files/f0bc6620: Regular expression on file /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/f0bc6620/stage/hello.txt is a MATCH!
regex_on_multiple_files/f0bc6620: Performing regex expression '^(usage: buildtest)' on file /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/f0bc6620/stage/buildtest_help.txt
regex_on_multiple_files/f0bc6620: Regular expression on file /tmp/tmpu6myg391/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/f0bc6620/stage/buildtest_help.txt is a MATCH!
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ regex_on_multiple_files │ generic.local.bash │ PASS   │ 0          │ 0.460   │
│ /f0bc6620               │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ regex_on_directory_not_ │ generic.local.bash │ FAIL   │ 0          │ 0.007   │
│ supported/bd09389a      │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ file_expansion_supporte │ generic.local.bash │ PASS   │ 0          │ 0.005   │
│ d/9ac7bc21              │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 2/3 Percentage: 66.667%
Failed Tests: 1/3 Percentage: 33.333%


Adding 3 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_0pe7mx4b.log

runtime: Passing Test based on runtime

buildtest can determine state of test based on runtime property which is part of status object. This can be used if you want to control how test PASS or FAIL based on execution time of test. In example below we have five tests that make use of runtime property for passing a test. The runtime property support min and max property that can mark test pass based on minimum and maximum runtime. A test will pass if it’s execution time is greater than min time and less than max time. If min is specified without max property the upperbound is not set, likewise max without min will pass if test is less than max time. The lower bound is not set, but test runtime will be greater than 0 sec.

In test timelimit_min, we sleep for 2 seconds and it will pass because minimum runtime is 1.0 seconds. Similarly, timelimit_max will pass because we sleep for 2 seconds with a max time of 5.0.

buildspecs:
  timelimit_min_max:
    type: script
    executor: generic.local.sh
    description: "Run a sleep job for 2 seconds and test pass if its within 1.0-3.0sec"
    tags: ["tutorials"]
    run: sleep 2
    status:
      runtime:
        min: 1.0
        max: 3.0

  timelimit_min:
    type: script
    executor: generic.local.sh
    description: "Run a sleep job for 2 seconds and test pass if its exceeds min time of 1.0 sec"
    tags: ["tutorials"]
    run: sleep 2
    status:
      runtime:
        min: 1.0

  timelimit_max:
    type: script
    executor: generic.local.sh
    description: "Run a sleep job for 2 seconds and test pass if it's within max time: 5.0 sec"
    tags: ["tutorials"]
    run: sleep 2
    status:
      runtime:
        max: 5.0

  timelimit_min_fail:
    type: script
    executor: generic.local.sh
    description: "This test fails because it runs less than mintime of 10 second"
    tags: ["tutorials"]
    run: sleep 2
    status:
      runtime:
        min: 10.0

  timelimit_max_fail:
    type: script
    executor: generic.local.sh
    description: "This test fails because it exceeds maxtime of 1.0 second"
    tags: ["tutorials"]
    run: sleep 3
    status:
      runtime:
        max: 1.0
buildtest build -b tutorials/test_status/runtime_status_test.yml
$ buildtest build -b tutorials/test_status/runtime_status_test.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:13                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/runtime_status_test.yml                                ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/runtime_status_test.yml: VALID
Total builder objects created: 5
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ timelimi │ script │ generic. │ None     │ None  │ None  │ Run a    │ /home/d │
│ t_min_ma │        │ local.sh │          │       │       │ sleep    │ ocs/che │
│ x/1e5ad4 │        │          │          │       │       │ job for  │ ckouts/ │
│ 28       │        │          │          │       │       │ 2        │ readthe │
│          │        │          │          │       │       │ seconds  │ docs.or │
│          │        │          │          │       │       │ and test │ g/user_ │
│          │        │          │          │       │       │ pass if  │ builds/ │
│          │        │          │          │       │       │ its      │ buildte │
│          │        │          │          │       │       │ within   │ st/chec │
│          │        │          │          │       │       │ 1.0-3.0s │ kouts/l │
│          │        │          │          │       │       │ ec       │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ runtime │
│          │        │          │          │       │       │          │ _status │
│          │        │          │          │       │       │          │ _test.y │
│          │        │          │          │       │       │          │ ml      │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ timelimi │ script │ generic. │ None     │ None  │ None  │ Run a    │ /home/d │
│ t_min/49 │        │ local.sh │          │       │       │ sleep    │ ocs/che │
│ bcd7db   │        │          │          │       │       │ job for  │ ckouts/ │
│          │        │          │          │       │       │ 2        │ readthe │
│          │        │          │          │       │       │ seconds  │ docs.or │
│          │        │          │          │       │       │ and test │ g/user_ │
│          │        │          │          │       │       │ pass if  │ builds/ │
│          │        │          │          │       │       │ its      │ buildte │
│          │        │          │          │       │       │ exceeds  │ st/chec │
│          │        │          │          │       │       │ min time │ kouts/l │
│          │        │          │          │       │       │ of 1.0   │ atest/t │
│          │        │          │          │       │       │ sec      │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ runtime │
│          │        │          │          │       │       │          │ _status │
│          │        │          │          │       │       │          │ _test.y │
│          │        │          │          │       │       │          │ ml      │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ timelimi │ script │ generic. │ None     │ None  │ None  │ Run a    │ /home/d │
│ t_max/66 │        │ local.sh │          │       │       │ sleep    │ ocs/che │
│ 075b22   │        │          │          │       │       │ job for  │ ckouts/ │
│          │        │          │          │       │       │ 2        │ readthe │
│          │        │          │          │       │       │ seconds  │ docs.or │
│          │        │          │          │       │       │ and test │ g/user_ │
│          │        │          │          │       │       │ pass if  │ builds/ │
│          │        │          │          │       │       │ it's     │ buildte │
│          │        │          │          │       │       │ within   │ st/chec │
│          │        │          │          │       │       │ max      │ kouts/l │
│          │        │          │          │       │       │ time:    │ atest/t │
│          │        │          │          │       │       │ 5.0 sec  │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ runtime │
│          │        │          │          │       │       │          │ _status │
│          │        │          │          │       │       │          │ _test.y │
│          │        │          │          │       │       │          │ ml      │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ timelimi │ script │ generic. │ None     │ None  │ None  │ This     │ /home/d │
│ t_min_fa │        │ local.sh │          │       │       │ test     │ ocs/che │
│ il/53c89 │        │          │          │       │       │ fails    │ ckouts/ │
│ a69      │        │          │          │       │       │ because  │ readthe │
│          │        │          │          │       │       │ it runs  │ docs.or │
│          │        │          │          │       │       │ less     │ g/user_ │
│          │        │          │          │       │       │ than     │ builds/ │
│          │        │          │          │       │       │ mintime  │ buildte │
│          │        │          │          │       │       │ of 10    │ st/chec │
│          │        │          │          │       │       │ second   │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ runtime │
│          │        │          │          │       │       │          │ _status │
│          │        │          │          │       │       │          │ _test.y │
│          │        │          │          │       │       │          │ ml      │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ timelimi │ script │ generic. │ None     │ None  │ None  │ This     │ /home/d │
│ t_max_fa │        │ local.sh │          │       │       │ test     │ ocs/che │
│ il/612ee │        │          │          │       │       │ fails    │ ckouts/ │
│ 608      │        │          │          │       │       │ because  │ readthe │
│          │        │          │          │       │       │ it       │ docs.or │
│          │        │          │          │       │       │ exceeds  │ g/user_ │
│          │        │          │          │       │       │ maxtime  │ builds/ │
│          │        │          │          │       │       │ of 1.0   │ buildte │
│          │        │          │          │       │       │ second   │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ runtime │
│          │        │          │          │       │       │          │ _status │
│          │        │          │          │       │       │          │ _test.y │
│          │        │          │          │       │       │          │ ml      │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
timelimit_min_max/1e5ad428: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min_max/1e5ad428
timelimit_min/49bcd7db: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min/49bcd7db
timelimit_max/66075b22: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_max/66075b22
timelimit_min_fail/53c89a69: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min_fail/53c89a69
timelimit_max_fail/612ee608: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_max_fail/612ee608
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
timelimit_min_max/1e5ad428 does not have any dependencies adding test to queue
timelimit_min_fail/53c89a69 does not have any dependencies adding test to queue
timelimit_min/49bcd7db does not have any dependencies adding test to queue
timelimit_max_fail/612ee608 does not have any dependencies adding test to queue
timelimit_max/66075b22 does not have any dependencies adding test to queue
   Builders Eligible to Run    
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                     ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ timelimit_min_max/1e5ad428  │
│ timelimit_min_fail/53c89a69 │
│ timelimit_min/49bcd7db      │
│ timelimit_max_fail/612ee608 │
│ timelimit_max/66075b22      │
└─────────────────────────────┘
timelimit_min_max/1e5ad428: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min_max/1e5ad428/stage
timelimit_min_max/1e5ad428: Running Test via command: bash timelimit_min_max_build.sh
timelimit_min_max/1e5ad428: Test completed in 2.006062 seconds with returncode: 0
timelimit_min_max/1e5ad428: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min_max/1e5ad428/timelimit_min_max.out
timelimit_min_max/1e5ad428: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min_max/1e5ad428/timelimit_min_max.err
timelimit_min_max/1e5ad428: Checking mintime < runtime < maxtime: 1.0 < 2.006062 < 3.0
timelimit_min_fail/53c89a69: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min_fail/53c89a69/stage
timelimit_min_fail/53c89a69: Running Test via command: bash timelimit_min_fail_build.sh
timelimit_min_fail/53c89a69: Test completed in 2.009034 seconds with returncode: 0
timelimit_min_fail/53c89a69: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min_fail/53c89a69/timelimit_min_fail.out
timelimit_min_fail/53c89a69: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min_fail/53c89a69/timelimit_min_fail.err
timelimit_min_fail/53c89a69: Checking  mintime < runtime: 10.0 < 2.009034
timelimit_min/49bcd7db: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min/49bcd7db/stage
timelimit_min/49bcd7db: Running Test via command: bash timelimit_min_build.sh
timelimit_min/49bcd7db: Test completed in 2.006252 seconds with returncode: 0
timelimit_min/49bcd7db: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min/49bcd7db/timelimit_min.out
timelimit_min/49bcd7db: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_min/49bcd7db/timelimit_min.err
timelimit_min/49bcd7db: Checking  mintime < runtime: 1.0 < 2.006252
timelimit_max_fail/612ee608: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_max_fail/612ee608/stage
timelimit_max_fail/612ee608: Running Test via command: bash timelimit_max_fail_build.sh
timelimit_max_fail/612ee608: Test completed in 3.007364 seconds with returncode: 0
timelimit_max_fail/612ee608: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_max_fail/612ee608/timelimit_max_fail.out
timelimit_max_fail/612ee608: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_max_fail/612ee608/timelimit_max_fail.err
timelimit_max_fail/612ee608: Checking runtime < maxtime: 3.007364 < 1.0 
timelimit_max/66075b22: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_max/66075b22/stage
timelimit_max/66075b22: Running Test via command: bash timelimit_max_build.sh
timelimit_max/66075b22: Test completed in 2.006277 seconds with returncode: 0
timelimit_max/66075b22: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_max/66075b22/timelimit_max.out
timelimit_max/66075b22: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.sh/runtime_status_test/timelimit_max/66075b22/timelimit_max.err
timelimit_max/66075b22: Checking runtime < maxtime: 2.006277 < 5.0 
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                   ┃ executor         ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ timelimit_min_max/1e5ad42 │ generic.local.sh │ PASS   │ 0          │ 2.006   │
│ 8                         │                  │        │            │         │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ timelimit_min/49bcd7db    │ generic.local.sh │ PASS   │ 0          │ 2.006   │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ timelimit_max_fail/612ee6 │ generic.local.sh │ FAIL   │ 0          │ 3.007   │
│ 08                        │                  │        │            │         │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ timelimit_max/66075b22    │ generic.local.sh │ PASS   │ 0          │ 2.006   │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ timelimit_min_fail/53c89a │ generic.local.sh │ FAIL   │ 0          │ 2.009   │
│ 69                        │                  │        │            │         │
└───────────────────────────┴──────────────────┴────────┴────────────┴─────────┘



Passed Tests: 3/5 Percentage: 60.000%
Failed Tests: 2/5 Percentage: 40.000%


Adding 5 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_ggyvllyh.log

If we look at the test results, we expect the first three tests timelimit_min, timelimit_max, timelimit_min_max will pass while the last two tests fail because it fails to comply with runtime property.

buildtest report --filter buildspec=tutorials/test_status/runtime_status_test.yml --format name,id,state,runtime --latest
$ buildtest report --filter buildspec=tutorials/test_status/runtime_status_test.yml --format name,id,state,runtime --latest
                 Report File: /tmp/tmpu6myg391/var/report.json                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ name                           ┃ id             ┃ state      ┃ runtime       ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ timelimit_min_max              │ 1e5ad428       │ PASS       │ 2.006062      │
├────────────────────────────────┼────────────────┼────────────┼───────────────┤
│ timelimit_min                  │ 49bcd7db       │ PASS       │ 2.006252      │
├────────────────────────────────┼────────────────┼────────────┼───────────────┤
│ timelimit_max_fail             │ 612ee608       │ FAIL       │ 3.007364      │
├────────────────────────────────┼────────────────┼────────────┼───────────────┤
│ timelimit_max                  │ 66075b22       │ PASS       │ 2.006277      │
├────────────────────────────────┼────────────────┼────────────┼───────────────┤
│ timelimit_min_fail             │ 53c89a69       │ FAIL       │ 2.009034      │
└────────────────────────────────┴────────────────┴────────────┴───────────────┘

state: Explicitly Declare Status of Test

You can explicitly define status of test regardless of what buildtest does for checking status of test. This can be useful if you want to explicitly mark a test as PASS or FAIL regardless of how test behaves. This can be done via state property which expects one of two types PASS or FAIL. If state property is specified, buildtest will ignore any checks including returncode, regex, or runtime match.

In this next example we will demonstrate how one can use state property for marking test state. In this example we have four tests. The first test always_pass will PASS even though we have a non-zero returncode. The second test always_fail will FAIL even though it has a 0 returncode. The last two test demonstrate how one can define state regardless of what is specified for returncode match. buildtest will honor the state property even if their is a match on the returncode.

buildspecs:
  always_pass:
    type: script
    executor: 'generic.local.sh'
    description: This test will always 'PASS'
    run: exit 1
    status:
      state: PASS

  always_fail:
    type: script
    executor: 'generic.local.sh'
    description: This test will always 'FAIL'
    run: exit 0
    status:
      state: FAIL

  test_fail_returncode_match:
    type: script
    executor: 'generic.local.sh'
    description: This test will 'FAIL' even if we have returncode match
    run: exit 1
    status:
      state: FAIL
      returncode: 1

  test_pass_returncode_mismatch:
    type: script
    executor: 'generic.local.sh'
    description: This test will 'PASS' even if we have returncode mismatch
    run: exit 1
    status:
      state: PASS
      returncode: 2

If we build this test, we expect buildtest to honor the value of state property

buildtest build -b tutorials/test_status/explicit_state.yml
$ buildtest build -b tutorials/test_status/explicit_state.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:25                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/explicit_state.yml                                     ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/explicit_state.yml: VALID
Total builder objects created: 4
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ always_p │ script │ generic. │ None     │ None  │ None  │ This     │ /home/d │
│ ass/fafc │        │ local.sh │          │       │       │ test     │ ocs/che │
│ 6ab9     │        │          │          │       │       │ will     │ ckouts/ │
│          │        │          │          │       │       │ always   │ readthe │
│          │        │          │          │       │       │ 'PASS'   │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ explici │
│          │        │          │          │       │       │          │ t_state │
│          │        │          │          │       │       │          │ .yml    │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ always_f │ script │ generic. │ None     │ None  │ None  │ This     │ /home/d │
│ ail/773f │        │ local.sh │          │       │       │ test     │ ocs/che │
│ b1e5     │        │          │          │       │       │ will     │ ckouts/ │
│          │        │          │          │       │       │ always   │ readthe │
│          │        │          │          │       │       │ 'FAIL'   │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ explici │
│          │        │          │          │       │       │          │ t_state │
│          │        │          │          │       │       │          │ .yml    │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ test_fai │ script │ generic. │ None     │ None  │ None  │ This     │ /home/d │
│ l_return │        │ local.sh │          │       │       │ test     │ ocs/che │
│ code_mat │        │          │          │       │       │ will     │ ckouts/ │
│ ch/6e3ea │        │          │          │       │       │ 'FAIL'   │ readthe │
│ 1ec      │        │          │          │       │       │ even if  │ docs.or │
│          │        │          │          │       │       │ we have  │ g/user_ │
│          │        │          │          │       │       │ returnco │ builds/ │
│          │        │          │          │       │       │ de match │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ explici │
│          │        │          │          │       │       │          │ t_state │
│          │        │          │          │       │       │          │ .yml    │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ test_pas │ script │ generic. │ None     │ None  │ None  │ This     │ /home/d │
│ s_return │        │ local.sh │          │       │       │ test     │ ocs/che │
│ code_mis │        │          │          │       │       │ will     │ ckouts/ │
│ match/cc │        │          │          │       │       │ 'PASS'   │ readthe │
│ a72236   │        │          │          │       │       │ even if  │ docs.or │
│          │        │          │          │       │       │ we have  │ g/user_ │
│          │        │          │          │       │       │ returnco │ builds/ │
│          │        │          │          │       │       │ de       │ buildte │
│          │        │          │          │       │       │ mismatch │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ explici │
│          │        │          │          │       │       │          │ t_state │
│          │        │          │          │       │       │          │ .yml    │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
always_pass/fafc6ab9: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/always_pass/fafc6ab9
always_fail/773fb1e5: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/always_fail/773fb1e5
test_fail_returncode_match/6e3ea1ec: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/test_fail_returncode_match/6e3ea1ec
test_pass_returncode_mismatch/cca72236: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/test_pass_returncode_mismatch/cca72236
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
always_pass/fafc6ab9 does not have any dependencies adding test to queue
test_fail_returncode_match/6e3ea1ec does not have any dependencies adding test to queue
always_fail/773fb1e5 does not have any dependencies adding test to queue
test_pass_returncode_mismatch/cca72236 does not have any dependencies adding test to queue
         Builders Eligible to Run         
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                                ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ always_pass/fafc6ab9                   │
│ test_fail_returncode_match/6e3ea1ec    │
│ always_fail/773fb1e5                   │
│ test_pass_returncode_mismatch/cca72236 │
└────────────────────────────────────────┘
always_pass/fafc6ab9: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/always_pass/fafc6ab9/stage
always_pass/fafc6ab9: Running Test via command: bash always_pass_build.sh
always_pass/fafc6ab9: failed to submit job with returncode: 1
──────────────────── Error Message for always_pass/fafc6ab9 ────────────────────

always_pass/fafc6ab9: Detected failure in running test, will attempt to retry test: 1 times
always_pass/fafc6ab9: Run - 1/1
always_pass/fafc6ab9: Running Test via command: bash always_pass_build.sh
always_pass/fafc6ab9: failed to submit job with returncode: 1
always_pass/fafc6ab9: Test completed in 0.012999 seconds with returncode: 1
always_pass/fafc6ab9: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/always_pass/fafc6ab9/always_pass.out
always_pass/fafc6ab9: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/always_pass/fafc6ab9/always_pass.err
test_fail_returncode_match/6e3ea1ec: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/test_fail_returncode_match/6e3ea1ec/stage
test_fail_returncode_match/6e3ea1ec: Running Test via command: bash test_fail_returncode_match_build.sh
test_fail_returncode_match/6e3ea1ec: failed to submit job with returncode: 1
──────────── Error Message for test_fail_returncode_match/6e3ea1ec ─────────────

test_fail_returncode_match/6e3ea1ec: Detected failure in running test, will attempt to retry test: 1 times
test_fail_returncode_match/6e3ea1ec: Run - 1/1
test_fail_returncode_match/6e3ea1ec: Running Test via command: bash test_fail_returncode_match_build.sh
test_fail_returncode_match/6e3ea1ec: failed to submit job with returncode: 1
test_fail_returncode_match/6e3ea1ec: Test completed in 0.012744 seconds with returncode: 1
test_fail_returncode_match/6e3ea1ec: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/test_fail_returncode_match/6e3ea1ec/test_fail_returncode_match.out
test_fail_returncode_match/6e3ea1ec: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/test_fail_returncode_match/6e3ea1ec/test_fail_returncode_match.err
always_fail/773fb1e5: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/always_fail/773fb1e5/stage
always_fail/773fb1e5: Running Test via command: bash always_fail_build.sh
always_fail/773fb1e5: Test completed in 0.004467 seconds with returncode: 0
always_fail/773fb1e5: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/always_fail/773fb1e5/always_fail.out
always_fail/773fb1e5: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/always_fail/773fb1e5/always_fail.err
test_pass_returncode_mismatch/cca72236: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/test_pass_returncode_mismatch/cca72236/stage
test_pass_returncode_mismatch/cca72236: Running Test via command: bash test_pass_returncode_mismatch_build.sh
test_pass_returncode_mismatch/cca72236: failed to submit job with returncode: 1
─────────── Error Message for test_pass_returncode_mismatch/cca72236 ───────────

test_pass_returncode_mismatch/cca72236: Detected failure in running test, will attempt to retry test: 1 times
test_pass_returncode_mismatch/cca72236: Run - 1/1
test_pass_returncode_mismatch/cca72236: Running Test via command: bash test_pass_returncode_mismatch_build.sh
test_pass_returncode_mismatch/cca72236: failed to submit job with returncode: 1
test_pass_returncode_mismatch/cca72236: Test completed in 0.012261 seconds with returncode: 1
test_pass_returncode_mismatch/cca72236: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/test_pass_returncode_mismatch/cca72236/test_pass_returncode_mismatch.out
test_pass_returncode_mismatch/cca72236: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.sh/explicit_state/test_pass_returncode_mismatch/cca72236/test_pass_returncode_mismatch.err
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                   ┃ executor         ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ always_pass/fafc6ab9      │ generic.local.sh │ PASS   │ 1          │ 0.013   │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ always_fail/773fb1e5      │ generic.local.sh │ FAIL   │ 0          │ 0.004   │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ test_fail_returncode_matc │ generic.local.sh │ FAIL   │ 1          │ 0.013   │
│ h/6e3ea1ec                │                  │        │            │         │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ test_pass_returncode_mism │ generic.local.sh │ PASS   │ 1          │ 0.012   │
│ atch/cca72236             │                  │        │            │         │
└───────────────────────────┴──────────────────┴────────┴────────────┴─────────┘



Passed Tests: 2/4 Percentage: 50.000%
Failed Tests: 2/4 Percentage: 50.000%


Adding 4 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest__h9v0v0e.log

File Checks

buildtest supports various file checks that can be used as means for passing test. This can include checking for exists: File Existence, is_file, is_dir: File and Directory Checks, is_symlink: Symbolic Link Check, and file_count: File Count.

exists: File Existence

For instance, if you want to check for file existence, you can use exists property which expects a list of file or directory names to check. This can be useful if your test will write some output file or directory and test will pass based on existence of file/directory.

In the example below we have two tests, first test will pass, where all files exist. We check for files and directory path, note variable and shell expansion is supported.

In the second example, we expect this test to fail because filename bar does not exist.

buildspecs:
  status_exists:
    type: script
    executor: generic.local.bash
    description: status check based for file and directory
    run: |
      mkdir -p $HOME/dirA
      mkdir -p /tmp/ABC
      touch file1
    status:
      exists:
        - $HOME/dirA
        - ~/.bashrc
        - /tmp/ABC
        - file1
  status_exists_failure:
    type: script
    executor: generic.local.bash
    description: status check failure for existence
    run: touch foo
    status:
      exists:
        - bar

We can run this test by running the following, take note of the output.

buildtest build -b tutorials/test_status/exists.yml
$ buildtest build -b tutorials/test_status/exists.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:26                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/exists.yml                                             ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/exists.yml: VALID
Total builder objects created: 2
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ status_e │ script │ generic. │ None     │ None  │ None  │ status   │ /home/d │
│ xists/8e │        │ local.ba │          │       │       │ check    │ ocs/che │
│ 6eb74f   │        │ sh       │          │       │       │ based    │ ckouts/ │
│          │        │          │          │       │       │ for file │ readthe │
│          │        │          │          │       │       │ and      │ docs.or │
│          │        │          │          │       │       │ director │ g/user_ │
│          │        │          │          │       │       │ y        │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ exists. │
│          │        │          │          │       │       │          │ yml     │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ status_e │ script │ generic. │ None     │ None  │ None  │ status   │ /home/d │
│ xists_fa │        │ local.ba │          │       │       │ check    │ ocs/che │
│ ilure/f6 │        │ sh       │          │       │       │ failure  │ ckouts/ │
│ 6bd6ac   │        │          │          │       │       │ for      │ readthe │
│          │        │          │          │       │       │ existenc │ docs.or │
│          │        │          │          │       │       │ e        │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ exists. │
│          │        │          │          │       │       │          │ yml     │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
status_exists/8e6eb74f: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/exists/status_exists/8e6eb74f
status_exists_failure/f66bd6ac: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/exists/status_exists_failure/f66bd6ac
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
status_exists/8e6eb74f does not have any dependencies adding test to queue
status_exists_failure/f66bd6ac does not have any dependencies adding test to queue
     Builders Eligible to Run     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                        ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ status_exists/8e6eb74f         │
│ status_exists_failure/f66bd6ac │
└────────────────────────────────┘
status_exists/8e6eb74f: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/exists/status_exists/8e6eb74f/stage
status_exists/8e6eb74f: Running Test via command: bash status_exists_build.sh
status_exists/8e6eb74f: Test completed in 0.008807 seconds with returncode: 0
status_exists/8e6eb74f: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/exists/status_exists/8e6eb74f/status_exists.out
status_exists/8e6eb74f: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/exists/status_exists/8e6eb74f/status_exists.err
status_exists/8e6eb74f: Test all files:  ['$HOME/dirA', '~/.bashrc', '/tmp/ABC', 'file1']  existences
status_exists/8e6eb74f: file: /home/docs/dirA exists
status_exists/8e6eb74f: file: /home/docs/.bashrc exists
status_exists/8e6eb74f: file: /tmp/ABC exists
status_exists/8e6eb74f: file: /tmp/tmpu6myg391/var/tests/generic.local.bash/exists/status_exists/8e6eb74f/stage/file1 exists
status_exists/8e6eb74f: Exist Check: True
status_exists_failure/f66bd6ac: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/exists/status_exists_failure/f66bd6ac/stage
status_exists_failure/f66bd6ac: Running Test via command: bash status_exists_failure_build.sh
status_exists_failure/f66bd6ac: Test completed in 0.006123 seconds with returncode: 0
status_exists_failure/f66bd6ac: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/exists/status_exists_failure/f66bd6ac/status_exists_failure.out
status_exists_failure/f66bd6ac: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/exists/status_exists_failure/f66bd6ac/status_exists_failure.err
status_exists_failure/f66bd6ac: Test all files:  ['bar']  existences 
status_exists_failure/f66bd6ac: file: bar does not exist
status_exists_failure/f66bd6ac: Exist Check: False
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ status_exists/8e6eb74f  │ generic.local.bash │ PASS   │ 0          │ 0.009   │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ status_exists_failure/f │ generic.local.bash │ FAIL   │ 0          │ 0.006   │
│ 66bd6ac                 │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 1/2 Percentage: 50.000%
Failed Tests: 1/2 Percentage: 50.000%


Adding 2 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_6z5k_1w3.log

Each item in the exists field must be a string, which can lead to issue in example below let’s assume we want a test to pass based on a directory name 1, if we specify as follows, this test will fail validation.

buildspecs:
  file_exists_failure:
   type: script
   executor: generic.local.bash
   description: this test will fail validation, because item must be a string
   run: mkdir -p 1
   status:
     exists: [1]

We can validate this buildspec by running the following

buildtest bc validate -b tutorials/test_status/file_exists_exception.yml
$ buildtest bc validate -b tutorials/test_status/file_exists_exception.yml
─ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest… ─
1 is not of type 'string'

Failed validating 'type' in schema['properties']['status']['properties']['exists']['items']:
    {'type': 'string'}

On instance['status']['exists'][0]:
    1


1 buildspecs failed to validate

In order to run this test, we need to enclose each item in quotes. Shown below is the same test with quotations.

buildspecs:
  file_exists_pass:
    type: script
    executor: generic.local.bash
    description: this test will pass
    run: mkdir -p 1
    status:
      exists: [ '1' ]

Let’s validate and build this test.

buildtest bc validate -b tutorials/test_status/file_exists_with_number.yml
$ buildtest bc validate -b tutorials/test_status/file_exists_with_number.yml
buildspec: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/file_exists_with_number.yml is valid
All buildspecs passed validation!!!
buildtest build -b tutorials/test_status/file_exists_with_number.yml
$ buildtest build -b tutorials/test_status/file_exists_with_number.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:28                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/file_exists_with_number.yml                            ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/file_exists_with_number.yml: VALID
Total builder objects created: 1
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ file_exi │ script │ generic. │ None     │ None  │ None  │ this     │ /home/d │
│ sts_pass │        │ local.ba │          │       │       │ test     │ ocs/che │
│ /74c4f50 │        │ sh       │          │       │       │ will     │ ckouts/ │
│ 5        │        │          │          │       │       │ pass     │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_ex │
│          │        │          │          │       │       │          │ ists_wi │
│          │        │          │          │       │       │          │ th_numb │
│          │        │          │          │       │       │          │ er.yml  │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_exists_pass/74c4f505: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_exists_with_number/file_exists_pass/74c4f505
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_exists_pass/74c4f505 does not have any dependencies adding test to queue
  Builders Eligible to Run   
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_exists_pass/74c4f505 │
└───────────────────────────┘
file_exists_pass/74c4f505: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_exists_with_number/file_exists_pass/74c4f505/stage
file_exists_pass/74c4f505: Running Test via command: bash file_exists_pass_build.sh
file_exists_pass/74c4f505: Test completed in 0.006931 seconds with returncode: 0
file_exists_pass/74c4f505: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_exists_with_number/file_exists_pass/74c4f505/file_exists_pass.out
file_exists_pass/74c4f505: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_exists_with_number/file_exists_pass/74c4f505/file_exists_pass.err
file_exists_pass/74c4f505: Test all files:  ['1']  existences 
file_exists_pass/74c4f505: file: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_exists_with_number/file_exists_pass/74c4f505/stage/1 exists
file_exists_pass/74c4f505: Exist Check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_exists_pass/74c4f5 │ generic.local.bash │ PASS   │ 0          │ 0.007   │
│ 05                      │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 1/1 Percentage: 100.000%
Failed Tests: 0/1 Percentage: 0.000%


Adding 1 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_rka29m04.log

is_file, is_dir: File and Directory Checks

In the next example, we introduce checks for files and directory via is_file and is_dir property, which behaves similar to exists except they will check if each item is a file or directory. We expect the first test to fail, because $HOME/.bashrc is not a directory but a file. The second test will incorporate the same test and use is_file for status check.

buildspecs:
  file_and_dir_checks:
    type: script
    executor: generic.local.bash
    description: status check for files and directories
    run: hostname
    status:
      is_dir:
        - $HOME
        - $HOME/.bashrc
        - /tmp
  combined_file_and_dir_checks:
    type: script
    executor: generic.local.bash
    description: status check for files and directories
    run: hostname
    status:
      is_dir:
        - $HOME
        - /tmp
      is_file:
        - $HOME/.bashrc

Let’s build the test and see the output.

buildtest build -b tutorials/test_status/file_and_dir_check.yml
$ buildtest build -b tutorials/test_status/file_and_dir_check.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:28                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/file_and_dir_check.yml                                 ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/file_and_dir_check.yml: VALID
Total builder objects created: 2
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ file_and │ script │ generic. │ None     │ None  │ None  │ status   │ /home/d │
│ _dir_che │        │ local.ba │          │       │       │ check    │ ocs/che │
│ cks/410c │        │ sh       │          │       │       │ for      │ ckouts/ │
│ 3439     │        │          │          │       │       │ files    │ readthe │
│          │        │          │          │       │       │ and      │ docs.or │
│          │        │          │          │       │       │ director │ g/user_ │
│          │        │          │          │       │       │ ies      │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_an │
│          │        │          │          │       │       │          │ d_dir_c │
│          │        │          │          │       │       │          │ heck.ym │
│          │        │          │          │       │       │          │ l       │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ combined │ script │ generic. │ None     │ None  │ None  │ status   │ /home/d │
│ _file_an │        │ local.ba │          │       │       │ check    │ ocs/che │
│ d_dir_ch │        │ sh       │          │       │       │ for      │ ckouts/ │
│ ecks/0e5 │        │          │          │       │       │ files    │ readthe │
│ 5236d    │        │          │          │       │       │ and      │ docs.or │
│          │        │          │          │       │       │ director │ g/user_ │
│          │        │          │          │       │       │ ies      │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_an │
│          │        │          │          │       │       │          │ d_dir_c │
│          │        │          │          │       │       │          │ heck.ym │
│          │        │          │          │       │       │          │ l       │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_and_dir_checks/410c3439: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_and_dir_check/file_and_dir_checks/410c3439
combined_file_and_dir_checks/0e55236d: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_and_dir_check/combined_file_and_dir_checks/0e55236d
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
combined_file_and_dir_checks/0e55236d does not have any dependencies adding test to queue
file_and_dir_checks/410c3439 does not have any dependencies adding test to queue
        Builders Eligible to Run         
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                               ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ combined_file_and_dir_checks/0e55236d │
│ file_and_dir_checks/410c3439          │
└───────────────────────────────────────┘
combined_file_and_dir_checks/0e55236d: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_and_dir_check/combined_file_and_dir_checks/0e55236d/stage
combined_file_and_dir_checks/0e55236d: Running Test via command: bash combined_file_and_dir_checks_build.sh
combined_file_and_dir_checks/0e55236d: Test completed in 0.006522 seconds with returncode: 0
combined_file_and_dir_checks/0e55236d: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_and_dir_check/combined_file_and_dir_checks/0e55236d/combined_file_and_dir_checks.out
combined_file_and_dir_checks/0e55236d: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_and_dir_check/combined_file_and_dir_checks/0e55236d/combined_file_and_dir_checks.err
combined_file_and_dir_checks/0e55236d: Test all files:  ['$HOME', '/tmp']  existences
combined_file_and_dir_checks/0e55236d: file: /home/docs is a directory 
combined_file_and_dir_checks/0e55236d: file: /tmp is a directory 
combined_file_and_dir_checks/0e55236d: Directory Existence Check: True
combined_file_and_dir_checks/0e55236d: Test all files:  ['$HOME/.bashrc']  existences
combined_file_and_dir_checks/0e55236d: file: /home/docs/.bashrc is a file 
combined_file_and_dir_checks/0e55236d: File Existence Check: True
file_and_dir_checks/410c3439: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_and_dir_check/file_and_dir_checks/410c3439/stage
file_and_dir_checks/410c3439: Running Test via command: bash file_and_dir_checks_build.sh
file_and_dir_checks/410c3439: Test completed in 0.006152 seconds with returncode: 0
file_and_dir_checks/410c3439: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_and_dir_check/file_and_dir_checks/410c3439/file_and_dir_checks.out
file_and_dir_checks/410c3439: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_and_dir_check/file_and_dir_checks/410c3439/file_and_dir_checks.err
file_and_dir_checks/410c3439: Test all files:  ['$HOME', '$HOME/.bashrc', '/tmp']  existences
file_and_dir_checks/410c3439: file: /home/docs is a directory 
file_and_dir_checks/410c3439: file: $HOME/.bashrc is not a directory
file_and_dir_checks/410c3439: file: /tmp is a directory 
file_and_dir_checks/410c3439: Directory Existence Check: False
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ combined_file_and_dir_c │ generic.local.bash │ PASS   │ 0          │ 0.007   │
│ hecks/0e55236d          │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ file_and_dir_checks/410 │ generic.local.bash │ FAIL   │ 0          │ 0.006   │
│ c3439                   │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 1/2 Percentage: 50.000%
Failed Tests: 1/2 Percentage: 50.000%


Adding 2 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_cqpwiha4.log

file_count: File Count

buildtest can check for number of files in a directory. This can be useful if your test writes number of files and you want to check if the number of files is as expected. You can use the file_count property to perform file count. This property is a list of assertion, where each item is an object. The dir and count are required keys.

The dir is the path to directory to perform directory traversal, and count key is the number of expected files that will be used for comparison. In the first test, we perform a directory walk and expect 5 files in the directory. We can perform directory search based on file extension by using ext key. The ext property can be a string or a list. The second test will perform directory walk on directory named foo and search for file extensions .sh, .py, .txt. The depth property controls the maximum depth for directory traversal, this must be of an integer type. The depth property is optional and if not specified, we will perform full directory traversal.

buildspecs:
  file_count_on_directory:
    type: script
    executor: generic.local.bash
    description: file count check in directory
    run: |
      mkdir -p foo
      touch foo/{1..5}
    status:
      file_count:
        - dir: foo
          count: 5
  file_count_by_extension:
    type: script
    executor: generic.local.bash
    description: file count by extension
    run: |
      mkdir -p foo/bar
      touch foo/{1..5}.sh
      touch foo/bar/{1..3}.py foo/bar/{1..3}.txt
    status:
      file_count:
        - dir: foo
          ext: '.sh'
          depth: 1
          count: 5
        - dir: foo/bar
          ext: ['.py', '.txt']
          count: 6

We can run this test by running the following.

buildtest build -b tutorials/test_status/file_count.yml
$ buildtest build -b tutorials/test_status/file_count.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:29                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/file_count.yml                                         ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/file_count.yml: VALID
Total builder objects created: 2
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ file_cou │ script │ generic. │ None     │ None  │ None  │ file     │ /home/d │
│ nt_on_di │        │ local.ba │          │       │       │ count    │ ocs/che │
│ rectory/ │        │ sh       │          │       │       │ check in │ ckouts/ │
│ b772a3d3 │        │          │          │       │       │ director │ readthe │
│          │        │          │          │       │       │ y        │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_co │
│          │        │          │          │       │       │          │ unt.yml │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ file_cou │ script │ generic. │ None     │ None  │ None  │ file     │ /home/d │
│ nt_by_ex │        │ local.ba │          │       │       │ count by │ ocs/che │
│ tension/ │        │ sh       │          │       │       │ extensio │ ckouts/ │
│ 58a3b193 │        │          │          │       │       │ n        │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_co │
│          │        │          │          │       │       │          │ unt.yml │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_count_on_directory/b772a3d3: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_on_directory/b772a3d3
file_count_by_extension/58a3b193: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_by_extension/58a3b193
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_count_by_extension/58a3b193 does not have any dependencies adding test to queue
file_count_on_directory/b772a3d3 does not have any dependencies adding test to queue
      Builders Eligible to Run      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                          ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_count_by_extension/58a3b193 │
│ file_count_on_directory/b772a3d3 │
└──────────────────────────────────┘
file_count_by_extension/58a3b193: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_by_extension/58a3b193/stage
file_count_by_extension/58a3b193: Running Test via command: bash file_count_by_extension_build.sh
file_count_by_extension/58a3b193: Test completed in 0.00927 seconds with returncode: 0
file_count_by_extension/58a3b193: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_by_extension/58a3b193/file_count_by_extension.out
file_count_by_extension/58a3b193: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_by_extension/58a3b193/file_count_by_extension.err
file_count_by_extension/58a3b193: Found 5 file in directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_by_extension/58a3b193/stage/foo. Comparing with reference count: 5. Comparison check is 5 == 5 which evaluates to True
file_count_by_extension/58a3b193: Found 6 file in directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_by_extension/58a3b193/stage/foo/bar. Comparing with reference count: 6. Comparison check is 6 == 6 which evaluates to True
file_count_by_extension/58a3b193: File Count Check: True
file_count_on_directory/b772a3d3: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_on_directory/b772a3d3/stage
file_count_on_directory/b772a3d3: Running Test via command: bash file_count_on_directory_build.sh
file_count_on_directory/b772a3d3: Test completed in 0.007489 seconds with returncode: 0
file_count_on_directory/b772a3d3: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_on_directory/b772a3d3/file_count_on_directory.out
file_count_on_directory/b772a3d3: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_on_directory/b772a3d3/file_count_on_directory.err
file_count_on_directory/b772a3d3: Found 5 file in directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count/file_count_on_directory/b772a3d3/stage/foo. Comparing with reference count: 5. Comparison check is 5 == 5 which evaluates to True
file_count_on_directory/b772a3d3: File Count Check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_count_by_extension │ generic.local.bash │ PASS   │ 0          │ 0.009   │
│ /58a3b193               │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ file_count_on_directory │ generic.local.bash │ PASS   │ 0          │ 0.007   │
│ /b772a3d3               │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 2/2 Percentage: 100.000%
Failed Tests: 0/2 Percentage: 0.000%


Adding 2 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_n008byff.log

In the next example, we introduce filepattern property which allows you to check for files based on a pattern. The filepattern property is a regular expression which is compiled via re.compile and applied to a directory path. Please note the regular expression must be valid, otherwise buildtest will not return any files during directory traversal.

You can use filepattern and ext property together to search for files. If both are specified, then we will search for files with both methods and join the two list prior to performing comparison.

buildspecs:
  file_count_by_expression:
    type: script
    executor: generic.local.bash
    description: file count by expression
    run: |
      mkdir -p /tmp
      touch /tmp/foo{1..5}.txt
      ls -l /tmp/foo*.txt
      filenames=$(find $BUILDTEST_ROOT/buildtest -type f  \( -name "defaults.py" -o -name "main.py" \) -maxdepth 1)
      totalfiles=$(find $BUILDTEST_ROOT/buildtest -type f  \( -name "defaults.py" -o -name "main.py" \) -maxdepth 1 | wc -l)
      echo "Filenames: $filenames"
      echo "Total files: $totalfiles"
    status:
      file_count:
        - dir: /tmp
          filepattern: 'foo[1-5].txt$'
          count: 5
        - dir: '$BUILDTEST_ROOT/buildtest'
          filepattern: '(defaults|main).py$'
          count: 2
          depth: 1

  file_extension_and_filepattern:
    type: script
    executor: generic.local.bash
    description: file count by file extension and file pattern
    run: |
      touch foo{1..5}.txt
      touch {conf,main}.py
      ls -l
    status:
      file_count:
        - dir: .
          ext: '.txt'
          filepattern: '(conf|main).py$'
          count: 7

Let’s build this test by running the following:

buildtest build -b tutorials/test_status/file_count_pattern.yml
$ buildtest build -b tutorials/test_status/file_count_pattern.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:30                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/file_count_pattern.yml                                 ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/file_count_pattern.yml: VALID
Total builder objects created: 2
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ file_cou │ script │ generic. │ None     │ None  │ None  │ file     │ /home/d │
│ nt_by_ex │        │ local.ba │          │       │       │ count by │ ocs/che │
│ pression │        │ sh       │          │       │       │ expressi │ ckouts/ │
│ /65b3341 │        │          │          │       │       │ on       │ readthe │
│ 5        │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_co │
│          │        │          │          │       │       │          │ unt_pat │
│          │        │          │          │       │       │          │ tern.ym │
│          │        │          │          │       │       │          │ l       │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ file_ext │ script │ generic. │ None     │ None  │ None  │ file     │ /home/d │
│ ension_a │        │ local.ba │          │       │       │ count by │ ocs/che │
│ nd_filep │        │ sh       │          │       │       │ file     │ ckouts/ │
│ attern/2 │        │          │          │       │       │ extensio │ readthe │
│ 8619ff6  │        │          │          │       │       │ n and    │ docs.or │
│          │        │          │          │       │       │ file     │ g/user_ │
│          │        │          │          │       │       │ pattern  │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_co │
│          │        │          │          │       │       │          │ unt_pat │
│          │        │          │          │       │       │          │ tern.ym │
│          │        │          │          │       │       │          │ l       │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_count_by_expression/65b33415: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_pattern/file_count_by_expression/65b33415
file_extension_and_filepattern/28619ff6: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_pattern/file_extension_and_filepattern/28619ff6
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_count_by_expression/65b33415 does not have any dependencies adding test to queue
file_extension_and_filepattern/28619ff6 does not have any dependencies adding test to queue
         Builders Eligible to Run          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                                 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_count_by_expression/65b33415       │
│ file_extension_and_filepattern/28619ff6 │
└─────────────────────────────────────────┘
file_count_by_expression/65b33415: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_pattern/file_count_by_expression/65b33415/stage
file_count_by_expression/65b33415: Running Test via command: bash file_count_by_expression_build.sh
file_count_by_expression/65b33415: Test completed in 0.013122 seconds with returncode: 0
file_count_by_expression/65b33415: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_pattern/file_count_by_expression/65b33415/file_count_by_expression.out
file_count_by_expression/65b33415: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_pattern/file_count_by_expression/65b33415/file_count_by_expression.err
file_count_by_expression/65b33415: Found 5 file in directory: /tmp. Comparing with reference count: 5. Comparison check is 5 == 5 which evaluates to True
file_count_by_expression/65b33415: Found 2 file in directory: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/buildtest. Comparing with reference count: 2. Comparison check is 2 == 2 which evaluates to True
file_count_by_expression/65b33415: File Count Check: True
file_extension_and_filepattern/28619ff6: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_pattern/file_extension_and_filepattern/28619ff6/stage
file_extension_and_filepattern/28619ff6: Running Test via command: bash file_extension_and_filepattern_build.sh
file_extension_and_filepattern/28619ff6: Test completed in 0.00862 seconds with returncode: 0
file_extension_and_filepattern/28619ff6: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_pattern/file_extension_and_filepattern/28619ff6/file_extension_and_filepattern.out
file_extension_and_filepattern/28619ff6: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_pattern/file_extension_and_filepattern/28619ff6/file_extension_and_filepattern.err
file_extension_and_filepattern/28619ff6: Found 7 file in directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_pattern/file_extension_and_filepattern/28619ff6/stage. Comparing with reference count: 7. Comparison check is 7 == 7 which evaluates to True
file_extension_and_filepattern/28619ff6: File Count Check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_count_by_expressio │ generic.local.bash │ PASS   │ 0          │ 0.013   │
│ n/65b33415              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ file_extension_and_file │ generic.local.bash │ PASS   │ 0          │ 0.009   │
│ pattern/28619ff6        │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 2/2 Percentage: 100.000%
Failed Tests: 0/2 Percentage: 0.000%


Adding 2 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_oebgpj0i.log

In the next example, we will introduce filetype property that can be used to filter directory search based on file type. The filetype property can one of the following values file, dir, symlink. Once set, the directory traversal will seek out files based on the file type. Note that when filetype is set to dir we will return the parent directory and all sub-directories. This test will create a few subdirectories and create symbolic link, next we will perform directory search by directory and symbolic link. We expect this test to pass as we will find 3 directories and 2 symbolic links.

buildspecs:
  file_count_by_filetype:
    type: script
    executor: generic.local.bash
    description: Count the number of directories and symbolic links
    run: |
      mkdir -p foo/{bar,baz}
      find foo -type dir
      ln -s foo/bar foo/bar.link
      ln -s foo/baz foo/baz.link
    status:
      file_count:
        - dir: foo
          count: 3
          filetype: 'dir'
        - dir: foo
          count: 2
          filetype: 'symlink'

Let’s build this test by running the following:

buildtest build -b tutorials/test_status/file_count_filetype.yml
$ buildtest build -b tutorials/test_status/file_count_filetype.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:31                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/file_count_filetype.yml                                ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/file_count_filetype.yml: VALID
Total builder objects created: 1
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ file_cou │ script │ generic. │ None     │ None  │ None  │ Count    │ /home/d │
│ nt_by_fi │        │ local.ba │          │       │       │ the      │ ocs/che │
│ letype/d │        │ sh       │          │       │       │ number   │ ckouts/ │
│ 2c98002  │        │          │          │       │       │ of       │ readthe │
│          │        │          │          │       │       │ director │ docs.or │
│          │        │          │          │       │       │ ies and  │ g/user_ │
│          │        │          │          │       │       │ symbolic │ builds/ │
│          │        │          │          │       │       │ links    │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_co │
│          │        │          │          │       │       │          │ unt_fil │
│          │        │          │          │       │       │          │ etype.y │
│          │        │          │          │       │       │          │ ml      │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_count_by_filetype/d2c98002: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/d2c98002
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_count_by_filetype/d2c98002 does not have any dependencies adding test to queue
     Builders Eligible to Run      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                         ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_count_by_filetype/d2c98002 │
└─────────────────────────────────┘
file_count_by_filetype/d2c98002: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/d2c98002/stage
file_count_by_filetype/d2c98002: Running Test via command: bash file_count_by_filetype_build.sh
file_count_by_filetype/d2c98002: failed to submit job with returncode: 1
────────────── Error Message for file_count_by_filetype/d2c98002 ───────────────
find: Must separate multiple arguments to -type using: ','

file_count_by_filetype/d2c98002: Detected failure in running test, will attempt to retry test: 1 times
file_count_by_filetype/d2c98002: Run - 1/1
file_count_by_filetype/d2c98002: Running Test via command: bash file_count_by_filetype_build.sh
file_count_by_filetype/d2c98002: failed to submit job with returncode: 1
file_count_by_filetype/d2c98002: Test completed in 0.01963 seconds with returncode: 1
file_count_by_filetype/d2c98002: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/d2c98002/file_count_by_filetype.out
file_count_by_filetype/d2c98002: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/d2c98002/file_count_by_filetype.err
file_count_by_filetype/d2c98002: Found 3 file in directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/d2c98002/stage/foo. Comparing with reference count: 3. Comparison check is 3 == 3 which evaluates to True
file_count_by_filetype/d2c98002: Found 0 file in directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/d2c98002/stage/foo. Comparing with reference count: 2. Comparison check is 0 == 2 which evaluates to False
file_count_by_filetype/d2c98002: File Count Check: False
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_count_by_filetype/ │ generic.local.bash │ FAIL   │ 1          │ 0.020   │
│ d2c98002                │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 0/1 Percentage: 0.000%
Failed Tests: 1/1 Percentage: 100.000%


Adding 1 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_wxgcxtgm.log

Buildtest will perform a directory walk when using file_count, which can run into performance issues if you have a large directory. We have added a safety check during directory traversal to a maximum of 999999 files. You have the option to configure the directory traversal limit using file_traversal_limit which is an integer, the default value is 10000 if not specified. The minimum value and maximum value can be 1 and 999999 respectively.

In this next example, we will illustrate how this feature works. We will create 99 .txt files in directory foo. We will perform two assertions with different values for file_traversal_limit. In the first example, we will set this to 50 and expect 50 files returned. We expect this check to be True. In the next example, we will set file_traversal_limit to 20 and set count: 10 where we should expect a failure. In principle, we should retrieve 20 files but this will mismatch the comparison check.

buildspecs:
  file_traverse_limit:
    type: script
    executor: generic.local.bash
    description: Use of file_traverse_limit to limit number of files searched in a directory
    run: |
      mkdir foo
      touch foo/{1..99}.txt
    status:
      file_count:
        - dir: foo
          count: 50
          file_traverse_limit: 50
        - dir: foo
          count: 10
          file_traverse_limit: 20

We can try building this test by running the following:

buildtest build -b tutorials/test_status/file_count_file_traverse_limit.yml
$ buildtest build -b tutorials/test_status/file_count_file_traverse_limit.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:32                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/file_count_file_traverse_limit.yml                     ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/file_count_file_traverse_limit.yml: VALID
Total builder objects created: 1
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ file_tra │ script │ generic. │ None     │ None  │ None  │ Use of   │ /home/d │
│ verse_li │        │ local.ba │          │       │       │ file_tra │ ocs/che │
│ mit/e0f3 │        │ sh       │          │       │       │ verse_li │ ckouts/ │
│ f3f7     │        │          │          │       │       │ mit to   │ readthe │
│          │        │          │          │       │       │ limit    │ docs.or │
│          │        │          │          │       │       │ number   │ g/user_ │
│          │        │          │          │       │       │ of files │ builds/ │
│          │        │          │          │       │       │ searched │ buildte │
│          │        │          │          │       │       │ in a     │ st/chec │
│          │        │          │          │       │       │ director │ kouts/l │
│          │        │          │          │       │       │ y        │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_co │
│          │        │          │          │       │       │          │ unt_fil │
│          │        │          │          │       │       │          │ e_trave │
│          │        │          │          │       │       │          │ rse_lim │
│          │        │          │          │       │       │          │ it.yml  │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_traverse_limit/e0f3f3f7: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/e0f3f3f7
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_traverse_limit/e0f3f3f7 does not have any dependencies adding test to queue
    Builders Eligible to Run    
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                      ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_traverse_limit/e0f3f3f7 │
└──────────────────────────────┘
file_traverse_limit/e0f3f3f7: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/e0f3f3f7/stage
file_traverse_limit/e0f3f3f7: Running Test via command: bash file_traverse_limit_build.sh
file_traverse_limit/e0f3f3f7: Test completed in 0.009674 seconds with returncode: 0
file_traverse_limit/e0f3f3f7: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/e0f3f3f7/file_traverse_limit.out
file_traverse_limit/e0f3f3f7: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/e0f3f3f7/file_traverse_limit.err
file_traverse_limit/e0f3f3f7: Found 50 file in directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/e0f3f3f7/stage/foo. Comparing with reference count: 50. Comparison check is 50 == 50 which evaluates to True
file_traverse_limit/e0f3f3f7: Found 20 file in directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/e0f3f3f7/stage/foo. Comparing with reference count: 10. Comparison check is 20 == 10 which evaluates to False
file_traverse_limit/e0f3f3f7: File Count Check: False
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_traverse_limit/e0f │ generic.local.bash │ FAIL   │ 0          │ 0.010   │
│ 3f3f7                   │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 0/1 Percentage: 0.000%
Failed Tests: 1/1 Percentage: 100.000%


Adding 1 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_urgmk89c.log

mode: Change Status Check Behavior to Logical AND/OR

By default, the status check performed by buildtest is a logical OR, where if any of the status check is True, then the test will PASS. However, if you want to change this behavior to logical AND, you can use the mode property. The valid values can be [AND, and, OR, or]. In the example below, we have two tests that illustrate the use of mode.

buildspecs:
  status_logical_and:
    type: script
    executor: 'generic.local.bash'
    description: 'Using logical AND to check status'
    run: |
      echo "This is a test"
      exit 1
    status:
      mode: and
      returncode: 1
      regex:
        stream: stdout
        exp: 'This is a test'

  status_logical_or:
    type: script
    executor: 'generic.local.bash'
    description: 'Using logical OR to check status'
    run: |
      echo "This is a test"
      exit 1
    status:
      mode: or
      returncode: 0
      regex:
        stream: stdout
        exp: 'This is a test'

The first test uses mode: and which implies all status check are evaluated as logical AND, we expect this test to PASS. In the second test, we use mode: or where status check are evaluated as logical OR which is the default behavior. Note if mode is not specified, it is equivalent to mode: or. In second test, we expect this to pass because regex check will PASS however, the returncode check will fail due to mismatch in returncode. If we changed this to mode: and then we would expect this test to fail.

Shown below is the output of running this test.

buildtest build -b tutorials/test_status/mode.yml
$ buildtest build -b tutorials/test_status/mode.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:32                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/mode.yml                                               ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/mode.yml: VALID
Total builder objects created: 2
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ status_l │ script │ generic. │ None     │ None  │ None  │ Using    │ /home/d │
│ ogical_a │        │ local.ba │          │       │       │ logical  │ ocs/che │
│ nd/358b6 │        │ sh       │          │       │       │ AND to   │ ckouts/ │
│ 33b      │        │          │          │       │       │ check    │ readthe │
│          │        │          │          │       │       │ status   │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ mode.ym │
│          │        │          │          │       │       │          │ l       │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ status_l │ script │ generic. │ None     │ None  │ None  │ Using    │ /home/d │
│ ogical_o │        │ local.ba │          │       │       │ logical  │ ocs/che │
│ r/b6e5db │        │ sh       │          │       │       │ OR to    │ ckouts/ │
│ 78       │        │          │          │       │       │ check    │ readthe │
│          │        │          │          │       │       │ status   │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ mode.ym │
│          │        │          │          │       │       │          │ l       │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
status_logical_and/358b633b: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/mode/status_logical_and/358b633b
status_logical_or/b6e5db78: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/mode/status_logical_or/b6e5db78
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
status_logical_and/358b633b does not have any dependencies adding test to queue
status_logical_or/b6e5db78 does not have any dependencies adding test to queue
   Builders Eligible to Run    
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                     ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ status_logical_and/358b633b │
│ status_logical_or/b6e5db78  │
└─────────────────────────────┘
status_logical_and/358b633b: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/mode/status_logical_and/358b633b/stage
status_logical_and/358b633b: Running Test via command: bash status_logical_and_build.sh
status_logical_and/358b633b: failed to submit job with returncode: 1
──────────────── Error Message for status_logical_and/358b633b ─────────────────

status_logical_and/358b633b: Detected failure in running test, will attempt to retry test: 1 times
status_logical_and/358b633b: Run - 1/1
status_logical_and/358b633b: Running Test via command: bash status_logical_and_build.sh
status_logical_and/358b633b: failed to submit job with returncode: 1
status_logical_and/358b633b: Test completed in 0.014581 seconds with returncode: 1
status_logical_and/358b633b: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/mode/status_logical_and/358b633b/status_logical_and.out
status_logical_and/358b633b: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/mode/status_logical_and/358b633b/status_logical_and.err
status_logical_and/358b633b: Checking returncode - 1 is matched in list [1]
status_logical_and/358b633b: performing regular expression - 'This is a test' on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/mode/status_logical_and/358b633b/status_logical_and.out
status_logical_and/358b633b: Regular Expression Match - Success!
status_logical_or/b6e5db78: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/mode/status_logical_or/b6e5db78/stage
status_logical_or/b6e5db78: Running Test via command: bash status_logical_or_build.sh
status_logical_or/b6e5db78: failed to submit job with returncode: 1
───────────────── Error Message for status_logical_or/b6e5db78 ─────────────────

status_logical_or/b6e5db78: Detected failure in running test, will attempt to retry test: 1 times
status_logical_or/b6e5db78: Run - 1/1
status_logical_or/b6e5db78: Running Test via command: bash status_logical_or_build.sh
status_logical_or/b6e5db78: failed to submit job with returncode: 1
status_logical_or/b6e5db78: Test completed in 0.013684 seconds with returncode: 1
status_logical_or/b6e5db78: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/mode/status_logical_or/b6e5db78/status_logical_or.out
status_logical_or/b6e5db78: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/mode/status_logical_or/b6e5db78/status_logical_or.err
status_logical_or/b6e5db78: Checking returncode - 1 is matched in list [0]
status_logical_or/b6e5db78: performing regular expression - 'This is a test' on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/mode/status_logical_or/b6e5db78/status_logical_or.out
status_logical_or/b6e5db78: Regular Expression Match - Success!
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ status_logical_or/b6e5d │ generic.local.bash │ PASS   │ 1          │ 0.014   │
│ b78                     │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ status_logical_and/358b │ generic.local.bash │ PASS   │ 1          │ 0.015   │
│ 633b                    │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 2/2 Percentage: 100.000%
Failed Tests: 0/2 Percentage: 0.000%


Adding 2 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_uxqy9ore.log

linecount: Line Count on Stdout/Stderr

This check counts the number of lines in stdout or stderr and compares with reference count. This can be useful if you want to make a test pass based on number of lines. buildtest will split lines by newline character and perform the comparison.

In the example below we will write 10 lines to standard output (stdout) and use the linecount status check to perform a comparison using the reference count of 10. The linecount is an object which requires the fields: stream and count. The stream can be stdout or stderr and count is the reference count to compare against. This must be an integer value and greater than 0. In second test we will compare output with standard error (stream: stderr) and compare with reference count of 5. Since the output is going to write 10 lines to error file we should expect the second test to fail.

buildspecs:
  linecount_stdout:
    type: script
    executor: generic.local.bash
    description: "Write 10 lines to stdout and run linecount check"
    run: |      
      for i in {1..10}; do
        echo $i
      done
    status:
      linecount:
        stream: stdout
        count: 10

  linecount_stderr_mismatch:
    type: script
    executor: generic.local.bash
    description: "Write 10 lines to stderr and run linecount check"
    run: |      
      for i in {1..10}; do
        echo $i >&2
      done
    status:
      linecount:
        stream: stderr
        count: 5

Let’s try building this test and you will see the test will pass based on line count comparison.

buildtest build -b tutorials/test_status/linecount.yml
$ buildtest build -b tutorials/test_status/linecount.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:33                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/linecount.yml                                          ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/linecount.yml: VALID
Total builder objects created: 2
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ linecoun │ script │ generic. │ None     │ None  │ None  │ Write 10 │ /home/d │
│ t_stdout │        │ local.ba │          │       │       │ lines to │ ocs/che │
│ /3bf48ac │        │ sh       │          │       │       │ stdout   │ ckouts/ │
│ 9        │        │          │          │       │       │ and run  │ readthe │
│          │        │          │          │       │       │ linecoun │ docs.or │
│          │        │          │          │       │       │ t check  │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ linecou │
│          │        │          │          │       │       │          │ nt.yml  │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ linecoun │ script │ generic. │ None     │ None  │ None  │ Write 10 │ /home/d │
│ t_stderr │        │ local.ba │          │       │       │ lines to │ ocs/che │
│ _mismatc │        │ sh       │          │       │       │ stderr   │ ckouts/ │
│ h/11d077 │        │          │          │       │       │ and run  │ readthe │
│ b8       │        │          │          │       │       │ linecoun │ docs.or │
│          │        │          │          │       │       │ t check  │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ linecou │
│          │        │          │          │       │       │          │ nt.yml  │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
linecount_stdout/3bf48ac9: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stdout/3bf48ac9
linecount_stderr_mismatch/11d077b8: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/11d077b8
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
linecount_stdout/3bf48ac9 does not have any dependencies adding test to queue
linecount_stderr_mismatch/11d077b8 does not have any dependencies adding test to queue
       Builders Eligible to Run       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ linecount_stdout/3bf48ac9          │
│ linecount_stderr_mismatch/11d077b8 │
└────────────────────────────────────┘
linecount_stdout/3bf48ac9: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stdout/3bf48ac9/stage
linecount_stdout/3bf48ac9: Running Test via command: bash linecount_stdout_build.sh
linecount_stdout/3bf48ac9: Test completed in 0.005974 seconds with returncode: 0
linecount_stdout/3bf48ac9: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stdout/3bf48ac9/linecount_stdout.out
linecount_stdout/3bf48ac9: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stdout/3bf48ac9/linecount_stdout.err
linecount_stdout/3bf48ac9: Performing line count check on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stdout/3bf48ac9/linecount_stdout.out with 10 (ref count) == 10 (actual count). linecount Check: True
linecount_stderr_mismatch/11d077b8: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/11d077b8/stage
linecount_stderr_mismatch/11d077b8: Running Test via command: bash linecount_stderr_mismatch_build.sh
linecount_stderr_mismatch/11d077b8: Test completed in 0.005462 seconds with returncode: 0
linecount_stderr_mismatch/11d077b8: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/11d077b8/linecount_stderr_mismatch.out
linecount_stderr_mismatch/11d077b8: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/11d077b8/linecount_stderr_mismatch.err
linecount_stderr_mismatch/11d077b8: Performing line count check on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/11d077b8/linecount_stderr_mismatch.err with 5 (ref count) == 10 (actual count). linecount Check: False
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ linecount_stderr_mismat │ generic.local.bash │ FAIL   │ 0          │ 0.005   │
│ ch/11d077b8             │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ linecount_stdout/3bf48a │ generic.local.bash │ PASS   │ 0          │ 0.006   │
│ c9                      │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 1/2 Percentage: 50.000%
Failed Tests: 1/2 Percentage: 50.000%


Adding 2 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_5pmtp7wi.log

We can inspect the output and error file for each corresponding test and we will notice that both tests will contain 10 lines of output.

$ buildtest inspect query -o linecount_stdout
──────────── linecount_stdout/3bf48ac9-2562-48ee-9464-8d26b464959e ─────────────
Executor: generic.local.bash
Description: Write 10 lines to stdout and run linecount check
State: PASS
Returncode: 0
Runtime: 0.005974 sec
Starttime: 2024/04/30 14:32:33
Endtime: 2024/04/30 14:32:33
Command: bash linecount_stdout_build.sh
Test Script: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stdout/3bf48ac9/linecount_stdout.sh
Build Script: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stdout/3bf48ac9/linecount_stdout_build.sh
Output File: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stdout/3bf48ac9/linecount_stdout.out
Error File: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stdout/3bf48ac9/linecount_stdout.err
Log File: /tmp/tmpu6myg391/var/logs/buildtest_5pmtp7wi.log
─ Output File:  /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linec… ─
1                                                                               
2                                                                               
3                                                                               
4                                                                               
5                                                                               
6                                                                               
7                                                                               
8                                                                               
9                                                                               
10
$ buildtest inspect query -e linecount_stderr_mismatch
──────── linecount_stderr_mismatch/11d077b8-e32b-4b7f-bf4c-5cbcb9d464c2 ────────
Executor: generic.local.bash
Description: Write 10 lines to stderr and run linecount check
State: FAIL
Returncode: 0
Runtime: 0.005462 sec
Starttime: 2024/04/30 14:32:33
Endtime: 2024/04/30 14:32:33
Command: bash linecount_stderr_mismatch_build.sh
Test Script: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/11d077b8/linecount_stderr_mismatch.sh
Build Script: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/11d077b8/linecount_stderr_mismatch_build.sh
Output File: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/11d077b8/linecount_stderr_mismatch.out
Error File: /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/11d077b8/linecount_stderr_mismatch.err
Log File: /tmp/tmpu6myg391/var/logs/buildtest_5pmtp7wi.log
─ Error File:  /tmp/tmpu6myg391/var/tests/generic.local.bash/linecount/lineco… ─
1                                                                               
2                                                                               
3                                                                               
4                                                                               
5                                                                               
6                                                                               
7                                                                               
8                                                                               
9                                                                               
10

file_linecount: Line Count on File

The file_linecount status check is similar to linecount: Line Count on Stdout/Stderr but instead of comparing output from stdout or stderr, it compares output from a file. This is useful if you want to compare output from a file with a reference count. The file_linecount is an array of objects which requires the fields: file and count. The file is the path to file and count is the reference count to compare against.

To demonstrate this feature we will write 10 lines to a file named count.txt and write output of one echo statement to file hello.txt. We will use file_linecount field to read both files and compare with reference count. We expect both checks to pass.

buildspecs:
  file_linecount:
    type: script
    executor: generic.local.bash
    description: "Perform linecount comparison on files"
    run: |
      for i in {1..10}; do
        echo $i >> count.txt
      done
      echo "hello world" > hello.txt
    status:
      file_linecount:
        - file: count.txt
          count: 10
        - file: hello.txt
          count: 1

Let’s try building this test and you will see in the build output comparison check is performed on both files. Buildtest will perform a logical AND operation when comparing multiple files for linecount match.

buildtest build -b tutorials/test_status/file_linecount.yml
$ buildtest build -b tutorials/test_status/file_linecount.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:34                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/file_linecount.yml                                     ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/file_linecount.yml: VALID
Total builder objects created: 1
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ file_lin │ script │ generic. │ None     │ None  │ None  │ Perform  │ /home/d │
│ ecount/a │        │ local.ba │          │       │       │ linecoun │ ocs/che │
│ 3f785ba  │        │ sh       │          │       │       │ t        │ ckouts/ │
│          │        │          │          │       │       │ comparis │ readthe │
│          │        │          │          │       │       │ on on    │ docs.or │
│          │        │          │          │       │       │ files    │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_li │
│          │        │          │          │       │       │          │ necount │
│          │        │          │          │       │       │          │ .yml    │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_linecount/a3f785ba: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_linecount/file_linecount/a3f785ba
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_linecount/a3f785ba does not have any dependencies adding test to queue
 Builders Eligible to Run  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_linecount/a3f785ba │
└─────────────────────────┘
file_linecount/a3f785ba: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_linecount/file_linecount/a3f785ba/stage
file_linecount/a3f785ba: Running Test via command: bash file_linecount_build.sh
file_linecount/a3f785ba: Test completed in 0.005886 seconds with returncode: 0
file_linecount/a3f785ba: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_linecount/file_linecount/a3f785ba/file_linecount.out
file_linecount/a3f785ba: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_linecount/file_linecount/a3f785ba/file_linecount.err
file_linecount/a3f785ba: Performing line count check on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_linecount/file_linecount/a3f785ba/stage/count.txt with 10 (ref count) == 10 (actual count). linecount Check: True
file_linecount/a3f785ba: Performing line count check on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_linecount/file_linecount/a3f785ba/stage/hello.txt with 1 (ref count) == 1 (actual count). linecount Check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_linecount/a3f785ba │ generic.local.bash │ PASS   │ 0          │ 0.006   │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 1/1 Percentage: 100.000%
Failed Tests: 0/1 Percentage: 0.000%


Adding 1 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_15t5dvo3.log

The file property must be a valid file that is readable, if you specify a directory name or non-existent file then buildtest will be unable to read the file, hence test will fail to perform comparison. In this next example, we perform a comparison on file: /tmp and file: badfile.txt both of which are invalid for file comparison.

buildspecs:
  file_linecount_exceptions:
    type: script
    executor: generic.local.bash
    description: "Performing file count on directory or invalid files can result in failure"
    run: |
      for i in {1..10}; do
        echo $i >> count.txt
      done
      echo "hello world" > hello.txt
    status:
      file_linecount:
        - file: /tmp
          count: 10
        - file: /badfile.txt
          count: 1

Buildtest will be able to run the test; however, the test will fail because its unable to read the files to get actual line count for comparison.

buildtest build -b tutorials/test_status/file_linecount_failure.yml
$ buildtest build -b tutorials/test_status/file_linecount_failure.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:35                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/file_linecount_failure.yml                             ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/file_linecount_failure.yml: VALID
Total builder objects created: 1
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ file_lin │ script │ generic. │ None     │ None  │ None  │ Performi │ /home/d │
│ ecount_e │        │ local.ba │          │       │       │ ng file  │ ocs/che │
│ xception │        │ sh       │          │       │       │ count on │ ckouts/ │
│ s/7f027b │        │          │          │       │       │ director │ readthe │
│ 7a       │        │          │          │       │       │ y or     │ docs.or │
│          │        │          │          │       │       │ invalid  │ g/user_ │
│          │        │          │          │       │       │ files    │ builds/ │
│          │        │          │          │       │       │ can      │ buildte │
│          │        │          │          │       │       │ result   │ st/chec │
│          │        │          │          │       │       │ in       │ kouts/l │
│          │        │          │          │       │       │ failure  │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_li │
│          │        │          │          │       │       │          │ necount │
│          │        │          │          │       │       │          │ _failur │
│          │        │          │          │       │       │          │ e.yml   │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_linecount_exceptions/7f027b7a: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/file_linecount_failure/file_linecount_exceptions/7f027b7a
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_linecount_exceptions/7f027b7a does not have any dependencies adding test to queue
       Builders Eligible to Run       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_linecount_exceptions/7f027b7a │
└────────────────────────────────────┘
file_linecount_exceptions/7f027b7a: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/file_linecount_failure/file_linecount_exceptions/7f027b7a/stage
file_linecount_exceptions/7f027b7a: Running Test via command: bash file_linecount_exceptions_build.sh
file_linecount_exceptions/7f027b7a: Test completed in 0.006126 seconds with returncode: 0
file_linecount_exceptions/7f027b7a: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/file_linecount_failure/file_linecount_exceptions/7f027b7a/file_linecount_exceptions.out
file_linecount_exceptions/7f027b7a: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/file_linecount_failure/file_linecount_exceptions/7f027b7a/file_linecount_exceptions.err
file_linecount_exceptions/7f027b7a: File: /tmp is not a file
file_linecount_exceptions/7f027b7a: Unable to resolve file path: /badfile.txt
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_linecount_exceptio │ generic.local.bash │ FAIL   │ 0          │ 0.006   │
│ ns/7f027b7a             │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 0/1 Percentage: 0.000%
Failed Tests: 1/1 Percentage: 100.000%


Adding 1 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_f5sph5ky.log

Finally, we must note that line count is expected to be 0 or greater, if you specify a negative value for count then buildtest will raise an error according to the JSON schema.

buildspecs:
  file_linecount_negative_value:
    type: script
    executor: generic.local.bash
    description: "Performing file count with a negative count value will result in error"
    run: |
      > empty.txt
    status:
      file_linecount:
      - file: empty.txt
        count: -1

We will simply try validating this buildspec and you will see the error message from the JSON schema

buildtest buildspec validate -b tutorials/test_status/file_linecount_invalid.yml
$ buildtest buildspec validate -b tutorials/test_status/file_linecount_invalid.yml
─ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest… ─
-1 is less than the minimum of 0

Failed validating 'minimum' in schema['properties']['status']['properties']['file_linecount']['items']['properties']['count']:
    {'description': 'Specify number of lines as reference value to compare '
                    'with actual output',
     'minimum': 0,
     'type': 'integer'}

On instance['status']['file_linecount'][0]['count']:
    -1


1 buildspecs failed to validate

re: Modify regular expression method

The re property can be used to select the type of regular expression to use with regex or file_regex which can be re.search, re.match or re.fullmatch. The re property is a string type which is used to select the regular expression function to use. In this next example, we will demonstrate the use of this feature with both regex and file_regex. The re property is optional and if not specified it defaults to re.search.

Since re.search will search for text at any position in the string, the first test re.search.stdout will match the string is with the output. In the second test re.match.stdout we use re.match which matches from beginning of string with input pattern is with output. We expect this match to FAIL since the output starts with This is ….

In the third test re.fullmatch.stdout we set re: re.fullmatch which will match the entire string with the pattern. We expect this match to PASS since the output and pattern are exactly the same. In the fourth test match_on_file_regex we have have three regular expression, one for each type re.search, re.match and re.fullmatch. All of these expressions will find a match and this test will PASS.

buildspecs:
  re.search.stdout:
    executor: generic.local.bash
    type: script
    description: Test re.search on stdout
    run: echo "This is a string"
    status:
      regex:
        stream: stdout
        exp: 'is'
        re: "re.search"

  re.match.stdout:
    executor: generic.local.bash
    type: script
    description: Test re.match on stdout
    run: echo "This is a string"
    status:
      regex:
        stream: stdout
        exp: 'is'
        re: "re.match"

  re.fullmatch.stdout:
    executor: generic.local.bash
    type: script
    description: Test re.fullmatch on stdout
    run: echo "This is a string"
    status:
      regex:
        stream: stdout
        exp: 'This is a string'
        re: "re.fullmatch"

  re.match_on_file_regex:
    executor: generic.local.bash
    type: script
    description: Test re.match on file regex
    run: |
      echo "This is a string" > file.txt
      echo "Hello World" > hello.txt
    status:
      file_regex:
        - file: file.txt
          exp: 'string'
          re: "re.search"
        - file: hello.txt
          exp: 'Hello'
          re: "re.match"
        - file: hello.txt
          exp: 'Hello World'
          re: "re.fullmatch"

Let’s try running this test example and see the generated output, all test should pass with exception of re.match.stdout.

buildtest build -b tutorials/test_status/specify_regex_type.yml
$ buildtest build -b tutorials/test_status/specify_regex_type.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-24235154-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/04/30 14:32:36                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.0                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.8.18                                                   │
│ Configuration File: /tmp/tmpu6myg391/config.yml                              │
│ Test Directory:     /tmp/tmpu6myg391/var/tests                               │
│ Report File:        /tmp/tmpu6myg391/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/ ║
║ tutorials/test_status/specify_regex_type.yml                                 ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/latest/tutorials/test_status/specify_regex_type.yml: VALID
Total builder objects created: 4
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ re.searc │ script │ generic. │ None     │ None  │ None  │ Test     │ /home/d │
│ h.stdout │        │ local.ba │          │       │       │ re.searc │ ocs/che │
│ /b7cac12 │        │ sh       │          │       │       │ h on     │ ckouts/ │
│ c        │        │          │          │       │       │ stdout   │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ specify │
│          │        │          │          │       │       │          │ _regex_ │
│          │        │          │          │       │       │          │ type.ym │
│          │        │          │          │       │       │          │ l       │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ re.match │ script │ generic. │ None     │ None  │ None  │ Test     │ /home/d │
│ .stdout/ │        │ local.ba │          │       │       │ re.match │ ocs/che │
│ 9e35d8be │        │ sh       │          │       │       │ on       │ ckouts/ │
│          │        │          │          │       │       │ stdout   │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ specify │
│          │        │          │          │       │       │          │ _regex_ │
│          │        │          │          │       │       │          │ type.ym │
│          │        │          │          │       │       │          │ l       │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ re.fullm │ script │ generic. │ None     │ None  │ None  │ Test     │ /home/d │
│ atch.std │        │ local.ba │          │       │       │ re.fullm │ ocs/che │
│ out/263d │        │ sh       │          │       │       │ atch on  │ ckouts/ │
│ 009a     │        │          │          │       │       │ stdout   │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ specify │
│          │        │          │          │       │       │          │ _regex_ │
│          │        │          │          │       │       │          │ type.ym │
│          │        │          │          │       │       │          │ l       │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ re.match │ script │ generic. │ None     │ None  │ None  │ Test     │ /home/d │
│ _on_file │        │ local.ba │          │       │       │ re.match │ ocs/che │
│ _regex/d │        │ sh       │          │       │       │ on file  │ ckouts/ │
│ 79885a5  │        │          │          │       │       │ regex    │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/l │
│          │        │          │          │       │       │          │ atest/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ specify │
│          │        │          │          │       │       │          │ _regex_ │
│          │        │          │          │       │       │          │ type.ym │
│          │        │          │          │       │       │          │ l       │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
re.search.stdout/b7cac12c: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.search.stdout/b7cac12c
re.match.stdout/9e35d8be: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match.stdout/9e35d8be
re.fullmatch.stdout/263d009a: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.fullmatch.stdout/263d009a
re.match_on_file_regex/d79885a5: Creating Test Directory: /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/d79885a5
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
re.match.stdout/9e35d8be does not have any dependencies adding test to queue
re.search.stdout/b7cac12c does not have any dependencies adding test to queue
re.match_on_file_regex/d79885a5 does not have any dependencies adding test to queue
re.fullmatch.stdout/263d009a does not have any dependencies adding test to queue
     Builders Eligible to Run      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                         ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ re.match.stdout/9e35d8be        │
│ re.search.stdout/b7cac12c       │
│ re.match_on_file_regex/d79885a5 │
│ re.fullmatch.stdout/263d009a    │
└─────────────────────────────────┘
re.match.stdout/9e35d8be: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match.stdout/9e35d8be/stage
re.match.stdout/9e35d8be: Running Test via command: bash re.match.stdout_build.sh
re.match.stdout/9e35d8be: Test completed in 0.005675 seconds with returncode: 0
re.match.stdout/9e35d8be: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match.stdout/9e35d8be/re.match.stdout.out
re.match.stdout/9e35d8be: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match.stdout/9e35d8be/re.match.stdout.err
re.match.stdout/9e35d8be: performing regular expression - 'is' on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match.stdout/9e35d8be/re.match.stdout.out
re.match.stdout/9e35d8be: Regular Expression Match - Failed!
re.search.stdout/b7cac12c: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.search.stdout/b7cac12c/stage
re.search.stdout/b7cac12c: Running Test via command: bash re.search.stdout_build.sh
re.search.stdout/b7cac12c: Test completed in 0.005355 seconds with returncode: 0
re.search.stdout/b7cac12c: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.search.stdout/b7cac12c/re.search.stdout.out
re.search.stdout/b7cac12c: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.search.stdout/b7cac12c/re.search.stdout.err
re.search.stdout/b7cac12c: performing regular expression - 'is' on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.search.stdout/b7cac12c/re.search.stdout.out
re.search.stdout/b7cac12c: Regular Expression Match - Success!
re.match_on_file_regex/d79885a5: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/d79885a5/stage
re.match_on_file_regex/d79885a5: Running Test via command: bash re.match_on_file_regex_build.sh
re.match_on_file_regex/d79885a5: Test completed in 0.005478 seconds with returncode: 0
re.match_on_file_regex/d79885a5: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/d79885a5/re.match_on_file_regex.out
re.match_on_file_regex/d79885a5: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/d79885a5/re.match_on_file_regex.err
re.match_on_file_regex/d79885a5: Performing regex expression 'string' on file /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/d79885a5/stage/file.txt
re.match_on_file_regex/d79885a5: Regular expression on file /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/d79885a5/stage/file.txt is a MATCH!
re.match_on_file_regex/d79885a5: Performing regex expression 'Hello' on file /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/d79885a5/stage/hello.txt
re.match_on_file_regex/d79885a5: Regular expression on file /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/d79885a5/stage/hello.txt is a MATCH!
re.match_on_file_regex/d79885a5: Performing regex expression 'Hello World' on file /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/d79885a5/stage/hello.txt
re.match_on_file_regex/d79885a5: Regular expression on file /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/d79885a5/stage/hello.txt is a MATCH!
re.fullmatch.stdout/263d009a: Current Working Directory : /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.fullmatch.stdout/263d009a/stage
re.fullmatch.stdout/263d009a: Running Test via command: bash re.fullmatch.stdout_build.sh
re.fullmatch.stdout/263d009a: Test completed in 0.005289 seconds with returncode: 0
re.fullmatch.stdout/263d009a: Writing output file -  /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.fullmatch.stdout/263d009a/re.fullmatch.stdout.out
re.fullmatch.stdout/263d009a: Writing error file - /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.fullmatch.stdout/263d009a/re.fullmatch.stdout.err
re.fullmatch.stdout/263d009a: performing regular expression - 'This is a string' on file: /tmp/tmpu6myg391/var/tests/generic.local.bash/specify_regex_type/re.fullmatch.stdout/263d009a/re.fullmatch.stdout.out
re.fullmatch.stdout/263d009a: Regular Expression Match - Success!
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ re.search.stdout/b7cac1 │ generic.local.bash │ PASS   │ 0          │ 0.005   │
│ 2c                      │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ re.match.stdout/9e35d8b │ generic.local.bash │ FAIL   │ 0          │ 0.006   │
│ e                       │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ re.fullmatch.stdout/263 │ generic.local.bash │ PASS   │ 0          │ 0.005   │
│ d009a                   │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ re.match_on_file_regex/ │ generic.local.bash │ PASS   │ 0          │ 0.005   │
│ d79885a5                │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



Passed Tests: 3/4 Percentage: 75.000%
Failed Tests: 1/4 Percentage: 25.000%


Adding 4 test results to report file: /tmp/tmpu6myg391/var/report.json
Writing Logfile to /tmp/tmpu6myg391/var/logs/buildtest_fv9blejf.log