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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:09                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/650fb │        │ local.ba │          │       │       │ by       │ ocs/che │
│ 923      │        │ sh       │          │       │       │ default  │ ckouts/ │
│          │        │          │          │       │       │ is FAIL  │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ pass_re │
│          │        │          │          │       │       │          │ turncod │
│          │        │          │          │       │       │          │ e.yml   │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ exit1_pa │ script │ generic. │ None     │ None  │ None  │ report   │ /home/d │
│ ss/17a93 │        │ local.ba │          │       │       │ exit 1   │ ocs/che │
│ b31      │        │ sh       │          │       │       │ as PASS  │ ckouts/ │
│          │        │          │          │       │       │          │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/ │
│ /f50b67e │        │          │          │       │       │ failed   │ readthe │
│ 2        │        │          │          │       │       │ to match │ docs.or │
│          │        │          │          │       │       │ returnco │ g/user_ │
│          │        │          │          │       │       │ de 1     │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/d0c │        │ sh       │          │       │       │ returnco │ ckouts/ │
│ b8641    │        │          │          │       │       │ de 128   │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ pass_re │
│          │        │          │          │       │       │          │ turncod │
│          │        │          │          │       │       │          │ e.yml   │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
exit1_fail/650fb923: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/exit1_fail/650fb923
exit1_pass/17a93b31: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/exit1_pass/17a93b31
returncode_list_mismatch/f50b67e2: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/returncode_list_mismatch/f50b67e2
returncode_int_match/d0cb8641: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/returncode_int_match/d0cb8641
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
returncode_int_match/d0cb8641 does not have any dependencies adding test to queue
exit1_pass/17a93b31 does not have any dependencies adding test to queue
exit1_fail/650fb923 does not have any dependencies adding test to queue
returncode_list_mismatch/f50b67e2 does not have any dependencies adding test to queue
      Builders Eligible to Run       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ returncode_int_match/d0cb8641     │
│ exit1_pass/17a93b31               │
│ exit1_fail/650fb923               │
│ returncode_list_mismatch/f50b67e2 │
└───────────────────────────────────┘
returncode_int_match/d0cb8641: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/returncode_int_match/d0cb8641/stage
returncode_int_match/d0cb8641: Running Test via command: bash returncode_int_match_build.sh
returncode_int_match/d0cb8641: failed to submit job with returncode: 128
returncode_int_match/d0cb8641: Detected failure in running test, will attempt to retry test: 1 times
returncode_int_match/d0cb8641: Run - 1/1
returncode_int_match/d0cb8641: Running Test via command: bash returncode_int_match_build.sh
returncode_int_match/d0cb8641: failed to submit job with returncode: 128
returncode_int_match/d0cb8641: Test completed in 0.020919 seconds with returncode: 128
returncode_int_match/d0cb8641: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/returncode_int_match/d0cb8641/returncode_int_match.out
returncode_int_match/d0cb8641: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/returncode_int_match/d0cb8641/returncode_int_match.err
returncode_int_match/d0cb8641: Checking returncode - 128 is matched in list [128]
exit1_pass/17a93b31: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/exit1_pass/17a93b31/stage
exit1_pass/17a93b31: Running Test via command: bash exit1_pass_build.sh
exit1_pass/17a93b31: failed to submit job with returncode: 1
exit1_pass/17a93b31: Detected failure in running test, will attempt to retry test: 1 times
exit1_pass/17a93b31: Run - 1/1
exit1_pass/17a93b31: Running Test via command: bash exit1_pass_build.sh
exit1_pass/17a93b31: failed to submit job with returncode: 1
exit1_pass/17a93b31: Test completed in 0.024824 seconds with returncode: 1
exit1_pass/17a93b31: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/exit1_pass/17a93b31/exit1_pass.out
exit1_pass/17a93b31: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/exit1_pass/17a93b31/exit1_pass.err
exit1_pass/17a93b31: Checking returncode - 1 is matched in list [1]
exit1_fail/650fb923: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/exit1_fail/650fb923/stage
exit1_fail/650fb923: Running Test via command: bash exit1_fail_build.sh
exit1_fail/650fb923: failed to submit job with returncode: 1
exit1_fail/650fb923: Detected failure in running test, will attempt to retry test: 1 times
exit1_fail/650fb923: Run - 1/1
exit1_fail/650fb923: Running Test via command: bash exit1_fail_build.sh
exit1_fail/650fb923: failed to submit job with returncode: 1
exit1_fail/650fb923: Test completed in 0.020278 seconds with returncode: 1
exit1_fail/650fb923: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/exit1_fail/650fb923/exit1_fail.out
exit1_fail/650fb923: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/exit1_fail/650fb923/exit1_fail.err
returncode_list_mismatch/f50b67e2: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/returncode_list_mismatch/f50b67e2/stage
returncode_list_mismatch/f50b67e2: Running Test via command: bash returncode_list_mismatch_build.sh
returncode_list_mismatch/f50b67e2: failed to submit job with returncode: 2
returncode_list_mismatch/f50b67e2: Detected failure in running test, will attempt to retry test: 1 times
returncode_list_mismatch/f50b67e2: Run - 1/1
returncode_list_mismatch/f50b67e2: Running Test via command: bash returncode_list_mismatch_build.sh
returncode_list_mismatch/f50b67e2: failed to submit job with returncode: 2
returncode_list_mismatch/f50b67e2: Test completed in 0.021153 seconds with returncode: 2
returncode_list_mismatch/f50b67e2: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/returncode_list_mismatch/f50b67e2/returncode_list_mismatch.out
returncode_list_mismatch/f50b67e2: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/pass_returncode/returncode_list_mismatch/f50b67e2/returncode_list_mismatch.err
returncode_list_mismatch/f50b67e2: Checking returncode - 2 is matched in list [1, 3]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ returncode_list_mismatc │ generic.local.bash │ FAIL   │ 2          │ 0.021   │
│ h/f50b67e2              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ exit1_pass/17a93b31     │ generic.local.bash │ PASS   │ 1          │ 0.025   │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ exit1_fail/650fb923     │ generic.local.bash │ FAIL   │ 1          │ 0.020   │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ returncode_int_match/d0 │ generic.local.bash │ PASS   │ 128        │ 0.021   │
│ cb8641                  │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 4 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_22qwj2vz.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:10                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/ │
│ /ede22ca │        │          │          │       │       │ regular  │ readthe │
│ 7        │        │          │          │       │       │ expressi │ docs.or │
│          │        │          │          │       │       │ on       │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/ │
│ /cfdca98 │        │          │          │       │       │ regular  │ readthe │
│ 2        │        │          │          │       │       │ expressi │ docs.or │
│          │        │          │          │       │       │ on       │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/ │
│ /74836dc │        │          │          │       │       │ regular  │ readthe │
│ a        │        │          │          │       │       │ expressi │ docs.or │
│          │        │          │          │       │       │ on       │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/ │
│ /ac0a5d3 │        │          │          │       │       │ regular  │ readthe │
│ b        │        │          │          │       │       │ expressi │ docs.or │
│          │        │          │          │       │       │ on       │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ status_ │
│          │        │          │          │       │       │          │ regex.y │
│          │        │          │          │       │       │          │ ml      │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
status_regex_stdout_pass/ede22ca7: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stdout_pass/ede22ca7
status_regex_stdout_fail/cfdca982: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stdout_fail/cfdca982
status_regex_stderr_pass/74836dca: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stderr_pass/74836dca
status_regex_stderr_fail/ac0a5d3b: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stderr_fail/ac0a5d3b
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
status_regex_stderr_fail/ac0a5d3b does not have any dependencies adding test to queue
status_regex_stdout_pass/ede22ca7 does not have any dependencies adding test to queue
status_regex_stdout_fail/cfdca982 does not have any dependencies adding test to queue
status_regex_stderr_pass/74836dca does not have any dependencies adding test to queue
      Builders Eligible to Run       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ status_regex_stderr_fail/ac0a5d3b │
│ status_regex_stdout_pass/ede22ca7 │
│ status_regex_stdout_fail/cfdca982 │
│ status_regex_stderr_pass/74836dca │
└───────────────────────────────────┘
status_regex_stderr_fail/ac0a5d3b: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stderr_fail/ac0a5d3b/stage
status_regex_stderr_fail/ac0a5d3b: Running Test via command: bash status_regex_stderr_fail_build.sh
status_regex_stderr_fail/ac0a5d3b: Test completed in 0.008832 seconds with returncode: 0
status_regex_stderr_fail/ac0a5d3b: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stderr_fail/ac0a5d3b/status_regex_stderr_fail.out
status_regex_stderr_fail/ac0a5d3b: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stderr_fail/ac0a5d3b/status_regex_stderr_fail.err
status_regex_stderr_fail/ac0a5d3b: performing regular expression - '^(123FAIL)$' on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stderr_fail/ac0a5d3b/status_regex_stderr_fail.err
status_regex_stderr_fail/ac0a5d3b: Regular Expression Match - Failed!
status_regex_stdout_pass/ede22ca7: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stdout_pass/ede22ca7/stage
status_regex_stdout_pass/ede22ca7: Running Test via command: bash status_regex_stdout_pass_build.sh
status_regex_stdout_pass/ede22ca7: Test completed in 0.008455 seconds with returncode: 0
status_regex_stdout_pass/ede22ca7: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stdout_pass/ede22ca7/status_regex_stdout_pass.out
status_regex_stdout_pass/ede22ca7: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stdout_pass/ede22ca7/status_regex_stdout_pass.err
status_regex_stdout_pass/ede22ca7: performing regular expression - '^(PASS)$' on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stdout_pass/ede22ca7/status_regex_stdout_pass.out
status_regex_stdout_pass/ede22ca7: Regular Expression Match - Success!
status_regex_stdout_fail/cfdca982: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stdout_fail/cfdca982/stage
status_regex_stdout_fail/cfdca982: Running Test via command: bash status_regex_stdout_fail_build.sh
status_regex_stdout_fail/cfdca982: Test completed in 0.008409 seconds with returncode: 0
status_regex_stdout_fail/cfdca982: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stdout_fail/cfdca982/status_regex_stdout_fail.out
status_regex_stdout_fail/cfdca982: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stdout_fail/cfdca982/status_regex_stdout_fail.err
status_regex_stdout_fail/cfdca982: performing regular expression - '^(123FAIL)$' on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stdout_fail/cfdca982/status_regex_stdout_fail.out
status_regex_stdout_fail/cfdca982: Regular Expression Match - Failed!
status_regex_stderr_pass/74836dca: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stderr_pass/74836dca/stage
status_regex_stderr_pass/74836dca: Running Test via command: bash status_regex_stderr_pass_build.sh
status_regex_stderr_pass/74836dca: Test completed in 0.008351 seconds with returncode: 0
status_regex_stderr_pass/74836dca: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stderr_pass/74836dca/status_regex_stderr_pass.out
status_regex_stderr_pass/74836dca: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stderr_pass/74836dca/status_regex_stderr_pass.err
status_regex_stderr_pass/74836dca: performing regular expression - '^(PASS)$' on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/status_regex/status_regex_stderr_pass/74836dca/status_regex_stderr_pass.err
status_regex_stderr_pass/74836dca: Regular Expression Match - Success!
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ status_regex_stderr_pas │ generic.local.bash │ PASS   │ 0          │ 0.008   │
│ s/74836dca              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ status_regex_stdout_pas │ generic.local.bash │ PASS   │ 0          │ 0.008   │
│ s/ede22ca7              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ status_regex_stdout_fai │ generic.local.bash │ FAIL   │ 0          │ 0.008   │
│ l/cfdca982              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ status_regex_stderr_fai │ generic.local.bash │ FAIL   │ 0          │ 0.009   │
│ l/ac0a5d3b              │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 4 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_du0pblkp.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:12                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/ │
│ 0533590e │        │          │          │       │       │ files    │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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 │
│ /329d0f6 │        │          │          │       │       │ supporte │ docs.or │
│ 4        │        │          │          │       │       │ d        │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/ │
│ /7086b4c │        │          │          │       │       │ variable │ readthe │
│ b        │        │          │          │       │       │ and      │ docs.or │
│          │        │          │          │       │       │ shell    │ g/user_ │
│          │        │          │          │       │       │ expansio │ builds/ │
│          │        │          │          │       │       │ n        │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ regex_o │
│          │        │          │          │       │       │          │ n_filen │
│          │        │          │          │       │       │          │ ame.yml │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
regex_on_multiple_files/0533590e: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/0533590e
regex_on_directory_not_supported/329d0f64: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_directory_not_supported/329d0f64
file_expansion_supported/7086b4cb: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/file_expansion_supported/7086b4cb
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
regex_on_directory_not_supported/329d0f64 does not have any dependencies adding test to queue
file_expansion_supported/7086b4cb does not have any dependencies adding test to queue
regex_on_multiple_files/0533590e does not have any dependencies adding test to queue
          Builders Eligible to Run           
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                                   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ regex_on_directory_not_supported/329d0f64 │
│ file_expansion_supported/7086b4cb         │
│ regex_on_multiple_files/0533590e          │
└───────────────────────────────────────────┘
regex_on_directory_not_supported/329d0f64: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_directory_not_supported/329d0f64/stage
regex_on_directory_not_supported/329d0f64: Running Test via command: bash regex_on_directory_not_supported_build.sh
regex_on_directory_not_supported/329d0f64: Test completed in 0.010215 seconds with returncode: 0
regex_on_directory_not_supported/329d0f64: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_directory_not_supported/329d0f64/regex_on_directory_not_supported.out
regex_on_directory_not_supported/329d0f64: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_directory_not_supported/329d0f64/regex_on_directory_not_supported.err
regex_on_directory_not_supported/329d0f64: File: /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_directory_not_supported/329d0f64/stage/hello is not a file
file_expansion_supported/7086b4cb: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/file_expansion_supported/7086b4cb/stage
file_expansion_supported/7086b4cb: Running Test via command: bash file_expansion_supported_build.sh
file_expansion_supported/7086b4cb: Test completed in 0.008573 seconds with returncode: 0
file_expansion_supported/7086b4cb: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/file_expansion_supported/7086b4cb/file_expansion_supported.out
file_expansion_supported/7086b4cb: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/file_expansion_supported/7086b4cb/file_expansion_supported.err
file_expansion_supported/7086b4cb: Performing regex expression '^(Hello)$' on file /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/hello.txt
file_expansion_supported/7086b4cb: Regular expression on file /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/hello.txt is a MATCH!
file_expansion_supported/7086b4cb: Performing regex expression '^(Hello)$' on file /home/docs/hello.txt
file_expansion_supported/7086b4cb: Regular expression on file /home/docs/hello.txt is a MATCH!
regex_on_multiple_files/0533590e: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/0533590e/stage
regex_on_multiple_files/0533590e: Running Test via command: bash regex_on_multiple_files_build.sh
regex_on_multiple_files/0533590e: Test completed in 0.840158 seconds with returncode: 0
regex_on_multiple_files/0533590e: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/0533590e/regex_on_multiple_files.out
regex_on_multiple_files/0533590e: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/0533590e/regex_on_multiple_files.err
regex_on_multiple_files/0533590e: Performing regex expression '^(Hello)$' on file /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/0533590e/stage/hello.txt
regex_on_multiple_files/0533590e: Regular expression on file /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/0533590e/stage/hello.txt is a MATCH!
regex_on_multiple_files/0533590e: Performing regex expression '^(usage: buildtest)' on file /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/0533590e/stage/buildtest_help.txt
regex_on_multiple_files/0533590e: Regular expression on file /tmp/tmpr88132k2/var/tests/generic.local.bash/regex_on_filename/regex_on_multiple_files/0533590e/stage/buildtest_help.txt is a MATCH!
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ regex_on_directory_not_ │ generic.local.bash │ FAIL   │ 0          │ 0.010   │
│ supported/329d0f64      │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ file_expansion_supporte │ generic.local.bash │ PASS   │ 0          │ 0.009   │
│ d/7086b4cb              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ regex_on_multiple_files │ generic.local.bash │ PASS   │ 0          │ 0.840   │
│ /0533590e               │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 3 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_6v2fy1r9.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:14                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/ad7f2a │        │          │          │       │       │ job for  │ ckouts/ │
│ 05       │        │          │          │       │       │ 2        │ readthe │
│          │        │          │          │       │       │ seconds  │ docs.or │
│          │        │          │          │       │       │ and test │ g/user_ │
│          │        │          │          │       │       │ pass if  │ builds/ │
│          │        │          │          │       │       │ its      │ buildte │
│          │        │          │          │       │       │ within   │ st/chec │
│          │        │          │          │       │       │ 1.0-3.0s │ kouts/s │
│          │        │          │          │       │       │ ec       │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ runtime │
│          │        │          │          │       │       │          │ _status │
│          │        │          │          │       │       │          │ _test.y │
│          │        │          │          │       │       │          │ ml      │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ timelimi │ script │ generic. │ None     │ None  │ None  │ Run a    │ /home/d │
│ t_min/44 │        │ local.sh │          │       │       │ sleep    │ ocs/che │
│ ce8205   │        │          │          │       │       │ job for  │ ckouts/ │
│          │        │          │          │       │       │ 2        │ readthe │
│          │        │          │          │       │       │ seconds  │ docs.or │
│          │        │          │          │       │       │ and test │ g/user_ │
│          │        │          │          │       │       │ pass if  │ builds/ │
│          │        │          │          │       │       │ its      │ buildte │
│          │        │          │          │       │       │ exceeds  │ st/chec │
│          │        │          │          │       │       │ min time │ kouts/s │
│          │        │          │          │       │       │ of 1.0   │ table/t │
│          │        │          │          │       │       │ sec      │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ runtime │
│          │        │          │          │       │       │          │ _status │
│          │        │          │          │       │       │          │ _test.y │
│          │        │          │          │       │       │          │ ml      │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ timelimi │ script │ generic. │ None     │ None  │ None  │ Run a    │ /home/d │
│ t_max/77 │        │ local.sh │          │       │       │ sleep    │ ocs/che │
│ 9bc5f2   │        │          │          │       │       │ job for  │ ckouts/ │
│          │        │          │          │       │       │ 2        │ readthe │
│          │        │          │          │       │       │ seconds  │ docs.or │
│          │        │          │          │       │       │ and test │ g/user_ │
│          │        │          │          │       │       │ pass if  │ builds/ │
│          │        │          │          │       │       │ it's     │ buildte │
│          │        │          │          │       │       │ within   │ st/chec │
│          │        │          │          │       │       │ max      │ kouts/s │
│          │        │          │          │       │       │ time:    │ table/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/1b3e2 │        │          │          │       │       │ fails    │ ckouts/ │
│ 04f      │        │          │          │       │       │ because  │ readthe │
│          │        │          │          │       │       │ it runs  │ docs.or │
│          │        │          │          │       │       │ less     │ g/user_ │
│          │        │          │          │       │       │ than     │ builds/ │
│          │        │          │          │       │       │ mintime  │ buildte │
│          │        │          │          │       │       │ of 10    │ st/chec │
│          │        │          │          │       │       │ second   │ kouts/s │
│          │        │          │          │       │       │          │ table/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/02b67 │        │          │          │       │       │ fails    │ ckouts/ │
│ 8d6      │        │          │          │       │       │ because  │ readthe │
│          │        │          │          │       │       │ it       │ docs.or │
│          │        │          │          │       │       │ exceeds  │ g/user_ │
│          │        │          │          │       │       │ maxtime  │ builds/ │
│          │        │          │          │       │       │ of 1.0   │ buildte │
│          │        │          │          │       │       │ second   │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ runtime │
│          │        │          │          │       │       │          │ _status │
│          │        │          │          │       │       │          │ _test.y │
│          │        │          │          │       │       │          │ ml      │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
timelimit_min_max/ad7f2a05: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min_max/ad7f2a05
timelimit_min/44ce8205: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min/44ce8205
timelimit_max/779bc5f2: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_max/779bc5f2
timelimit_min_fail/1b3e204f: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min_fail/1b3e204f
timelimit_max_fail/02b678d6: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_max_fail/02b678d6
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
timelimit_max_fail/02b678d6 does not have any dependencies adding test to queue
timelimit_min/44ce8205 does not have any dependencies adding test to queue
timelimit_min_fail/1b3e204f does not have any dependencies adding test to queue
timelimit_min_max/ad7f2a05 does not have any dependencies adding test to queue
timelimit_max/779bc5f2 does not have any dependencies adding test to queue
   Builders Eligible to Run    
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                     ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ timelimit_max_fail/02b678d6 │
│ timelimit_min/44ce8205      │
│ timelimit_min_max/ad7f2a05  │
│ timelimit_min_fail/1b3e204f │
│ timelimit_max/779bc5f2      │
└─────────────────────────────┘
timelimit_max_fail/02b678d6: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_max_fail/02b678d6/stage
timelimit_max_fail/02b678d6: Running Test via command: bash timelimit_max_fail_build.sh
timelimit_max_fail/02b678d6: Test completed in 3.00927 seconds with returncode: 0
timelimit_max_fail/02b678d6: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_max_fail/02b678d6/timelimit_max_fail.out
timelimit_max_fail/02b678d6: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_max_fail/02b678d6/timelimit_max_fail.err
timelimit_max_fail/02b678d6: Checking runtime < maxtime: 3.00927 < 1.0 
timelimit_min/44ce8205: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min/44ce8205/stage
timelimit_min/44ce8205: Running Test via command: bash timelimit_min_build.sh
timelimit_min/44ce8205: Test completed in 2.008593 seconds with returncode: 0
timelimit_min/44ce8205: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min/44ce8205/timelimit_min.out
timelimit_min/44ce8205: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min/44ce8205/timelimit_min.err
timelimit_min/44ce8205: Checking  mintime < runtime: 1.0 < 2.008593
timelimit_min_max/ad7f2a05: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min_max/ad7f2a05/stage
timelimit_min_max/ad7f2a05: Running Test via command: bash timelimit_min_max_build.sh
timelimit_min_max/ad7f2a05: Test completed in 2.007057 seconds with returncode: 0
timelimit_min_max/ad7f2a05: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min_max/ad7f2a05/timelimit_min_max.out
timelimit_min_max/ad7f2a05: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min_max/ad7f2a05/timelimit_min_max.err
timelimit_min_max/ad7f2a05: Checking mintime < runtime < maxtime: 1.0 < 2.007057 < 3.0
timelimit_min_fail/1b3e204f: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min_fail/1b3e204f/stage
timelimit_min_fail/1b3e204f: Running Test via command: bash timelimit_min_fail_build.sh
timelimit_min_fail/1b3e204f: Test completed in 2.009245 seconds with returncode: 0
timelimit_min_fail/1b3e204f: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min_fail/1b3e204f/timelimit_min_fail.out
timelimit_min_fail/1b3e204f: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_min_fail/1b3e204f/timelimit_min_fail.err
timelimit_min_fail/1b3e204f: Checking  mintime < runtime: 10.0 < 2.009245
timelimit_max/779bc5f2: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_max/779bc5f2/stage
timelimit_max/779bc5f2: Running Test via command: bash timelimit_max_build.sh
timelimit_max/779bc5f2: Test completed in 2.009428 seconds with returncode: 0
timelimit_max/779bc5f2: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_max/779bc5f2/timelimit_max.out
timelimit_max/779bc5f2: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.sh/runtime_status_test/timelimit_max/779bc5f2/timelimit_max.err
timelimit_max/779bc5f2: Checking runtime < maxtime: 2.009428 < 5.0 
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                   ┃ executor         ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ timelimit_min_fail/1b3e20 │ generic.local.sh │ FAIL   │ 0          │ 2.009   │
│ 4f                        │                  │        │            │         │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ timelimit_min_max/ad7f2a0 │ generic.local.sh │ PASS   │ 0          │ 2.007   │
│ 5                         │                  │        │            │         │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ timelimit_max_fail/02b678 │ generic.local.sh │ FAIL   │ 0          │ 3.009   │
│ d6                        │                  │        │            │         │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ timelimit_min/44ce8205    │ generic.local.sh │ PASS   │ 0          │ 2.009   │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ timelimit_max/779bc5f2    │ generic.local.sh │ PASS   │ 0          │ 2.009   │
└───────────────────────────┴──────────────────┴────────┴────────────┴─────────┘



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


Adding 5 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_5q_jpxfl.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/tmpr88132k2/var/report.json    
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━┓
┃ name               ┃ id       ┃ state ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━┩
│ timelimit_min_fail │ 1b3e204f │ FAIL  │ 2.009245 │
│ timelimit_min_max  │ ad7f2a05 │ PASS  │ 2.007057 │
│ timelimit_max_fail │ 02b678d6 │ FAIL  │ 3.00927  │
│ timelimit_min      │ 44ce8205 │ PASS  │ 2.008593 │
│ timelimit_max      │ 779bc5f2 │ PASS  │ 2.009428 │
└────────────────────┴──────────┴───────┴──────────┘

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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:27                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/cbcc │        │ local.sh │          │       │       │ test     │ ocs/che │
│ 5e12     │        │          │          │       │       │ will     │ ckouts/ │
│          │        │          │          │       │       │ always   │ readthe │
│          │        │          │          │       │       │ 'PASS'   │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ explici │
│          │        │          │          │       │       │          │ t_state │
│          │        │          │          │       │       │          │ .yml    │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ always_f │ script │ generic. │ None     │ None  │ None  │ This     │ /home/d │
│ ail/e7be │        │ local.sh │          │       │       │ test     │ ocs/che │
│ 0fcf     │        │          │          │       │       │ will     │ ckouts/ │
│          │        │          │          │       │       │ always   │ readthe │
│          │        │          │          │       │       │ 'FAIL'   │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/9c90f │        │          │          │       │       │ 'FAIL'   │ readthe │
│ 2a5      │        │          │          │       │       │ even if  │ docs.or │
│          │        │          │          │       │       │ we have  │ g/user_ │
│          │        │          │          │       │       │ returnco │ builds/ │
│          │        │          │          │       │       │ de match │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/1e │        │          │          │       │       │ 'PASS'   │ readthe │
│ 14e623   │        │          │          │       │       │ even if  │ docs.or │
│          │        │          │          │       │       │ we have  │ g/user_ │
│          │        │          │          │       │       │ returnco │ builds/ │
│          │        │          │          │       │       │ de       │ buildte │
│          │        │          │          │       │       │ mismatch │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ explici │
│          │        │          │          │       │       │          │ t_state │
│          │        │          │          │       │       │          │ .yml    │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
always_pass/cbcc5e12: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/always_pass/cbcc5e12
always_fail/e7be0fcf: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/always_fail/e7be0fcf
test_fail_returncode_match/9c90f2a5: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/test_fail_returncode_match/9c90f2a5
test_pass_returncode_mismatch/1e14e623: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/test_pass_returncode_mismatch/1e14e623
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
always_pass/cbcc5e12 does not have any dependencies adding test to queue
always_fail/e7be0fcf does not have any dependencies adding test to queue
test_pass_returncode_mismatch/1e14e623 does not have any dependencies adding test to queue
test_fail_returncode_match/9c90f2a5 does not have any dependencies adding test to queue
         Builders Eligible to Run         
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                                ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ always_pass/cbcc5e12                   │
│ always_fail/e7be0fcf                   │
│ test_pass_returncode_mismatch/1e14e623 │
│ test_fail_returncode_match/9c90f2a5    │
└────────────────────────────────────────┘
always_pass/cbcc5e12: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/always_pass/cbcc5e12/stage
always_pass/cbcc5e12: Running Test via command: bash always_pass_build.sh
always_pass/cbcc5e12: failed to submit job with returncode: 1
always_pass/cbcc5e12: Detected failure in running test, will attempt to retry test: 1 times
always_pass/cbcc5e12: Run - 1/1
always_pass/cbcc5e12: Running Test via command: bash always_pass_build.sh
always_pass/cbcc5e12: failed to submit job with returncode: 1
always_pass/cbcc5e12: Test completed in 0.018429 seconds with returncode: 1
always_pass/cbcc5e12: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/always_pass/cbcc5e12/always_pass.out
always_pass/cbcc5e12: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/always_pass/cbcc5e12/always_pass.err
always_fail/e7be0fcf: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/always_fail/e7be0fcf/stage
always_fail/e7be0fcf: Running Test via command: bash always_fail_build.sh
always_fail/e7be0fcf: Test completed in 0.007131 seconds with returncode: 0
always_fail/e7be0fcf: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/always_fail/e7be0fcf/always_fail.out
always_fail/e7be0fcf: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/always_fail/e7be0fcf/always_fail.err
test_pass_returncode_mismatch/1e14e623: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/test_pass_returncode_mismatch/1e14e623/stage
test_pass_returncode_mismatch/1e14e623: Running Test via command: bash test_pass_returncode_mismatch_build.sh
test_pass_returncode_mismatch/1e14e623: failed to submit job with returncode: 1
test_pass_returncode_mismatch/1e14e623: Detected failure in running test, will attempt to retry test: 1 times
test_pass_returncode_mismatch/1e14e623: Run - 1/1
test_pass_returncode_mismatch/1e14e623: Running Test via command: bash test_pass_returncode_mismatch_build.sh
test_pass_returncode_mismatch/1e14e623: failed to submit job with returncode: 1
test_pass_returncode_mismatch/1e14e623: Test completed in 0.018922 seconds with returncode: 1
test_pass_returncode_mismatch/1e14e623: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/test_pass_returncode_mismatch/1e14e623/test_pass_returncode_mismatch.out
test_pass_returncode_mismatch/1e14e623: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/test_pass_returncode_mismatch/1e14e623/test_pass_returncode_mismatch.err
test_fail_returncode_match/9c90f2a5: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/test_fail_returncode_match/9c90f2a5/stage
test_fail_returncode_match/9c90f2a5: Running Test via command: bash test_fail_returncode_match_build.sh
test_fail_returncode_match/9c90f2a5: failed to submit job with returncode: 1
test_fail_returncode_match/9c90f2a5: Detected failure in running test, will attempt to retry test: 1 times
test_fail_returncode_match/9c90f2a5: Run - 1/1
test_fail_returncode_match/9c90f2a5: Running Test via command: bash test_fail_returncode_match_build.sh
test_fail_returncode_match/9c90f2a5: failed to submit job with returncode: 1
test_fail_returncode_match/9c90f2a5: Test completed in 0.018599 seconds with returncode: 1
test_fail_returncode_match/9c90f2a5: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/test_fail_returncode_match/9c90f2a5/test_fail_returncode_match.out
test_fail_returncode_match/9c90f2a5: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.sh/explicit_state/test_fail_returncode_match/9c90f2a5/test_fail_returncode_match.err
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                   ┃ executor         ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ always_pass/cbcc5e12      │ generic.local.sh │ PASS   │ 1          │ 0.018   │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ test_pass_returncode_mism │ generic.local.sh │ PASS   │ 1          │ 0.019   │
│ atch/1e14e623             │                  │        │            │         │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ always_fail/e7be0fcf      │ generic.local.sh │ FAIL   │ 0          │ 0.007   │
├───────────────────────────┼──────────────────┼────────┼────────────┼─────────┤
│ test_fail_returncode_matc │ generic.local.sh │ FAIL   │ 1          │ 0.019   │
│ h/9c90f2a5                │                  │        │            │         │
└───────────────────────────┴──────────────────┴────────┴────────────┴─────────┘



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


Adding 4 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_at_bbr5s.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:28                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/d3 │        │ local.ba │          │       │       │ check    │ ocs/che │
│ a228b6   │        │ sh       │          │       │       │ based    │ ckouts/ │
│          │        │          │          │       │       │ for file │ readthe │
│          │        │          │          │       │       │ and      │ docs.or │
│          │        │          │          │       │       │ director │ g/user_ │
│          │        │          │          │       │       │ y        │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/ba │        │ sh       │          │       │       │ failure  │ ckouts/ │
│ a40e9a   │        │          │          │       │       │ for      │ readthe │
│          │        │          │          │       │       │ existenc │ docs.or │
│          │        │          │          │       │       │ e        │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ exists. │
│          │        │          │          │       │       │          │ yml     │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
status_exists/d3a228b6: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/exists/status_exists/d3a228b6
status_exists_failure/baa40e9a: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/exists/status_exists_failure/baa40e9a
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
status_exists/d3a228b6 does not have any dependencies adding test to queue
status_exists_failure/baa40e9a does not have any dependencies adding test to queue
     Builders Eligible to Run     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                        ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ status_exists/d3a228b6         │
│ status_exists_failure/baa40e9a │
└────────────────────────────────┘
status_exists/d3a228b6: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/exists/status_exists/d3a228b6/stage
status_exists/d3a228b6: Running Test via command: bash status_exists_build.sh
status_exists/d3a228b6: Test completed in 0.013705 seconds with returncode: 0
status_exists/d3a228b6: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/exists/status_exists/d3a228b6/status_exists.out
status_exists/d3a228b6: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/exists/status_exists/d3a228b6/status_exists.err
status_exists/d3a228b6: Test all files:  ['$HOME/dirA', '~/.bashrc', '/tmp/ABC', 'file1']  existences
status_exists/d3a228b6: file: /home/docs/dirA exists
status_exists/d3a228b6: file: /home/docs/.bashrc exists
status_exists/d3a228b6: file: /tmp/ABC exists
status_exists/d3a228b6: file: /tmp/tmpr88132k2/var/tests/generic.local.bash/exists/status_exists/d3a228b6/stage/file1 exists
status_exists/d3a228b6: Exist Check: True
status_exists_failure/baa40e9a: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/exists/status_exists_failure/baa40e9a/stage
status_exists_failure/baa40e9a: Running Test via command: bash status_exists_failure_build.sh
status_exists_failure/baa40e9a: Test completed in 0.01101 seconds with returncode: 0
status_exists_failure/baa40e9a: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/exists/status_exists_failure/baa40e9a/status_exists_failure.out
status_exists_failure/baa40e9a: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/exists/status_exists_failure/baa40e9a/status_exists_failure.err
status_exists_failure/baa40e9a: Test all files:  ['bar']  existences 
status_exists_failure/baa40e9a: file: bar does not exist
status_exists_failure/baa40e9a: Exist Check: False
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ status_exists/d3a228b6  │ generic.local.bash │ PASS   │ 0          │ 0.014   │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ status_exists_failure/b │ generic.local.bash │ FAIL   │ 0          │ 0.011   │
│ aa40e9a                 │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 2 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_83x1trbp.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/stable… ─
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/stable/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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:31                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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 │
│ /92e084c │        │ sh       │          │       │       │ will     │ ckouts/ │
│ 4        │        │          │          │       │       │ pass     │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_ex │
│          │        │          │          │       │       │          │ ists_wi │
│          │        │          │          │       │       │          │ th_numb │
│          │        │          │          │       │       │          │ er.yml  │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_exists_pass/92e084c4: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_exists_with_number/file_exists_pass/92e084c4
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_exists_pass/92e084c4 does not have any dependencies adding test to queue
  Builders Eligible to Run   
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_exists_pass/92e084c4 │
└───────────────────────────┘
file_exists_pass/92e084c4: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_exists_with_number/file_exists_pass/92e084c4/stage
file_exists_pass/92e084c4: Running Test via command: bash file_exists_pass_build.sh
file_exists_pass/92e084c4: Test completed in 0.010512 seconds with returncode: 0
file_exists_pass/92e084c4: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_exists_with_number/file_exists_pass/92e084c4/file_exists_pass.out
file_exists_pass/92e084c4: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_exists_with_number/file_exists_pass/92e084c4/file_exists_pass.err
file_exists_pass/92e084c4: Test all files:  ['1']  existences 
file_exists_pass/92e084c4: file: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_exists_with_number/file_exists_pass/92e084c4/stage/1 exists
file_exists_pass/92e084c4: Exist Check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_exists_pass/92e084 │ generic.local.bash │ PASS   │ 0          │ 0.011   │
│ c4                      │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 1 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_o2jnwn_m.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:32                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/ce10 │        │ sh       │          │       │       │ for      │ ckouts/ │
│ cb21     │        │          │          │       │       │ files    │ readthe │
│          │        │          │          │       │       │ and      │ docs.or │
│          │        │          │          │       │       │ director │ g/user_ │
│          │        │          │          │       │       │ ies      │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/0f6 │        │          │          │       │       │ files    │ readthe │
│ 585c7    │        │          │          │       │       │ and      │ docs.or │
│          │        │          │          │       │       │ director │ g/user_ │
│          │        │          │          │       │       │ ies      │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_an │
│          │        │          │          │       │       │          │ d_dir_c │
│          │        │          │          │       │       │          │ heck.ym │
│          │        │          │          │       │       │          │ l       │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_and_dir_checks/ce10cb21: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_and_dir_check/file_and_dir_checks/ce10cb21
combined_file_and_dir_checks/0f6585c7: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_and_dir_check/combined_file_and_dir_checks/0f6585c7
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
combined_file_and_dir_checks/0f6585c7 does not have any dependencies adding test to queue
file_and_dir_checks/ce10cb21 does not have any dependencies adding test to queue
        Builders Eligible to Run         
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                               ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ combined_file_and_dir_checks/0f6585c7 │
│ file_and_dir_checks/ce10cb21          │
└───────────────────────────────────────┘
combined_file_and_dir_checks/0f6585c7: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_and_dir_check/combined_file_and_dir_checks/0f6585c7/stage
combined_file_and_dir_checks/0f6585c7: Running Test via command: bash combined_file_and_dir_checks_build.sh
combined_file_and_dir_checks/0f6585c7: Test completed in 0.009817 seconds with returncode: 0
combined_file_and_dir_checks/0f6585c7: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_and_dir_check/combined_file_and_dir_checks/0f6585c7/combined_file_and_dir_checks.out
combined_file_and_dir_checks/0f6585c7: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_and_dir_check/combined_file_and_dir_checks/0f6585c7/combined_file_and_dir_checks.err
combined_file_and_dir_checks/0f6585c7: Test all files:  ['$HOME', '/tmp']  existences
combined_file_and_dir_checks/0f6585c7: file: /home/docs is a directory 
combined_file_and_dir_checks/0f6585c7: file: /tmp is a directory 
combined_file_and_dir_checks/0f6585c7: Directory Existence Check: True
combined_file_and_dir_checks/0f6585c7: Test all files:  ['$HOME/.bashrc']  existences
combined_file_and_dir_checks/0f6585c7: file: /home/docs/.bashrc is a file 
combined_file_and_dir_checks/0f6585c7: File Existence Check: True
file_and_dir_checks/ce10cb21: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_and_dir_check/file_and_dir_checks/ce10cb21/stage
file_and_dir_checks/ce10cb21: Running Test via command: bash file_and_dir_checks_build.sh
file_and_dir_checks/ce10cb21: Test completed in 0.00938 seconds with returncode: 0
file_and_dir_checks/ce10cb21: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_and_dir_check/file_and_dir_checks/ce10cb21/file_and_dir_checks.out
file_and_dir_checks/ce10cb21: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_and_dir_check/file_and_dir_checks/ce10cb21/file_and_dir_checks.err
file_and_dir_checks/ce10cb21: Test all files:  ['$HOME', '$HOME/.bashrc', '/tmp']  existences
file_and_dir_checks/ce10cb21: file: /home/docs is a directory 
file_and_dir_checks/ce10cb21: file: $HOME/.bashrc is not a directory
file_and_dir_checks/ce10cb21: file: /tmp is a directory 
file_and_dir_checks/ce10cb21: Directory Existence Check: False
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ combined_file_and_dir_c │ generic.local.bash │ PASS   │ 0          │ 0.010   │
│ hecks/0f6585c7          │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ file_and_dir_checks/ce1 │ generic.local.bash │ FAIL   │ 0          │ 0.009   │
│ 0cb21                   │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 2 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_vi3ymcxe.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:34                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/ │
│ 811f7dd3 │        │          │          │       │       │ director │ readthe │
│          │        │          │          │       │       │ y        │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/ │
│ 38c21028 │        │          │          │       │       │ n        │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_co │
│          │        │          │          │       │       │          │ unt.yml │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_count_on_directory/811f7dd3: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_on_directory/811f7dd3
file_count_by_extension/38c21028: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_by_extension/38c21028
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_count_by_extension/38c21028 does not have any dependencies adding test to queue
file_count_on_directory/811f7dd3 does not have any dependencies adding test to queue
      Builders Eligible to Run      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                          ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_count_by_extension/38c21028 │
│ file_count_on_directory/811f7dd3 │
└──────────────────────────────────┘
file_count_by_extension/38c21028: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_by_extension/38c21028/stage
file_count_by_extension/38c21028: Running Test via command: bash file_count_by_extension_build.sh
file_count_by_extension/38c21028: Test completed in 0.013552 seconds with returncode: 0
file_count_by_extension/38c21028: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_by_extension/38c21028/file_count_by_extension.out
file_count_by_extension/38c21028: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_by_extension/38c21028/file_count_by_extension.err
file_count_by_extension/38c21028: Found 5 file in directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_by_extension/38c21028/stage/foo. Comparing with reference count: 5. Comparison check is 5 == 5 which evaluates to True
file_count_by_extension/38c21028: Found 6 file in directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_by_extension/38c21028/stage/foo/bar. Comparing with reference count: 6. Comparison check is 6 == 6 which evaluates to True
file_count_by_extension/38c21028: File Count Check: True
file_count_on_directory/811f7dd3: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_on_directory/811f7dd3/stage
file_count_on_directory/811f7dd3: Running Test via command: bash file_count_on_directory_build.sh
file_count_on_directory/811f7dd3: Test completed in 0.011976 seconds with returncode: 0
file_count_on_directory/811f7dd3: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_on_directory/811f7dd3/file_count_on_directory.out
file_count_on_directory/811f7dd3: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_on_directory/811f7dd3/file_count_on_directory.err
file_count_on_directory/811f7dd3: Found 5 file in directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count/file_count_on_directory/811f7dd3/stage/foo. Comparing with reference count: 5. Comparison check is 5 == 5 which evaluates to True
file_count_on_directory/811f7dd3: File Count Check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_count_by_extension │ generic.local.bash │ PASS   │ 0          │ 0.014   │
│ /38c21028               │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ file_count_on_directory │ generic.local.bash │ PASS   │ 0          │ 0.012   │
│ /811f7dd3               │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 2 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_o1dqulvw.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:35                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/ │
│ /75da5a5 │        │          │          │       │       │ on       │ readthe │
│ d        │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/f │        │          │          │       │       │ extensio │ readthe │
│ db8eaa0  │        │          │          │       │       │ n and    │ docs.or │
│          │        │          │          │       │       │ file     │ g/user_ │
│          │        │          │          │       │       │ pattern  │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_co │
│          │        │          │          │       │       │          │ unt_pat │
│          │        │          │          │       │       │          │ tern.ym │
│          │        │          │          │       │       │          │ l       │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_count_by_expression/75da5a5d: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_pattern/file_count_by_expression/75da5a5d
file_extension_and_filepattern/fdb8eaa0: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_pattern/file_extension_and_filepattern/fdb8eaa0
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_count_by_expression/75da5a5d does not have any dependencies adding test to queue
file_extension_and_filepattern/fdb8eaa0 does not have any dependencies adding test to queue
         Builders Eligible to Run          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                                 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_count_by_expression/75da5a5d       │
│ file_extension_and_filepattern/fdb8eaa0 │
└─────────────────────────────────────────┘
file_count_by_expression/75da5a5d: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_pattern/file_count_by_expression/75da5a5d/stage
file_count_by_expression/75da5a5d: Running Test via command: bash file_count_by_expression_build.sh
file_count_by_expression/75da5a5d: Test completed in 0.020953 seconds with returncode: 0
file_count_by_expression/75da5a5d: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_pattern/file_count_by_expression/75da5a5d/file_count_by_expression.out
file_count_by_expression/75da5a5d: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_pattern/file_count_by_expression/75da5a5d/file_count_by_expression.err
file_count_by_expression/75da5a5d: Found 5 file in directory: /tmp. Comparing with reference count: 5. Comparison check is 5 == 5 which evaluates to True
file_count_by_expression/75da5a5d: Found 2 file in directory: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/buildtest. Comparing with reference count: 2. Comparison check is 2 == 2 which evaluates to True
file_count_by_expression/75da5a5d: File Count Check: True
file_extension_and_filepattern/fdb8eaa0: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_pattern/file_extension_and_filepattern/fdb8eaa0/stage
file_extension_and_filepattern/fdb8eaa0: Running Test via command: bash file_extension_and_filepattern_build.sh
file_extension_and_filepattern/fdb8eaa0: Test completed in 0.014183 seconds with returncode: 0
file_extension_and_filepattern/fdb8eaa0: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_pattern/file_extension_and_filepattern/fdb8eaa0/file_extension_and_filepattern.out
file_extension_and_filepattern/fdb8eaa0: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_pattern/file_extension_and_filepattern/fdb8eaa0/file_extension_and_filepattern.err
file_extension_and_filepattern/fdb8eaa0: Found 7 file in directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_pattern/file_extension_and_filepattern/fdb8eaa0/stage. Comparing with reference count: 7. Comparison check is 7 == 7 which evaluates to True
file_extension_and_filepattern/fdb8eaa0: File Count Check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_count_by_expressio │ generic.local.bash │ PASS   │ 0          │ 0.021   │
│ n/75da5a5d              │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ file_extension_and_file │ generic.local.bash │ PASS   │ 0          │ 0.014   │
│ pattern/fdb8eaa0        │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 2 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_5yg2ycqm.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:36                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/8 │        │ sh       │          │       │       │ number   │ ckouts/ │
│ 5fd9da1  │        │          │          │       │       │ of       │ readthe │
│          │        │          │          │       │       │ director │ docs.or │
│          │        │          │          │       │       │ ies and  │ g/user_ │
│          │        │          │          │       │       │ symbolic │ builds/ │
│          │        │          │          │       │       │ links    │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_co │
│          │        │          │          │       │       │          │ unt_fil │
│          │        │          │          │       │       │          │ etype.y │
│          │        │          │          │       │       │          │ ml      │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_count_by_filetype/85fd9da1: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/85fd9da1
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_count_by_filetype/85fd9da1 does not have any dependencies adding test to queue
     Builders Eligible to Run      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                         ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_count_by_filetype/85fd9da1 │
└─────────────────────────────────┘
file_count_by_filetype/85fd9da1: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/85fd9da1/stage
file_count_by_filetype/85fd9da1: Running Test via command: bash file_count_by_filetype_build.sh
file_count_by_filetype/85fd9da1: Test completed in 0.015079 seconds with returncode: 0
file_count_by_filetype/85fd9da1: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/85fd9da1/file_count_by_filetype.out
file_count_by_filetype/85fd9da1: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/85fd9da1/file_count_by_filetype.err
file_count_by_filetype/85fd9da1: Found 3 file in directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/85fd9da1/stage/foo. Comparing with reference count: 3. Comparison check is 3 == 3 which evaluates to True
file_count_by_filetype/85fd9da1: Found 2 file in directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_filetype/file_count_by_filetype/85fd9da1/stage/foo. Comparing with reference count: 2. Comparison check is 2 == 2 which evaluates to True
file_count_by_filetype/85fd9da1: File Count Check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_count_by_filetype/ │ generic.local.bash │ PASS   │ 0          │ 0.015   │
│ 85fd9da1                │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 1 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_fjznjnif.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:37                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/c626 │        │ sh       │          │       │       │ verse_li │ ckouts/ │
│ 60e9     │        │          │          │       │       │ mit to   │ readthe │
│          │        │          │          │       │       │ limit    │ docs.or │
│          │        │          │          │       │       │ number   │ g/user_ │
│          │        │          │          │       │       │ of files │ builds/ │
│          │        │          │          │       │       │ searched │ buildte │
│          │        │          │          │       │       │ in a     │ st/chec │
│          │        │          │          │       │       │ director │ kouts/s │
│          │        │          │          │       │       │ y        │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_co │
│          │        │          │          │       │       │          │ unt_fil │
│          │        │          │          │       │       │          │ e_trave │
│          │        │          │          │       │       │          │ rse_lim │
│          │        │          │          │       │       │          │ it.yml  │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_traverse_limit/c62660e9: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/c62660e9
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_traverse_limit/c62660e9 does not have any dependencies adding test to queue
    Builders Eligible to Run    
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                      ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_traverse_limit/c62660e9 │
└──────────────────────────────┘
file_traverse_limit/c62660e9: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/c62660e9/stage
file_traverse_limit/c62660e9: Running Test via command: bash file_traverse_limit_build.sh
file_traverse_limit/c62660e9: Test completed in 0.014999 seconds with returncode: 0
file_traverse_limit/c62660e9: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/c62660e9/file_traverse_limit.out
file_traverse_limit/c62660e9: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/c62660e9/file_traverse_limit.err
file_traverse_limit/c62660e9: Found 50 file in directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/c62660e9/stage/foo. Comparing with reference count: 50. Comparison check is 50 == 50 which evaluates to True
file_traverse_limit/c62660e9: Found 20 file in directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_count_file_traverse_limit/file_traverse_limit/c62660e9/stage/foo. Comparing with reference count: 10. Comparison check is 20 == 10 which evaluates to False
file_traverse_limit/c62660e9: File Count Check: False
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_traverse_limit/c62 │ generic.local.bash │ FAIL   │ 0          │ 0.015   │
│ 660e9                   │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 1 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest__k7sxu4_.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:38                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/5f796 │        │ sh       │          │       │       │ AND to   │ ckouts/ │
│ 62b      │        │          │          │       │       │ check    │ readthe │
│          │        │          │          │       │       │ status   │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/71f04f │        │ sh       │          │       │       │ OR to    │ ckouts/ │
│ fe       │        │          │          │       │       │ check    │ readthe │
│          │        │          │          │       │       │ status   │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ mode.ym │
│          │        │          │          │       │       │          │ l       │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
status_logical_and/5f79662b: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/mode/status_logical_and/5f79662b
status_logical_or/71f04ffe: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/mode/status_logical_or/71f04ffe
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
status_logical_and/5f79662b does not have any dependencies adding test to queue
status_logical_or/71f04ffe does not have any dependencies adding test to queue
   Builders Eligible to Run    
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                     ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ status_logical_and/5f79662b │
│ status_logical_or/71f04ffe  │
└─────────────────────────────┘
status_logical_and/5f79662b: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/mode/status_logical_and/5f79662b/stage
status_logical_and/5f79662b: Running Test via command: bash status_logical_and_build.sh
status_logical_and/5f79662b: failed to submit job with returncode: 1
status_logical_and/5f79662b: Detected failure in running test, will attempt to retry test: 1 times
status_logical_and/5f79662b: Run - 1/1
status_logical_and/5f79662b: Running Test via command: bash status_logical_and_build.sh
status_logical_and/5f79662b: failed to submit job with returncode: 1
status_logical_and/5f79662b: Test completed in 0.021247 seconds with returncode: 1
status_logical_and/5f79662b: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/mode/status_logical_and/5f79662b/status_logical_and.out
status_logical_and/5f79662b: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/mode/status_logical_and/5f79662b/status_logical_and.err
status_logical_and/5f79662b: Checking returncode - 1 is matched in list [1]
status_logical_and/5f79662b: performing regular expression - 'This is a test' on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/mode/status_logical_and/5f79662b/status_logical_and.out
status_logical_and/5f79662b: Regular Expression Match - Success!
status_logical_or/71f04ffe: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/mode/status_logical_or/71f04ffe/stage
status_logical_or/71f04ffe: Running Test via command: bash status_logical_or_build.sh
status_logical_or/71f04ffe: failed to submit job with returncode: 1
status_logical_or/71f04ffe: Detected failure in running test, will attempt to retry test: 1 times
status_logical_or/71f04ffe: Run - 1/1
status_logical_or/71f04ffe: Running Test via command: bash status_logical_or_build.sh
status_logical_or/71f04ffe: failed to submit job with returncode: 1
status_logical_or/71f04ffe: Test completed in 0.0206 seconds with returncode: 1
status_logical_or/71f04ffe: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/mode/status_logical_or/71f04ffe/status_logical_or.out
status_logical_or/71f04ffe: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/mode/status_logical_or/71f04ffe/status_logical_or.err
status_logical_or/71f04ffe: Checking returncode - 1 is matched in list [0]
status_logical_or/71f04ffe: performing regular expression - 'This is a test' on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/mode/status_logical_or/71f04ffe/status_logical_or.out
status_logical_or/71f04ffe: Regular Expression Match - Success!
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ status_logical_or/71f04 │ generic.local.bash │ PASS   │ 1          │ 0.021   │
│ ffe                     │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ status_logical_and/5f79 │ generic.local.bash │ PASS   │ 1          │ 0.021   │
│ 662b                    │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 2 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_bqxup2s2.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:40                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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 │
│ /f43d2b6 │        │ sh       │          │       │       │ stdout   │ ckouts/ │
│ 8        │        │          │          │       │       │ and run  │ readthe │
│          │        │          │          │       │       │ linecoun │ docs.or │
│          │        │          │          │       │       │ t check  │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/ab4d01 │        │          │          │       │       │ and run  │ readthe │
│ 0d       │        │          │          │       │       │ linecoun │ docs.or │
│          │        │          │          │       │       │ t check  │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ linecou │
│          │        │          │          │       │       │          │ nt.yml  │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
linecount_stdout/f43d2b68: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stdout/f43d2b68
linecount_stderr_mismatch/ab4d010d: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/ab4d010d
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
linecount_stdout/f43d2b68 does not have any dependencies adding test to queue
linecount_stderr_mismatch/ab4d010d does not have any dependencies adding test to queue
       Builders Eligible to Run       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ linecount_stdout/f43d2b68          │
│ linecount_stderr_mismatch/ab4d010d │
└────────────────────────────────────┘
linecount_stdout/f43d2b68: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stdout/f43d2b68/stage
linecount_stdout/f43d2b68: Running Test via command: bash linecount_stdout_build.sh
linecount_stdout/f43d2b68: Test completed in 0.008933 seconds with returncode: 0
linecount_stdout/f43d2b68: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stdout/f43d2b68/linecount_stdout.out
linecount_stdout/f43d2b68: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stdout/f43d2b68/linecount_stdout.err
linecount_stdout/f43d2b68: Performing line count check on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stdout/f43d2b68/linecount_stdout.out with 10 (ref count) == 10 (actual count). linecount Check: True
linecount_stderr_mismatch/ab4d010d: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/ab4d010d/stage
linecount_stderr_mismatch/ab4d010d: Running Test via command: bash linecount_stderr_mismatch_build.sh
linecount_stderr_mismatch/ab4d010d: Test completed in 0.00871 seconds with returncode: 0
linecount_stderr_mismatch/ab4d010d: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/ab4d010d/linecount_stderr_mismatch.out
linecount_stderr_mismatch/ab4d010d: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/ab4d010d/linecount_stderr_mismatch.err
linecount_stderr_mismatch/ab4d010d: Performing line count check on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/ab4d010d/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.009   │
│ ch/ab4d010d             │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ linecount_stdout/f43d2b │ generic.local.bash │ PASS   │ 0          │ 0.009   │
│ 68                      │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 2 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_ptz7ca37.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/f43d2b68-7719-482d-b9be-83858cd12813 ─────────────
Executor: generic.local.bash
Description: Write 10 lines to stdout and run linecount check
State: PASS
Returncode: 0
Runtime: 0.008933 sec
Starttime: 2024/09/05 15:38:40
Endtime: 2024/09/05 15:38:40
Command: bash linecount_stdout_build.sh
Test Script: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stdout/f43d2b68/linecount_stdout.sh
Build Script: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stdout/f43d2b68/linecount_stdout_build.sh
Output File: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stdout/f43d2b68/linecount_stdout.out
Error File: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stdout/f43d2b68/linecount_stdout.err
Log File: /tmp/tmpr88132k2/var/logs/buildtest_ptz7ca37.log
──────────────────────────────── Output File:  ─────────────────────────────────
1                                                                               
2                                                                               
3                                                                               
4                                                                               
5                                                                               
6                                                                               
7                                                                               
8                                                                               
9                                                                               
10                                                                              
                                                                                
────────────────────────────────────────────────────────────────────────────────
$ buildtest inspect query -e linecount_stderr_mismatch
──────── linecount_stderr_mismatch/ab4d010d-9398-4757-a1c0-c1e15b3b714c ────────
Executor: generic.local.bash
Description: Write 10 lines to stderr and run linecount check
State: FAIL
Returncode: 0
Runtime: 0.00871 sec
Starttime: 2024/09/05 15:38:40
Endtime: 2024/09/05 15:38:40
Command: bash linecount_stderr_mismatch_build.sh
Test Script: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/ab4d010d/linecount_stderr_mismatch.sh
Build Script: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/ab4d010d/linecount_stderr_mismatch_build.sh
Output File: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/ab4d010d/linecount_stderr_mismatch.out
Error File: /tmp/tmpr88132k2/var/tests/generic.local.bash/linecount/linecount_stderr_mismatch/ab4d010d/linecount_stderr_mismatch.err
Log File: /tmp/tmpr88132k2/var/logs/buildtest_ptz7ca37.log
───────────────────────────────── Error File:  ─────────────────────────────────
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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:42                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/5 │        │ local.ba │          │       │       │ linecoun │ ocs/che │
│ e64acbf  │        │ sh       │          │       │       │ t        │ ckouts/ │
│          │        │          │          │       │       │ comparis │ readthe │
│          │        │          │          │       │       │ on on    │ docs.or │
│          │        │          │          │       │       │ files    │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_li │
│          │        │          │          │       │       │          │ necount │
│          │        │          │          │       │       │          │ .yml    │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_linecount/5e64acbf: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_linecount/file_linecount/5e64acbf
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_linecount/5e64acbf does not have any dependencies adding test to queue
 Builders Eligible to Run  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_linecount/5e64acbf │
└─────────────────────────┘
file_linecount/5e64acbf: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_linecount/file_linecount/5e64acbf/stage
file_linecount/5e64acbf: Running Test via command: bash file_linecount_build.sh
file_linecount/5e64acbf: Test completed in 0.009176 seconds with returncode: 0
file_linecount/5e64acbf: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_linecount/file_linecount/5e64acbf/file_linecount.out
file_linecount/5e64acbf: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_linecount/file_linecount/5e64acbf/file_linecount.err
file_linecount/5e64acbf: Performing line count check on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_linecount/file_linecount/5e64acbf/stage/count.txt with 10 (ref count) == 10 (actual count). linecount Check: True
file_linecount/5e64acbf: Performing line count check on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_linecount/file_linecount/5e64acbf/stage/hello.txt with 1 (ref count) == 1 (actual count). linecount Check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_linecount/5e64acbf │ generic.local.bash │ PASS   │ 0          │ 0.009   │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 1 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_kym6ogoi.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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:43                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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/80d1dc │        │          │          │       │       │ director │ readthe │
│ 62       │        │          │          │       │       │ y or     │ docs.or │
│          │        │          │          │       │       │ invalid  │ g/user_ │
│          │        │          │          │       │       │ files    │ builds/ │
│          │        │          │          │       │       │ can      │ buildte │
│          │        │          │          │       │       │ result   │ st/chec │
│          │        │          │          │       │       │ in       │ kouts/s │
│          │        │          │          │       │       │ failure  │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ file_li │
│          │        │          │          │       │       │          │ necount │
│          │        │          │          │       │       │          │ _failur │
│          │        │          │          │       │       │          │ e.yml   │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
file_linecount_exceptions/80d1dc62: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/file_linecount_failure/file_linecount_exceptions/80d1dc62
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
file_linecount_exceptions/80d1dc62 does not have any dependencies adding test to queue
       Builders Eligible to Run       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ file_linecount_exceptions/80d1dc62 │
└────────────────────────────────────┘
file_linecount_exceptions/80d1dc62: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/file_linecount_failure/file_linecount_exceptions/80d1dc62/stage
file_linecount_exceptions/80d1dc62: Running Test via command: bash file_linecount_exceptions_build.sh
file_linecount_exceptions/80d1dc62: Test completed in 0.009538 seconds with returncode: 0
file_linecount_exceptions/80d1dc62: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/file_linecount_failure/file_linecount_exceptions/80d1dc62/file_linecount_exceptions.out
file_linecount_exceptions/80d1dc62: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/file_linecount_failure/file_linecount_exceptions/80d1dc62/file_linecount_exceptions.err
file_linecount_exceptions/80d1dc62: File: /tmp is not a file
file_linecount_exceptions/80d1dc62: Unable to resolve file path: /badfile.txt
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ file_linecount_exceptio │ generic.local.bash │ FAIL   │ 0          │ 0.010   │
│ ns/80d1dc62             │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 1 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_9j0qbckg.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/stable… ─
-1 is less than the minimum of 0

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

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-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:45                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ 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/stable/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 │
│ /daf4e2e │        │ sh       │          │       │       │ h on     │ ckouts/ │
│ c        │        │          │          │       │       │ stdout   │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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 │
│ 1dfcfb13 │        │ sh       │          │       │       │ on       │ ckouts/ │
│          │        │          │          │       │       │ stdout   │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/c406 │        │ sh       │          │       │       │ atch on  │ ckouts/ │
│ 9dd6     │        │          │          │       │       │ stdout   │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/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/b │        │ sh       │          │       │       │ on file  │ ckouts/ │
│ a4b3e59  │        │          │          │       │       │ regex    │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/test_ │
│          │        │          │          │       │       │          │ status/ │
│          │        │          │          │       │       │          │ specify │
│          │        │          │          │       │       │          │ _regex_ │
│          │        │          │          │       │       │          │ type.ym │
│          │        │          │          │       │       │          │ l       │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
re.search.stdout/daf4e2ec: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.search.stdout/daf4e2ec
re.match.stdout/1dfcfb13: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match.stdout/1dfcfb13
re.fullmatch.stdout/c4069dd6: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.fullmatch.stdout/c4069dd6
re.match_on_file_regex/ba4b3e59: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/ba4b3e59
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
re.fullmatch.stdout/c4069dd6 does not have any dependencies adding test to queue
re.search.stdout/daf4e2ec does not have any dependencies adding test to queue
re.match.stdout/1dfcfb13 does not have any dependencies adding test to queue
re.match_on_file_regex/ba4b3e59 does not have any dependencies adding test to queue
     Builders Eligible to Run      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                         ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ re.fullmatch.stdout/c4069dd6    │
│ re.search.stdout/daf4e2ec       │
│ re.match.stdout/1dfcfb13        │
│ re.match_on_file_regex/ba4b3e59 │
└─────────────────────────────────┘
re.fullmatch.stdout/c4069dd6: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.fullmatch.stdout/c4069dd6/stage
re.fullmatch.stdout/c4069dd6: Running Test via command: bash re.fullmatch.stdout_build.sh
re.fullmatch.stdout/c4069dd6: Test completed in 0.008893 seconds with returncode: 0
re.fullmatch.stdout/c4069dd6: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.fullmatch.stdout/c4069dd6/re.fullmatch.stdout.out
re.fullmatch.stdout/c4069dd6: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.fullmatch.stdout/c4069dd6/re.fullmatch.stdout.err
re.fullmatch.stdout/c4069dd6: performing regular expression - 'This is a string' on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.fullmatch.stdout/c4069dd6/re.fullmatch.stdout.out
re.fullmatch.stdout/c4069dd6: Regular Expression Match - Success!
re.search.stdout/daf4e2ec: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.search.stdout/daf4e2ec/stage
re.search.stdout/daf4e2ec: Running Test via command: bash re.search.stdout_build.sh
re.search.stdout/daf4e2ec: Test completed in 0.008587 seconds with returncode: 0
re.search.stdout/daf4e2ec: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.search.stdout/daf4e2ec/re.search.stdout.out
re.search.stdout/daf4e2ec: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.search.stdout/daf4e2ec/re.search.stdout.err
re.search.stdout/daf4e2ec: performing regular expression - 'is' on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.search.stdout/daf4e2ec/re.search.stdout.out
re.search.stdout/daf4e2ec: Regular Expression Match - Success!
re.match.stdout/1dfcfb13: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match.stdout/1dfcfb13/stage
re.match.stdout/1dfcfb13: Running Test via command: bash re.match.stdout_build.sh
re.match.stdout/1dfcfb13: Test completed in 0.009082 seconds with returncode: 0
re.match.stdout/1dfcfb13: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match.stdout/1dfcfb13/re.match.stdout.out
re.match.stdout/1dfcfb13: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match.stdout/1dfcfb13/re.match.stdout.err
re.match.stdout/1dfcfb13: performing regular expression - 'is' on file: /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match.stdout/1dfcfb13/re.match.stdout.out
re.match.stdout/1dfcfb13: Regular Expression Match - Failed!
re.match_on_file_regex/ba4b3e59: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/ba4b3e59/stage
re.match_on_file_regex/ba4b3e59: Running Test via command: bash re.match_on_file_regex_build.sh
re.match_on_file_regex/ba4b3e59: Test completed in 0.008981 seconds with returncode: 0
re.match_on_file_regex/ba4b3e59: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/ba4b3e59/re.match_on_file_regex.out
re.match_on_file_regex/ba4b3e59: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/ba4b3e59/re.match_on_file_regex.err
re.match_on_file_regex/ba4b3e59: Performing regex expression 'string' on file /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/ba4b3e59/stage/file.txt
re.match_on_file_regex/ba4b3e59: Regular expression on file /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/ba4b3e59/stage/file.txt is a MATCH!
re.match_on_file_regex/ba4b3e59: Performing regex expression 'Hello' on file /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/ba4b3e59/stage/hello.txt
re.match_on_file_regex/ba4b3e59: Regular expression on file /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/ba4b3e59/stage/hello.txt is a MATCH!
re.match_on_file_regex/ba4b3e59: Performing regex expression 'Hello World' on file /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/ba4b3e59/stage/hello.txt
re.match_on_file_regex/ba4b3e59: Regular expression on file /tmp/tmpr88132k2/var/tests/generic.local.bash/specify_regex_type/re.match_on_file_regex/ba4b3e59/stage/hello.txt is a MATCH!
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ re.match.stdout/1dfcfb1 │ generic.local.bash │ FAIL   │ 0          │ 0.009   │
│ 3                       │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ re.fullmatch.stdout/c40 │ generic.local.bash │ PASS   │ 0          │ 0.009   │
│ 69dd6                   │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ re.match_on_file_regex/ │ generic.local.bash │ PASS   │ 0          │ 0.009   │
│ ba4b3e59                │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ re.search.stdout/daf4e2 │ generic.local.bash │ PASS   │ 0          │ 0.009   │
│ ec                      │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


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

post_run: Specify Post Run Tests

Buildtest can run additional commands after test execution that can be specified via post_run property. This can be used to perform cleanup or additional operations after test execution. To demonstrate this example we have the following buildspec. In this test we will create a directory named demo and create a symbolic link named $HOME/.bashrc_link. You will notice that in status check we are comparing the existence of directory and symbolic link. This is where post_run script comes into play where we want to remove the created directory and symbolic link. If we were to do this in run section, the test will fail since status check will fail to find these files. The post_run property is a list of commands that will be executed in a bash shell.

buildspecs:
  post_run_example:
    type: script
    executor: generic.local.bash
    description: post run example that will remove symbolic link
    run: |
      ln -s $HOME/.bashrc $HOME/.bashrc_link
      mkdir demo
    post_run: |
      unlink $HOME/.bashrc_link
      rmdir demo
    status:
      is_dir:
        - demo
      is_symlink:
        - $HOME/.bashrc_link

Now we can build this test and see the output, note buildtest will run the post_run script after test execution and show the exit code of test. It won’t affect the actual test behavior even if the post run script fails to execute properly.

buildtest build -b tutorials/post_run.yml
$ buildtest build -b tutorials/post_run.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:38:47                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/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/stable/ ║
║ tutorials/post_run.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/stable/tutorials/post_run.yml: VALID
Total builder objects created: 1
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ post_run │ script │ generic. │ None     │ None  │ None  │ post run │ /home/d │
│ _example │        │ local.ba │          │       │       │ example  │ ocs/che │
│ /fc8bd2e │        │ sh       │          │       │       │ that     │ ckouts/ │
│ 5        │        │          │          │       │       │ will     │ readthe │
│          │        │          │          │       │       │ remove   │ docs.or │
│          │        │          │          │       │       │ symbolic │ g/user_ │
│          │        │          │          │       │       │ link     │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/post_ │
│          │        │          │          │       │       │          │ run.yml │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
post_run_example/fc8bd2e5: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/post_run/post_run_example/fc8bd2e5
post_run_example/fc8bd2e5: Writing Post Run Script: /tmp/tmpr88132k2/var/tests/generic.local.bash/post_run/post_run_example/fc8bd2e5/stage/post_run_example_postrun.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
post_run_example/fc8bd2e5 does not have any dependencies adding test to queue
  Builders Eligible to Run   
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ post_run_example/fc8bd2e5 │
└───────────────────────────┘
post_run_example/fc8bd2e5: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/post_run/post_run_example/fc8bd2e5/stage
post_run_example/fc8bd2e5: Running Test via command: bash post_run_example_build.sh
post_run_example/fc8bd2e5: Test completed in 0.011964 seconds with returncode: 0
post_run_example/fc8bd2e5: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/post_run/post_run_example/fc8bd2e5/post_run_example.out
post_run_example/fc8bd2e5: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/post_run/post_run_example/fc8bd2e5/post_run_example.err
post_run_example/fc8bd2e5: Check all items:  ['$HOME/.bashrc_link']  for symbolic links
post_run_example/fc8bd2e5: $HOME/.bashrc_link is a symbolic link to /home/docs/.bashrc
post_run_example/fc8bd2e5: Symlink Check: True
post_run_example/fc8bd2e5: Test all files:  ['demo']  existences 
post_run_example/fc8bd2e5: file: /tmp/tmpr88132k2/var/tests/generic.local.bash/post_run/post_run_example/fc8bd2e5/stage/demo is a directory
post_run_example/fc8bd2e5: Directory Existence Check: True
post_run_example/fc8bd2e5: Running Post Run Script: /tmp/tmpr88132k2/var/tests/generic.local.bash/post_run/post_run_example/fc8bd2e5/stage/post_run_example_postrun.sh
post_run_example/fc8bd2e5: Post run script exit code: 0
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ post_run_example/fc8bd2 │ generic.local.bash │ PASS   │ 0          │ 0.012   │
│ e5                      │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


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

We can confirm the files are not present by checking existence of these files by running the following commands

$ ls -l $HOME/.bashrc_link
ls: cannot access '/home/docs/.bashrc_link': No such file or directory

We can retrieve the full path to stage directory via buildtest path -s command given the name of test. The demo directory is created in stage directory so if we run the following command we should see this directory is not present.

$ ls -l $(buildtest path -s post_run_example)/demo
ls: cannot access '/tmp/tmpr88132k2/var/tests/generic.local.bash/post_run/post_run_example/fc8bd2e5/stage/demo': No such file or directory