pax_global_header00006660000000000000000000000064144715027650014525gustar00rootroot0000000000000052 comment=13ad5e2ffcc360281432db3d43a306f7b3667d60 bats-file-0.4.0/000077500000000000000000000000001447150276500133745ustar00rootroot00000000000000bats-file-0.4.0/.github/000077500000000000000000000000001447150276500147345ustar00rootroot00000000000000bats-file-0.4.0/.github/workflows/000077500000000000000000000000001447150276500167715ustar00rootroot00000000000000bats-file-0.4.0/.github/workflows/tests.yml000066400000000000000000000020361447150276500206570ustar00rootroot00000000000000# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions name: Tests on: push: branches: [ master ] pull_request: branches: [ master ] jobs: shellcheck: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: shellcheck ./src/* build: strategy: matrix: os: ['macos-12', 'ubuntu-latest'] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - run: ./script/install-bats.sh - uses: actions/checkout@v2 with: repository: bats-core/bats-support path: bats-support # set PATh to ensure we use bats from our local installation (looking at you Mac Runner!) - name: bats test run: | PATH="$HOME/.local/bin:$PATH" bats -v BATS_LIB_PATH="$PWD" bats --print-output-on-failure testbats-file-0.4.0/.gitignore000066400000000000000000000001461447150276500153650ustar00rootroot00000000000000.vagrant # vagrant virtualbox image creates this log file. so, better to ignore *-cloudimg-console.logbats-file-0.4.0/CHANGELOG.md000066400000000000000000000032411447150276500152050ustar00rootroot00000000000000# Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [0.4.0] - 2023-08-23 ### Added - add aliases for `assert_*_exist`**s** (#34, #43) - CI: run shellcheck, fixed found issues (#51) - `assert_file_contains`: print regex on error (#57) - add `assert_file_not_contains` (#61) ### Fixed - various links and typos in README.md (#28, #26, #45) - migrated CI scripts to Github Actions (#42) - make `temp_*` functions compatible with `setup_file` (#36) - don't require `sudo` anymore for `assert_file_owner`/`assert_not_file_owner` (#38, #50) - fixed internal unset variable errors with `set -u` (#33) - make `temp_del` work even when contents are write protected (#31) - parameter documentation for `assert_file_permissions` (#47) - tests use `bats_load_library bats-support` (#48) - fix `temp_make` template to work with Alpine's `mktemp` (#52) - removed `temp.bash`'s executable bit (#55) - use new `bats_sudo` helper to avoid running `sudo` as root/when not available (#53, 54) - fix `assert_symlink_to` for temp files in OSX (#56) ## [0.3.0] - 2018-10-28 ### Added - Added assert_files_equal assert_files_not_equal functions! - Added 2 test scripts for assert_files_equal assert_files_not_equal ## [0.2.0] - 2016-12-07 ### Added - Handling temporary directories with `temp_make()` and `temp_del()` ### Fixed - Function comments listing path transformation variables incorrectly ## 0.1.0 - 2016-03-22 ### Added - Testing file existence with `assert_file_exist` and `assert_file_not_exist` - `npm` support [0.2.0]: https://github.com/bats-core/bats-file/compare/v0.1.0...v0.2.0 bats-file-0.4.0/LICENSE000066400000000000000000000146331447150276500144100ustar00rootroot00000000000000CC0 1.0 Universal Statement of Purpose The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work"). Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others. For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights. 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following: i. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work; ii. moral rights retained by the original author(s) and/or performer(s); iii. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work; iv. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below; v. rights protecting the extraction, dissemination, use and reuse of data in a Work; vi. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and vii. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof. 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose. 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose. 4. Limitations and Disclaimers. a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document. b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law. c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work. d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work. For more information, please see bats-file-0.4.0/README.md000066400000000000000000000557021447150276500146640ustar00rootroot00000000000000# bats-file [![GitHub license](https://img.shields.io/badge/license-CC0-blue.svg)](https://raw.githubusercontent.com/bats-core/bats-file/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/bats-core/bats-file.svg)](https://github.com/bats-core/bats-file/releases/latest) [![Tests](https://github.com/bats-core/bats-file/actions/workflows/tests.yml/badge.svg)](https://github.com/bats-core/bats-file/actions/workflows/tests.yml) `bats-file` is a helper library providing common filesystem related assertions and helpers for [Bats][bats]. Assertions are functions that perform a test and output relevant information on failure to help debugging. They return 1 on failure and 0 otherwise. Output, [formatted][bats-support-output] for readability, is sent to the standard error to make assertions usable outside of `@test` blocks too. Features: - [assertions](#usage) - [temporary directory handling](#working-with-temporary-directories) Dependencies: - [`bats-support`][bats-support] - output formatting, function call restriction See the [shared documentation][bats-docs] to learn how to install and load this library. ## **Index of all functions** | Test File Types | Test File Attributes | Test File Content | | ----------- | ----------- | ----------- | | _Check if a **file or directory** exists!_
- [assert_exists](#assert_exists)
- [assert_not_exists](#assert_not_exists) | _Check if file is **executable**!_
- [assert_file_executable](#assert_file_executable)
- [assert_file_not_executable](#assert_file_not_executable) | _Check if file is **empty**!_
- [assert_file_empty](#assert_file_empty)
- [assert_file_not_empty](#assert_file_not_empty) | | _Check if a **file** exists!_
- [assert_file_exists](#assert_file_exists)
- [assert_file_not_exists](#assert_file_not_exists) | _Check the **owner** of a file!_
- [assert_file_owner](#assert_file_owner)
- [assert_file_not_owner](#assert_file_not_owner) | _Check if file **contains regex**!_
- [assert_file_contains](#assert_file_contains)
- [assert_file_not_contains](#assert_file_not_contains) | | _Check if a **directory** exists!_
- [assert_dir_exists](#assert_dir_exists)
- [assert_dir_not_exists](#assert_dir_not_exists) | _Check the **permission** of a file!_
- [assert_file_permission](#assert_file_permission)
- [assert_not_file_permission](#assert_not_file_permission) | _Check if file is a **symlink to target**!_
- [assert_symlink_to](#assert_symlink_to)
- [assert_not_symlink_to](#assert_not_symlink_to) | | _Check if a **link** exists!_
- [assert_link_exists](#assert_link_exists)
- [assert_link_not_exists](#assert_link_not_exists) | _Check the **size** of a file **by bytes**!_
- [assert_file_size_equals](#assert_file_size_equals) | | _Check if a **block special file** exists!_
- [assert_block_exists](#assert_block_exists)
- [assert_block_not_exists](#assert_block_not_exists) | _Check if a file have **zero bytes**!_
- [assert_size_zero](#assert_size_zero)
- [assert_size_not_zero](#assert_size_not_zero) | | _Check if a **character special file** exists!_
- [assert_character_exists](#assert_character_exists)
- [assert_character_not_exists](#assert_character_not_exists) | _Check the **groupID** of a file!_
- [assert_file_group_id_set](#assert_file_group_id_set)
- [assert_file_not_group_id_set](#assert_file_not_group_id_set) | | _Check if a **socket** exists!_
- [assert_socket_exists](#assert_socket_exists)
- [assert_socket_not_exists](#assert_socket_not_exists) | _Check the **userID** of a file!_
- [assert_file_user_id_set](#assert_file_user_id_set)
- [assert_file_not_user_id_set](#assert_file_not_user_id_set) | | _Check if a **fifo special file** exists!_
- [assert_fifo_exists](#assert_fifo_exists)
- [assert_fifo_not_exists](#assert_fifo_not_exists) | _Check if a **stickybit is set**!_
- [assert_sticky_bit](#assert_sticky_bit)
- [assert_no_sticky_bit](#assert_no_sticky_bit) | ## **Usage** ## _Test File Types:_ ### `assert_exists` Fail if the given file or directory does not exist. ```bash @test 'assert_exists()' { assert_exists /path/to/non-existent-file-or-dir } ``` On failure, the path is displayed. ``` -- file or directory does not exist -- path : /path/to/non-existent-file-or-dir -- ``` [Back to index](#Index-of-all-functions) ### `assert_not_exists` Fail if the given file or directory does exist. ```bash @test 'assert_not_exists()' { assert_not_exists /path/to/existent-file-or-dir } ``` On failure, the path is displayed. ``` -- file or directory exists, but it was expected to be absent -- path : /path/to/existent-file-or-dir -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_file_exists` Fail if the given file does not exist. ```bash @test 'assert_file_exists()' { assert_file_exists /path/to/non-existent-file } ``` On failure, the path is displayed. ``` -- file does not exist -- path : /path/to/non-existent-file -- ``` [Back to index](#Index-of-all-functions) ### `assert_file_not_exists` Fail if the given file or directory exists. ```bash @test 'assert_file_not_exists() { assert_file_not_exists /path/to/existing-file } ``` On failure, the path is displayed. ``` -- file or directory exists, but it was expected to be absent -- path : /path/to/existing-file -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_dir_exists` Fail if the given directory does not exist. ```bash @test 'assert_dir_exists()' { assert_dir_exists /path/to/non-existent-directory } ``` On failure, the path is displayed. ``` -- directory does not exist -- path : /path/to/non-existent-directory -- ``` [Back to index](#Index-of-all-functions) ### `assert_dir_not_exists` Fail if the given directory exists. ```bash @test 'assert_dir_not_exists() { assert_dir_not_exists /path/to/existing-directory } ``` On failure, the path is displayed. ``` -- directory exists, but it was expected to be absent -- path : /path/to/existing-directory -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_link_exists` Fail if the given symbolic link does not exist. ```bash @test 'assert_link_exists()' { assert_file_exists /path/to/non-existent-link-file } ``` On failure, the path is displayed. ``` -- symbolic link does not exist -- path : /path/to/non-existent-link-file -- ``` [Back to index](#Index-of-all-functions) ### `assert_link_not_exists` Fail if the given symbolic link exists. ```bash @test 'assert_link_not_exists() { assert_file_not_exists /path/to/existing-link-file } ``` On failure, the path is displayed. ``` -- symbolic link exists, but it was expected to be absent -- path : /path/to/existing-link-file -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_block_exists` Fail if the given block special file does not exist. ```bash @test 'assert_block_exists()' { assert_file_exists /path/to/non-existent-block-file } ``` On failure, the path is displayed. ``` -- block special file does not exist -- path : /path/to/non-existent-block-file -- ``` [Back to index](#Index-of-all-functions) ### `assert_block_not_exists` Fail if the given block special file exists. ```bash @test 'assert_block_not_exists() { assert_file_not_exists /path/to/existing-block-file } ``` On failure, the path is displayed. ``` -- block special file exists, but it was expected to be absent -- path : /path/to/existing-block-file -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_character_exists` Fail if the given character special file does not exist. ```bash @test 'assert_character_exists()' { assert_file_exists /path/to/non-existent-character-file } ``` On failure, the path is displayed. ``` -- character special file does not exist -- path : /path/to/non-existent-character-file -- ``` [Back to index](#Index-of-all-functions) ### `assert_character_not_exists` Fail if the given character special file exists. ```bash @test 'assert_character_not_exists() { assert_file_not_exists /path/to/existing-character-file } ``` On failure, the path is displayed. ``` -- character special file exists, but it was expected to be absent -- path : /path/to/existing-character-file -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_socket_exists` Fail if the given socket does not exist. ```bash @test 'assert_socket_exists()' { assert_file_exists /path/to/non-existent-socket } ``` On failure, the path is displayed. ``` -- socket does not exist -- path : /path/to/non-existent-socket -- ``` [Back to index](#Index-of-all-functions) ### `assert_socket_not_exists` Fail if the given socket exists. ```bash @test 'assert_socket_not_exists() { assert_file_not_exists /path/to/existing-socket } ``` On failure, the path is displayed. ``` -- socket exists, but it was expected to be absent -- path : /path/to/existing-socket -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_fifo_exists` Fail if the given named pipe does not exist. ```bash @test 'assert_fifo_exists()' { assert_file_exists /path/to/non-existent-fifo-file } ``` On failure, the path is displayed. ``` -- fifo does not exist -- path : /path/to/non-existent-fifo-file -- ``` [Back to index](#Index-of-all-functions) ### `assert_fifo_not_exists` Fail if the given named pipe exists. ```bash @test 'assert_fifo_not_exists()' { assert_file_not_exists /path/to/existing-fifo-file } ``` On failure, the path is displayed. ``` -- named pipe exists, but it was expected to be absent -- path : /path/to/existing-fifo-file -- ``` [Back to index](#Index-of-all-functions) --- --- ## _Test File Attributes:_ ### `assert_file_executable` Fail if the given file is not executable. ```bash @test 'assert_file_executable()' { assert_file_executable /path/to/executable-file } ``` On failure, the path is displayed. ``` -- file is not executable -- path : /path/to/executable-file -- ``` [Back to index](#Index-of-all-functions) ### `assert_file_not_executable` Fail if the given file is executable. ```bash @test 'assert_file_not_executable()' { assert_file_not_executable /path/to/executable-file } ``` On failure, the path is displayed. ``` -- file is executable, but it was expected to be not executable -- path : /path/to/executable-file -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_file_owner` Fail if given user is not the owner of the given file. ```bash @test 'assert_file_owner() { assert_file_owner $owner /path/to/owner } ``` On failure, the path is displayed. ``` -- user is not the owner of the file -- path : /path/to/notowner owner : user -- ``` [Back to index](#Index-of-all-functions) ### `assert_not_file_owner` Fail if given user is the owner of the given file. ```bash @test 'assert_not_file_owner() { assert_not_file_owner $owner /path/to/notowner } ``` On failure, the path is displayed. ``` -- Fail if given user is the owner, but it was expected not to be -- path : /path/to/owner owner : $owner -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_file_permission` Fail if given file does not have given permission. ```bash @test 'assert_file_permission() { assert_file_permission $permission /path/to/permission } ``` On failure, the path is displayed. ``` -- given file does not have permissions 777 -- path : /path/to/nopermission permission: $permission -- ``` [Back to index](#Index-of-all-functions) ### `assert_not_file_permission` Fail if given file has given permission. ```bash @test 'assert_not_file_permission() { assert_not_file_permission $permission /path/to/nopermission } ``` On failure, the path is displayed. ``` -- given file has permissions 777, but it was expected not to have -- path : /path/to/permission permission : $permission -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_file_size_equals` Fail if the given file size does not match the input. ```bash @test 'assert_file_size_equals() { assert_file_size_equals /path/to/non-empty-file bytecount } ``` On failure, the path and expected bytecount are displayed. [Back to index](#Index-of-all-functions) --- ### `assert_size_zero` Fail if file is not zero byte. ```bash @test 'assert_size_zero() { assert_size_zero /path/to/zerobyte } ``` On failure, the path is displayed. ``` -- file is not zero byte -- path : /path/to/notzerobyte -- ``` [Back to index](#Index-of-all-functions) ### `assert_size_not_zero` Fail if file size is zero byte. ```bash @test 'assert_size_not_zero() { assert_size_not_zero /path/to/notzerobyte } ``` On failure, the path is displayed. ``` -- file is 0 byte, but it was expected not to be -- path : /path/to/zerobyte -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_file_group_id_set` Fail if group id is not set. ```bash @test 'assert_file_group_id_set() { assert_file_group_id_set /path/to/groupidset } ``` On failure, the path is displayed. ``` -- group id is not set -- path : /path/to/groupidnotset -- ``` [Back to index](#Index-of-all-functions) ### `assert_file_not_group_id_set` Fail if group id is set. ```bash @test 'assert_file_not_group_id_set() { assert_file_not_group_id_set /path/to/groupidnotset } ``` On failure, the path is displayed. ``` -- group id is set, but it was expected not to be -- path : /path/to/groupdidset -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_file_user_id_set` Fail if user id is not set. ```bash @test 'assert_file_user_id_set() { assert_file_user_id_set /path/to/useridset } ``` On failure, the path is displayed. ``` -- user id is not set -- path : /path/to/useridnotset -- ``` [Back to index](#Index-of-all-functions) ### `assert_file_not_user_id_set` Fail if user id is set. ```bash @test 'assert_file_not_user_id_set() { assert_file_not_user_id_set /path/to/groupidnotset } ``` On failure, the path is displayed. ``` -- user id is set, but it was expected not to be -- path : /path/to/userdidset -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_sticky_bit` Fail if stickybit is not set. ```bash @test 'assert_sticky_bit() { assert_sticky_bit /path/to/stickybit } ``` On failure, the path is displayed. ``` -- stickybit is not set -- path : /path/to/notstickybit -- ``` [Back to index](#Index-of-all-functions) ### `assert_not_sticky_bit` Fail if stickybit is set. ```bash @test 'assert_not_sticky_bit() { assert_not_sticky_bit /path/to/notstickybit } ``` On failure, the path is displayed. ``` -- stickybit is set, but it was expected not to be -- path : /path/to/stickybit -- ``` [Back to index](#Index-of-all-functions) --- ## _Test File Content:_ ### `assert_file_empty` Fail if the given file or directory is not empty. ```bash @test 'assert_file_empty()' { assert_file_empty /path/to/empty-file } ``` On failure, the path and the content of the file is displayed. ``` -- file is not empty -- path : /path/to/empty-file output (2 lines) : content-line-1 content-line-2 -- ``` [Back to index](#Index-of-all-functions) ### `assert_file_not_empty` Fail if the given file or directory empty. ```bash @test 'assert_file_not_empty() { assert_file_not_empty /path/to/non-empty-file } ``` On failure, the path is displayed. ``` -- file empty, but it was expected to contain something -- path : /path/to/non-empty-file -- ``` [Back to index](#Index-of-all-functions) --- ### `assert_file_contains` Fail if the given file does not contain the regex. ```bash @test 'assert_file_contains() { assert_file_contains /path/to/non-empty-file regex } ``` On failure, the path and expected regex are displayed. [Back to index](#Index-of-all-functions) --- ### `assert_file_not_contains` Fail if the given file contains the regex or if the file does not exist. ```bash @test 'assert_file_not_contains() { assert_file_not_contains /path/to/non-empty-file regex } ``` On failure, the path and regex are displayed. [Back to index](#Index-of-all-functions) --- ### `assert_symlink_to` Fail if the given file is not a symbolic to a defined target. ```bash @test 'assert_symlink_to() { assert_symlink_to /path/to/source-file /path/to/symlink } ``` On failure, the path is displayed. ``` -- symbolic link does not have the correct target -- path : /path/to/symlink -- ``` [Back to index](#Index-of-all-functions) ### `assert_not_symlink_to` Fail if the given file is a symbolic to a defined target. ```bash @test 'assert_not_symlink_to() { assert_not_symlink_to /path/to/source-file /path/to/symlink } ``` On failure, the path is displayed. ``` -- file is a symbolic link -- path : /path/to/symlink -- -- symbolic link does have the correct target -- path : /path/to/symlink -- ``` [Back to index](#Index-of-all-functions) --- --- ## Working with temporary directories When testing code that manipulates the filesystem, it is good practice to run tests in clean, throw-away environments to ensure correctness and reproducibility. Therefore, this library includes convenient functions to create and destroy temporary directories. ### `temp_make` Create a temporary directory for the current test in `BATS_TMPDIR`. The directory is guaranteed to be unique and its name is derived from the test's filename and number for easy identification. ``` -- ``` This information is only available in `setup`, `@test` and `teardown`, thus the function must be called from one of these locations. The path of the directory is displayed on the standard output and is meant to be captured into a variable. ```bash setup() { TEST_TEMP_DIR="$(temp_make)" } ``` For example, for the first test in `sample.bats`, this snippet creates a directory named `sample.bats-1-XXXXXXXXXX`, where each trailing `X` is a random alphanumeric character. If the directory cannot be created, the function fails and displays an error message on the standard error. ``` -- ERROR: temp_make -- mktemp: failed to create directory via template ‘/etc/samle.bats-1-XXXXXXXXXX’: Permission denied -- ``` #### Directory name prefix The directory name can be prefixed with an arbitrary string using the `--prefix ` option (`-p ` for short). ```bash setup() { TEST_TEMP_DIR="$(temp_make --prefix 'myapp-')" } ``` Following the previous example, this will create a directory named `myapp-sample.bats-1-XXXXXXXXXX`. This can be used to group temporary directories. Generally speaking, the directory name is of the following form. ``` -- ``` ### `temp_del` Delete a temporary directory, typically created with `temp_make`. ```bash teardown() { temp_del "$TEST_TEMP_DIR" } ``` If the directory cannot be deleted, the function fails and displays an error message on the standard error. ``` -- ERROR: temp_del -- rm: cannot remove '/etc/samle.bats-1-04RUVmBP7x': No such file or directory -- ``` _**Note:** Actually, this function can be used to delete any file or directory. However, it is most useful in deleting temporary directories created with `temp_make`, hence the naming._ #### Preserve directory During development, it is useful to peak into temporary directories post-mortem to see what the tested code has done. When `BATSLIB_TEMP_PRESERVE` is set to 1, the function succeeds but the directory is not deleted. ```bash $ BATSLIB_TEMP_PRESERVE=1 bats sample.bats ``` #### Preserve directory on failure During debugging, it is useful to preserve the temporary directories of failing tests. When `BATSLIB_TEMP_PRESERVE_ON_FAILURE` is set to 1, the function succeeds but the directory is not deleted if the test has failed. ```bash $ BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 bats sample.bats ``` The outcome of a test is only known in `teardown`, therefore this feature can be used only when `temp_del` is called from that location. Otherwise and error is displayed on the standard error. ## Transforming displayed paths Sometimes paths can be long and tiresome to parse to the human eye. To help focus on the interesting bits, all functions support hiding part of the displayed paths by replacing it with an arbitrary string. A single [pattern substitution][bash-pe] is performed on the path before displaying it. ``` ${path/$BATSLIB_FILE_PATH_REM/$BATSLIB_FILE_PATH_ADD} ``` The longest match of the pattern `BATSLIB_FILE_PATH_REM` is replaced with `BATSLIB_FILE_PATH_ADD`. To anchor the pattern to the beginning or the end, prepend `#` or `%`, respectively. For example, the following example hides the path of the temporary directory where the test takes place. ```bash setup { TEST_TEMP_DIR="$(temp_make)" BATSLIB_FILE_PATH_REM="#${TEST_TEMP_DIR}" BATSLIB_FILE_PATH_ADD='' } @test 'assert_file_exists()' { assert_file_exists "${TEST_TEMP_DIR}/path/to/non-existent-file" } teardown() { temp_del "$TEST_TEMP_DIR" } ``` On failure, only the relevant part of the path is shown. ``` -- file does not exist -- path : /path/to/non-existent-file -- ``` ## **Development** No one would want to develop piece of bash dependant libraries on their laptops due to single mistake (globbing for instance) can cause a disaster. In order to prevent this there is a Vagrantfile that you can use. In order to start development environment, you have to take two steps; ```shell user@localhost:~/bats-file$ vagrant up ``` The line above spins up a brand new virtualbox image and provisions with prerequisites. However, as the tests require not to be on a network share due to running commands eg: `mknod`, the files are shared into the VM by `rsync` module. Rsync in vagrant only runs initialy and stops. During the active development, you regularly change files and might want to see the impact. To achive that, you have to use auto rsync. > `auto-rsync` is a long running command. It means that it has to run on terminal screen as long as the VM is up and running. So, you have to keep this in a dedicated terminal screen. After bringing up the VM, you can simply run following command; ```shell user@localhost:~/bats-file$ vagrant rsync-auto ``` **WARNING! WARNING! WARNING!:** There will be a small delay between file save and sync. When you save a file please keep eye on the terminal window/pane and sync is triggered and finished. Simply run your next test with 5s-10s delay. The repo files can be found under `/home/vagrant/bats-file` and you can run tests with ```shell user@localhost:~/bats-file$ bats test # or user@localhost:~/bats-file$ bats test/on-particular-test.bats ``` Once you're done with development, you can simply turn the VM off with ```shell user@localhost:~/bats-file$ vagrant halt ``` ### Why? - Why Vagrant, not Docker - This replicates the 100% CI - Why EoL Xenial image - This replicates the 100% CI. Also, one step at a time. This wasn't in place at all. However, this change will bring up other concerns. So, that problems should be solved at another time. [bats]: https://github.com/bats-core/bats-core [bats-support-output]: https://github.com/bats-core/bats-support#output-formatting [bats-support]: https://github.com/bats-core/bats-support [bats-docs]: https://github.com/ztombol/bats-docs [bash-pe]: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html bats-file-0.4.0/Vagrantfile000066400000000000000000000020171447150276500155610ustar00rootroot00000000000000# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.box = "ubuntu/xenial64" config.vm.network "public_network" config.vm.synced_folder ".", "/home/vagrant/bats-file/", type: "rsync", rsync__exclude: [ ".git/", ".gitignore", "*.yml", "*.md", "LICENSE", "*.json", "*.log", "Vagrantfile", ], rsync__args: ["--verbose", "--archive", "--delete", "-z"] config.vm.provider "virtualbox" do |vb| # vb.gui = true vb.memory = "1024" end config.vm.provision "shell", privileged: true, inline: <<-SHELL apt-get update apt-get install -y git vim curl ln -s /usr/bin/python3 /usr/bin/python SHELL config.vm.provision "shell", privileged: false, inline: <<-SHELL mkdir -p $HOME/.local/bin echo 'export PATH="$PATH:$HOME/.local/bin"' >> /home/vagrant/.bashrc git clone --depth 1 https://github.com/bats-core/bats-support /home/vagrant/bats-support /home/vagrant/bats-file/script/install-bats.sh SHELL end bats-file-0.4.0/load.bash000066400000000000000000000001541447150276500151520ustar00rootroot00000000000000source "$(dirname "${BASH_SOURCE[0]}")/src/file.bash" source "$(dirname "${BASH_SOURCE[0]}")/src/temp.bash" bats-file-0.4.0/package.json000066400000000000000000000002571447150276500156660ustar00rootroot00000000000000{ "name": "bats-file", "version": "0.2.0", "private": true, "peerDependencies": { "bats-support": "git+https://github.com/bats-core/bats-support.git#v0.3.0" } } bats-file-0.4.0/script/000077500000000000000000000000001447150276500147005ustar00rootroot00000000000000bats-file-0.4.0/script/install-bats.sh000077500000000000000000000002561447150276500176370ustar00rootroot00000000000000#!/bin/sh set -o errexit set -o xtrace git clone --depth 1 https://github.com/bats-core/bats-core cd bats-core && ./install.sh "${HOME}/.local" && cd .. && rm -rf bats-core bats-file-0.4.0/src/000077500000000000000000000000001447150276500141635ustar00rootroot00000000000000bats-file-0.4.0/src/file.bash000066400000000000000000000722551447150276500157540ustar00rootroot00000000000000# # bats-file - Common filesystem assertions and helpers for Bats # # Written in 2016 by Zoltan Tombol # # To the extent possible under law, the author(s) have dedicated all # copyright and related and neighboring rights to this software to the # public domain worldwide. This software is distributed without any # warranty. # # You should have received a copy of the CC0 Public Domain Dedication # along with this software. If not, see # . # # # file.bash # --------- # # Assertions are functions that perform a test and output relevant # information on failure to help debugging. They return 1 on failure # and 0 otherwise. # # All output is formatted for readability using the functions of # `output.bash' and sent to the standard error. # # Fail and display path of the file or directory if it does not exist. # This function is the logical complement of `assert_not_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - file or directory exists # 1 - otherwise # Outputs: # STDERR - details, on failure assert_exists() { local -r file="$1" if [[ ! -e "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'file or directory does not exist' \ | fail fi } # Fail and display path of the file if it does not exist. # This function is the logical complement of `assert_file_not_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - file exists # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_exists() { local -r file="$1" if [[ ! -f "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'file does not exist' \ | fail fi } # Fail and display path of the directory if it does not exist. # This function is the logical complement of `assert_dir_not_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - directory exists # 1 - otherwise # Outputs: # STDERR - details, on failure assert_dir_exists() { local -r file="$1" if [[ ! -d "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'directory does not exist' \ | fail fi } # Fail and display path of the block special file if it does not exist. # This function is the logical complement of `assert_block_not_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - block special file exists # 1 - otherwise # Outputs: # STDERR - details, on failure assert_block_exists() { local -r file="$1" if [[ ! -b "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'block special file does not exist' \ | fail fi } # Fail and display path of the character special file if it does not exist. # This function is the logical complement of `assert_character_not_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - character special file exists # 1 - otherwise # Outputs: # STDERR - details, on failure assert_character_exists() { local -r file="$1" if [[ ! -c "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'character special file does not exist' \ | fail fi } # Fail and display path of the symbolic link if it does not exist. # This function is the logical complement of `assert_link_not_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - symbolic link exists # 1 - otherwise # Outputs: # STDERR - details, on failure assert_link_exists() { local -r file="$1" if [[ ! -L "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'symbolic link does not exist' \ | fail fi } # Fail and display path of the socket if it does not exist. # This function is the logical complement of `assert_socket_not_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - socket exists # 1 - otherwise # Outputs: # STDERR - details, on failure assert_socket_exists() { local -r file="$1" if [[ ! -S "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'socket does not exist' \ | fail fi } # Fail and display path of the named pipe if it does not exist. # This function is the logical complement of `assert_fifo_not_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - named pipe exists # 1 - otherwise # Outputs: # STDERR - details, on failure assert_fifo_exists() { local -r file="$1" if [[ ! -p "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'fifo does not exist' \ | fail fi } # Fail and display path of the named file if it is not executable. # This function is the logical complement of `assert_file_not_executable'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - named pipe exists # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_executable() { local -r file="$1" if [[ ! -x "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'file is not executable' \ | fail fi } # Fail and display path of both files if they are not equal. # This function is the logical complement of `assert_files_not_equal'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - 1st path # $2 - 2nd path # Returns: # 0 - named files are the same # 1 - otherwise # Outputs: # STDERR - details, on failure assert_files_equal() { local -r file1="$1" local -r file2="$2" if ! cmp -s "$file1" "$file2" >/dev/null ; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file1/$rem/$add}" 'path' "${file2/$rem/$add}" \ | batslib_decorate 'files are not the same' \ | fail fi } # Get the owner of a file # Arguments: # $1 - output variable name # $2 - path to file _bats_get_file_owner() { local -r output_var=$1 local -r file=$2 if [[ "$OSTYPE" == darwin* ]]; then local -ra cmd_params=(-f %Su) else local -ra cmd_params=(-c %U) fi printf -v "$output_var" "%s" "$(stat "${cmd_params[@]}" "$file")" } # Fail and display path of the user is not the owner of a file. This # function is the logical complement of `assert_file_not_owner'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - owns file # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_owner() { local -r owner="$1" local -r file="$2" local actual_owner _bats_get_file_owner actual_owner "$file" readonly actual_owner if [[ "$actual_owner" != "$owner" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate "user $owner is not the owner of the file" \ | fail fi } # Fail if file does not have given permissions. This # function is the logical complement of `assert_file_not_permission'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - permission # $2 - path # Returns: # 0 - file has given permissions # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_permission() { local -r permission="$1" local -r file="$2" if [[ "$OSTYPE" == darwin* ]]; then local -r actual_permission=$(stat -f '%A' "$file") else local -r actual_permission=$(stat -c "%a" "$file") fi if [[ "$actual_permission" != "$permission" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate "file does not have permissions $permission" \ | fail fi } # Fail if file is not zero byte. This # function is the logical complement of `assert_size_not_zero'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - file size is zero byte # 1 - otherwise # Outputs: # STDERR - details, on failure assert_size_zero() { local -r file="$1" if [ -s "$file" ]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'file is greater than 0 byte' \ | fail fi } # Fail if group if is not set on file. This # function is the logical complement of `assert_file_not_group_id_set'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - group id is set # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_group_id_set() { local -r file="$1" if [[ ! -g "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'set-group-ID is not set' \ | fail fi } # Fail if user if is not set on file. This # function is the logical complement of `assert_file_not_user_id_set'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - user id is set # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_user_id_set() { local -r file="$1" if [[ ! -u "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'set-user-ID is not set' \ | fail fi } # Fail if stickybit not set on file. This # function is the logical complement of `assert_sticky_bit'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - stickybit is set # 1 - otherwise # Outputs: # STDERR - details, on failure assert_sticky_bit() { local -r file="$1" if [[ ! -k "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'stickybit is not set' \ | fail fi } _bats_file_readlinkf_macos() { local TARGET_FILE=$1 cd "$(dirname "$TARGET_FILE")" 2>/dev/null || return TARGET_FILE=$(basename "$TARGET_FILE") # Iterate down a (possible) chain of symlinks while [ -L "$TARGET_FILE" ] do TARGET_FILE=$(readlink "$TARGET_FILE") cd "$(dirname "$TARGET_FILE")" 2>/dev/null || return TARGET_FILE=$(basename "$TARGET_FILE") done # Compute the canonicalized name by finding the physical path # for the directory we're in and appending the target file. local -r PHYS_DIR=$(pwd -P) printf "%s/%s\n" "$PHYS_DIR" "$TARGET_FILE" } # Fail and display path of the file (or directory) if it is not a symlink to given destination. # function is the logical complement of `assert_not_symlink_to` # $1 - source # $2 - destination # Returns: # 0 - link to correct target # 1 - otherwise # Outputs: # STDERR - details, on failure assert_symlink_to() { local -r sourcefile="$1" local -r link="$2" # If OS is OSX, emulate readlink -f if [[ $OSTYPE == "darwin"* ]]; then local -ra readlink_command=(_bats_file_readlinkf_macos) else local -ra readlink_command=(readlink -f) fi if [ ! -L "$link" ]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${link/$rem/$add}" \ | batslib_decorate 'file is not a symbolic link' \ | fail fi local realsource; realsource=$( "${readlink_command[@]}" "$link" ); readonly realsource local realexpectedsource; realexpectedsource=$( "${readlink_command[@]}" "$sourcefile" ); readonly realexpectedsource if [ ! "${realsource}" = "${realexpectedsource}" ]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${link/$rem/$add}" \ | batslib_decorate 'symbolic link does not have the correct target' \ | fail fi } # Fail and display path of the file (or directory) if it does not match a size. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # $2 - expected size (bytes) # Returns: # 0 - file is correct size # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_size_equals() { local -r file="$1" local -r expectedsize="$2" local -r size=$( wc -c "$file" | awk '{print $1}' ) if [ ! "$expectedsize" = "$size" ]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'file size does not match expected size' \ | fail fi } # Fail and display path of the file (or directory) if it does not contain a string. # This function is the logical complement of `assert_file_not_contains'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # $2 - regex # Returns: # 0 - file contains regex # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_contains() { local -r file="$1" local -r regex="$2" if ! grep -q "$regex" "$file"; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" 'regex' "$regex" \ | batslib_decorate 'file does not contain regex' \ | fail fi } # Fail and display path of the file (or directory) if it does contain a string. # This function is the logical complement of `assert_file_contains'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # $2 - regex # Returns: # 0 - file does not contain regex # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_not_contains() { local -r file="$1" local -r regex="$2" if [[ ! -f "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" 'regex' "$regex" \ | batslib_decorate 'file does not exist' \ | fail elif grep -q "$regex" "$file"; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" 'regex' "$regex" \ | batslib_decorate 'file contains regex' \ | fail fi } # Fail and display path of the file (or directory) if it is not empty. # This function is the logical complement of `assert_file_not_empty'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - file empty # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_empty() { local -r file="$1" if [[ -s "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" { local -ir width=8 batslib_print_kv_single "$width" 'path' "${file/$rem/$add}" batslib_print_kv_single_or_multi "$width" \ 'output' "$(cat "$file")" } | batslib_decorate 'file is not empty' \ | fail fi } # Fail and display path of the file (or directory) if it exists. This # function is the logical complement of `assert_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - file does not exist # 1 - otherwise # Outputs: # STDERR - details, on failure assert_not_exists() { local -r file="$1" if [[ -e "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'file or directory exists, but it was expected to be absent' \ | fail fi } # Fail and display path of the file if it exists. This # function is the logical complement of `assert_file_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - file does not exist # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_not_exists() { local -r file="$1" if [[ -f "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'file exists, but it was expected to be absent' \ | fail fi } # Fail and display path of the directory if it exists. This # function is the logical complement of `assert_dir_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - directory does not exist # 1 - otherwise # Outputs: # STDERR - details, on failure assert_dir_not_exists() { local -r file="$1" if [[ -d "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'directory exists, but it was expected to be absent' \ | fail fi } # Fail and display path of the block special file if it exists. This # function is the logical complement of `assert_block_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - block special file does not exist # 1 - otherwise # Outputs: # STDERR - details, on failure assert_block_not_exists() { local -r file="$1" if [[ -b "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'block special file exists, but it was expected to be absent' \ | fail fi } # Fail and display path of the character special file if it exists. This # function is the logical complement of `assert_character_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - character special file does not exist # 1 - otherwise # Outputs: # STDERR - details, on failure assert_character_not_exists() { local -r file="$1" if [[ -c "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'character special file exists, but it was expected to be absent' \ | fail fi } # Fail and display path of the symbolic link if it exists. This # function is the logical complement of `assert_link_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - symbolic link does not exist # 1 - otherwise # Outputs: # STDERR - details, on failure assert_link_not_exists() { local -r file="$1" if [[ -L "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'symbolic link exists, but it was expected to be absent' \ | fail fi } # Fail and display path of the socket if it exists. This # function is the logical complement of `assert_socket_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - socket does not exist # 1 - otherwise # Outputs: # STDERR - details, on failure assert_socket_not_exists() { local -r file="$1" if [[ -S "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'socket exists, but it was expected to be absent' \ | fail fi } # Fail and display path of the named pipe if it exists. This # function is the logical complement of `assert_fifo_exists'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - named pipe does not exist # 1 - otherwise # Outputs: # STDERR - details, on failure assert_fifo_not_exists() { local -r file="$1" if [[ -p "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'fifo exists, but it was expected to be absent' \ | fail fi } # Fail and display path of the named file if it is executable. This # function is the logical complement of `assert_file_executable'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - named pipe does not exist # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_not_executable() { local -r file="$1" if [[ -x "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'file is executable, but it was expected to be not executable' \ | fail fi } # Fail if the user is not the owner of the given file.. This # function is the logical complement of `assert_file_owner'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - is not an owner # 1 - otherwise # Outputs: # STDERR - details, on failure assert_not_file_owner() { local -r expected_owner="$1" local -r file="$2" local actual_owner _bats_get_file_owner actual_owner "$file" readonly actual_owner if [[ "$actual_owner" == "$expected_owner" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate "user $expected_owner is the owner of the file, but it was expected not to be" \ | fail fi } # Fail if the file has given permissions. This # function is the logical complement of `assert_file_permission'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - does not have given permissions # 1 - otherwise # Outputs: # STDERR - details, on failure assert_not_file_permission() { local -r permission="$1" local -r file="$2" if [[ "$OSTYPE" == darwin* ]]; then local -r actual_permission=$(stat -f '%A' "$file") else local -r actual_permission=$(stat -c "%a" "$file") fi if [ "$actual_permission" -eq "$permission" ]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate "file has permissions $permission, but it was expected not to have" \ | fail fi } # This function is the logical complement of `assert_files_equal'. # $1 - 1st path # $2 - 2nd path # Returns: # 0 - named files are the same # 1 - otherwise # Outputs: # STDERR - details, on failure assert_files_not_equal() { local -r file1="$1" local -r file2="$2" if cmp -s "$file1" "$file2" >/dev/null ; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file1/$rem/$add}" 'path' "${file2/$rem/$add}" \ | batslib_decorate 'files are the same' \ | fail fi } # Fail if The file size is zero byte. This # function is the logical complement of `assert_size_zero'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - size is not 0 byte # 1 - otherwise # Outputs: # STDERR - details, on failure assert_size_not_zero() { local -r file="$1" if [[ ! -s "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'file is 0 byte, but it was expected not to be' \ | fail fi } # Fail if group id is set. This # function is the logical complement of `assert_file_group_id_set'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - group id is not set # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_not_group_id_set() { local -r file="$1" if [ -g "$file" ]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'group id is set, but it was expected not to be' \ | fail fi } # Fail if user id is set. This # function is the logical complement of `assert_file_user_id_set'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - user id is not set # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_not_user_id_set() { local -r file="$1" if [ -u "$file" ]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'user id is set, but it was expected not to be' \ | fail fi } # Fail if stickybit is set. This # function is the logical complement of `assert_sticky_bit'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - stickybit not set # 1 - otherwise # Outputs: # STDERR - details, on failure assert_no_sticky_bit() { local -r file="$1" if [ -k "$file" ]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'stickybit is set, but it was expected not to be' \ | fail fi } # Fail and display path of the file (or directory) if it is a symlink. # function is the logical complement of `assert_symlink_to'. # $1 - source # $2 - destination # Returns: # 0 - link to correct target # 1 - otherwise # Outputs: # STDERR - details, on failure assert_not_symlink_to() { local -r sourcefile="$1" local -r link="$2" if [[ $OSTYPE == darwin* ]]; then local -ra readlink_command=(_bats_file_readlinkf_macos) else local -ra readlink_command=(readlink -f) fi if [ -L "$link" ]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${link/$rem/$add}" \ | batslib_decorate 'file is a symbolic link' \ | fail fi local -r realsource=$( "${readlink_command[@]}" "$link" ) if [ "$realsource" = "$sourcefile" ]; then batslib_print_kv_single 4 'path' "${link/$rem/$add}" \ | batslib_decorate 'symbolic link does have the correct target' \ | fail fi } # Fail and display path of the file (or directory) if it is empty. This # function is the logical complement of `assert_file_empty'. # # Globals: # BATSLIB_FILE_PATH_REM # BATSLIB_FILE_PATH_ADD # Arguments: # $1 - path # Returns: # 0 - file is not empty # 1 - otherwise # Outputs: # STDERR - details, on failure assert_file_not_empty() { local -r file="$1" if [[ ! -s "$file" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ | batslib_decorate 'file empty, but it was expected to contain something' \ | fail fi } # Aliases to old assertion names assert_exist() { assert_exists "$@"; } assert_not_exist() { assert_not_exists "$@"; } assert_file_exist() { assert_file_exists "$@"; } assert_file_not_exist() { assert_file_not_exists "$@"; } assert_dir_exist() { assert_dir_exists "$@"; } assert_dir_not_exist() { assert_dir_not_exists "$@"; } assert_link_exist() { assert_link_exists "$@"; } assert_link_not_exist() { assert_link_not_exists "$@"; } assert_block_exist() { assert_block_exists "$@"; } assert_block_not_exist() { assert_block_not_exists "$@"; } assert_character_exist() { assert_character_exists "$@"; } assert_character_not_exist() { assert_character_not_exists "$@"; } assert_socket_exist() { assert_socket_exists "$@"; } assert_socket_not_exist() { assert_socket_not_exists "$@"; } assert_fifo_exist() { assert_fifo_exists "$@"; } assert_fifo_not_exist() { assert_fifo_not_exists "$@"; } bats-file-0.4.0/src/temp.bash000066400000000000000000000107711447150276500157750ustar00rootroot00000000000000# # bats-file - Common filesystem assertions and helpers for Bats # # Written in 2016 by Zoltan Tombol # # To the extent possible under law, the author(s) have dedicated all # copyright and related and neighboring rights to this software to the # public domain worldwide. This software is distributed without any # warranty. # # You should have received a copy of the CC0 Public Domain Dedication # along with this software. If not, see # . # # # temp.bash # --------- # # Functions for handling temporary directories. # # Create a temporary directory for the current test in `BATS_TMPDIR`, # and display its path on the standard output. # # The directory name is derived from the test's filename and number, and # a random string for uniqueness. # # -- # # When `--prefix ' is specified, `' is prepended to the # directory name. # # -- # # Must be called from `setup', `@test' or `teardown'. # # Example: # # setup() { # TEST_TEMP_DIR="$(temp_make --prefix 'myapp-')" # } # # teardown() { # temp_del "$TEST_TEMP_DIR" # } # # Globals: # BATS_TEST_NAME # BATS_TEST_FILENAME # BATS_TEST_NUMBER # BATS_TMPDIR # Arguments: # none # Options: # -p, --prefix - prefix the directory name with `' # Returns: # 0 - on success # 1 - otherwise # Outputs: # STDOUT - path of temporary directory # STDERR - error messages temp_make() { # Check caller. if ! ( batslib_is_caller --indirect 'setup' \ || batslib_is_caller --indirect 'setup_file' \ || batslib_is_caller --indirect "$BATS_TEST_NAME" \ || batslib_is_caller --indirect 'teardown' \ || batslib_is_caller --indirect 'teardown_file' ) then echo "Must be called from \`setup', \`@test' or \`teardown'" \ | batslib_decorate 'ERROR: temp_make' \ | fail return $? fi # Handle options. local prefix='' while (( $# > 0 )); do case "$1" in -p|--prefix) if (( $# < 2 )); then echo "\`--prefix' requires an argument" \ | batslib_decorate 'ERROR: temp_make' \ | fail return $? fi prefix="$2" shift 2 ;; --) shift; break ;; *) break ;; esac done # Create directory. local template="$prefix" template+="${BATS_TEST_FILENAME##*/}" template+="-${BATS_TEST_NUMBER}" template+='-XXXXXX' local path if ! path="$(mktemp -d -- "${BATS_TMPDIR}/${template}" 2>&1)"; then echo "$path" \ | batslib_decorate 'ERROR: temp_make' \ | fail return $? fi echo "$path" } # Delete a temporary directory, typically created with `temp_make', and # its contents. # # Note: Actually, this function can be used to delete any file or # directory. However, it is most useful in deleting temporary # directories created with `temp_make', hence the naming. # # For development and debugging, deletion can be prevented using # environment variables. # # When `BATSLIB_TEMP_PRESERVE' is set to 1, the function succeeds but # the directory is not deleted. # # When `BATSLIB_TEMP_PRESERVE_ON_FAILURE' is set to 1 and `temp_del' is # called, directly or indirectly, from `teardown', the function succeeds # but the directory is not deleted if the test has failed. # # Example: # # setup() { # TEST_TEMP_DIR="$(temp_make --prefix 'myapp-')" # } # # teardown() { # temp_del "$TEST_TEMP_DIR" # } # # Globals: # BATSLIB_TEMP_PRESERVE # BATSLIB_TEMP_PRESERVE_ON_FAILURE # BATS_TEST_COMPLETED # Arguments: # $1 - path of directory # Returns: # 0 - on success # 1 - otherwise # Outputs: # STDERR - error messages temp_del() { local -r path="$1" # Environment variables. if [[ ${BATSLIB_TEMP_PRESERVE-} == '1' ]]; then return 0 elif [[ ${BATSLIB_TEMP_PRESERVE_ON_FAILURE-} == '1' ]]; then # Check caller. if ! ( batslib_is_caller --indirect 'teardown' \ || batslib_is_caller --indirect 'teardown_file' ) then echo "Must be called from \`teardown' or \`teardown_file' when using \`BATSLIB_TEMP_PRESERVE_ON_FAILURE'" \ | batslib_decorate 'ERROR: temp_del' \ | fail return $? fi (( ${BATS_TEST_COMPLETED:-0} != 1 )) && return 0 fi # Delete directory. local result if ! result="$(rm -r -- "$path" 2>&1 >/dev/null )"; then echo "$result" \ | batslib_decorate 'ERROR: temp_del' \ | fail return $? fi } bats-file-0.4.0/test/000077500000000000000000000000001447150276500143535ustar00rootroot00000000000000bats-file-0.4.0/test/50-assert-10-assert_exists.bats000077500000000000000000000042701447150276500220730ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/file } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/file } # Correctness @test 'assert_exists() : returns 0 if exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_exists() : returns 0 if exists' { local -r file="${TEST_FIXTURE_ROOT}/dir" run assert_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_exists() : returns 1 and displays path if does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir/file.does_not_exists" run assert_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory does not exist --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_exists "${TEST_FIXTURE_ROOT}/dir/file.does_not_exist" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory does not exist --' ] [ "${lines[1]}" == "path : ../dir/file.does_not_exist" ] [ "${lines[2]}" == '--' ] } @test 'assert_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file.does_not_exist' local -r BATSLIB_FILE_PATH_ADD='..' run assert_exists "${TEST_FIXTURE_ROOT}/dir/file.does_not_exist" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_exists "${TEST_FIXTURE_ROOT}/dir/file.does_not_exist" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../file.does_not_exist" ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/50-assert-11-assert_not_exists.bats000066400000000000000000000040611447150276500227470ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/file } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/file } # Correctness @test 'assert_not_exists() : returns 0 if does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir/file.does_not_exists" run assert_not_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_not_exists() : returns 1 and displays path if exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_not_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_not_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_not_exists "${TEST_FIXTURE_ROOT}/dir/file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ../dir/file" ] [ "${lines[2]}" == '--' ] } @test 'assert_not_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_not_exists "${TEST_FIXTURE_ROOT}/dir/file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_not_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_not_exists "${TEST_FIXTURE_ROOT}/dir/file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../file" ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/51-assert-10-assert_file_exists.bats000077500000000000000000000035761447150276500231030ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/file } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/file } # Correctness @test 'assert_file_exists() : returns 0 if exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_file_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_exists() : returns 1 and displays path if does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir" run assert_file_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file does not exist --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_file_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_exists "${TEST_FIXTURE_ROOT}/dir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file does not exist --' ] [ "${lines[1]}" == "path : ../dir" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file.does_not_exists' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_exists "${TEST_FIXTURE_ROOT}/dir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_exists "${TEST_FIXTURE_ROOT}/dir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/51-assert-11-assert_file_not_exists.bats000077500000000000000000000040611447150276500237520ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/file } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/file } # Correctness @test 'assert_not_exists() : returns 0 if does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir/file.does_not_exists" run assert_not_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_not_exists() : returns 1 and displays path if exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_not_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_not_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_not_exists "${TEST_FIXTURE_ROOT}/dir/file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ../dir/file" ] [ "${lines[2]}" == '--' ] } @test 'assert_not_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_not_exists "${TEST_FIXTURE_ROOT}/dir/file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_not_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_not_exists "${TEST_FIXTURE_ROOT}/dir/file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file or directory exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../file" ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/52-assert-10-assert_file_executable.bats000066400000000000000000000041031447150276500236660ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/execfile ${TEST_FIXTURE_ROOT}/dir/file chmod +x ${TEST_FIXTURE_ROOT}/dir/execfile } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/execfile ${TEST_FIXTURE_ROOT}/dir/file } # Correctness @test 'assert_file_executable() : returns 0 if is executable' { local -r file="${TEST_FIXTURE_ROOT}/dir/execfile" run assert_file_executable "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_executable() : returns 1 and displays path if is not executable' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_file_executable "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is not executable --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_file_executable() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_executable "${TEST_FIXTURE_ROOT}/nodir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is not executable --' ] [ "${lines[1]}" == "path : ../nodir" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_executable() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file.does_not_exists' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_executable "${TEST_FIXTURE_ROOT}/nodir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is not executable --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/nodir" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_executable() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='nodir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_executable "${TEST_FIXTURE_ROOT}/nodir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is not executable --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/52-assert-11-assert_file_not_executable.bats000066400000000000000000000044351447150276500245570ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/execfile ${TEST_FIXTURE_ROOT}/dir/noexecfile chmod +x ${TEST_FIXTURE_ROOT}/dir/execfile } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/execfile ${TEST_FIXTURE_ROOT}/dir/noexecfile } # Correctness @test 'assert_file_not_executable() : returns 0 if is not executable' { local -r file="${TEST_FIXTURE_ROOT}/dir/noexecfile" run assert_file_not_executable "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_not_executable() : returns 1 and displays path if is executable' { local -r file="${TEST_FIXTURE_ROOT}/dir/execfile" run assert_file_not_executable "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is executable, but it was expected to be not executable --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_file_not_executable() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_executable "${TEST_FIXTURE_ROOT}/dir/execfile" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is executable, but it was expected to be not executable --' ] [ "${lines[1]}" == "path : ../dir/execfile" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_not_executable() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_executable "${TEST_FIXTURE_ROOT}/dir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is executable, but it was expected to be not executable --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_not_executable() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_executable "${TEST_FIXTURE_ROOT}/dir/execfile" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is executable, but it was expected to be not executable --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../execfile" ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/53-assert-10-assert_link_exists.bats000066400000000000000000000040461447150276500231110ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/file ln -s ${TEST_FIXTURE_ROOT}/dir/file ${TEST_FIXTURE_ROOT}/dir/link } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/link ${TEST_FIXTURE_ROOT}/dir/file } # Correctness @test 'assert_link_exists() : returns 0 if Link exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/link" run assert_link_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_link_exists() : returns 1 and displays path if symbolic link does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir/ " run assert_link_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- symbolic link does not exist --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_link_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_link_exists "${TEST_FIXTURE_ROOT}/nodir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- symbolic link does not exist --' ] [ "${lines[1]}" == "path : ../nodir" ] [ "${lines[2]}" == '--' ] } @test 'assert_link_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file.does_not_exists' local -r BATSLIB_FILE_PATH_ADD='..' run assert_link_exists "${TEST_FIXTURE_ROOT}/nodir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- symbolic link does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/nodir" ] [ "${lines[2]}" == '--' ] } @test 'assert_link_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='nodir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_link_exists "${TEST_FIXTURE_ROOT}/nodir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- symbolic link does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/53-assert-11-assert_link_not_exists.bats000066400000000000000000000043571447150276500237770ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/file ln -s ${TEST_FIXTURE_ROOT}/dir/file ${TEST_FIXTURE_ROOT}/dir/link } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/link ${TEST_FIXTURE_ROOT}/dir/file } # Correctness @test 'assert_link_not_exists() : returns 0 if is not a link' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_link_not_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_link_not_exists() : returns 1 and displays path if symbolic link exists, but it was expected to be absent' { local -r file="${TEST_FIXTURE_ROOT}/dir/link" run assert_link_not_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] echo "${lines[0]}" [ "${lines[0]}" == '-- symbolic link exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_link_not_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_link_not_exists "${TEST_FIXTURE_ROOT}/dir/link" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- symbolic link exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ../dir/link" ] [ "${lines[2]}" == '--' ] } @test 'assert_link_not_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_link_not_exists "${TEST_FIXTURE_ROOT}/dir/link" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- symbolic link exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/link" ] [ "${lines[2]}" == '--' ] } @test 'assert_link_not_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_link_not_exists "${TEST_FIXTURE_ROOT}/dir/link" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- symbolic link exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../link" ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/54-assert-10-assert_character_exists.bats000066400000000000000000000041351447150276500241100ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { bats_sudo mknod ${TEST_FIXTURE_ROOT}/dir/test_device c 89 1 } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/test_device } # Correctness @test 'assert_character_exists() : returns 0 if character special file exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/test_device" run assert_character_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_character_exists() : returns 1 and displays path if character special file does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_character_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- character special file does not exist --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_character_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_character_exists "${TEST_FIXTURE_ROOT}/nodir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- character special file does not exist --' ] [ "${lines[1]}" == "path : ../nodir" ] [ "${lines[2]}" == '--' ] } @test 'assert_character_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file.does_not_exists' local -r BATSLIB_FILE_PATH_ADD='..' run assert_character_exists "${TEST_FIXTURE_ROOT}/nodir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- character special file does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/nodir" ] [ "${lines[2]}" == '--' ] } @test 'assert_character_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='nodir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_character_exists "${TEST_FIXTURE_ROOT}/nodir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- character special file does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/54-assert-11-assert_character_not_exists.bats000066400000000000000000000044731447150276500247760ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { bats_sudo mknod ${TEST_FIXTURE_ROOT}/dir/test_device c 89 1 } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/test_device } # Correctness @test 'assert_character_not_exists() : returns 0 if character special file does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_character_not_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_character_not_exists() : returns 1 and displays path if character special file exists, but it was expected to be absent' { local -r file="${TEST_FIXTURE_ROOT}/dir/test_device" run assert_character_not_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- character special file exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_character_not_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_character_not_exists "${TEST_FIXTURE_ROOT}/dir/test_device" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- character special file exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ../dir/test_device" ] [ "${lines[2]}" == '--' ] } @test 'assert_character_not_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_character_not_exists "${TEST_FIXTURE_ROOT}/dir/test_device" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- character special file exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/test_device" ] [ "${lines[2]}" == '--' ] } @test 'assert_character_not_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_character_not_exists "${TEST_FIXTURE_ROOT}/dir/test_device" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- character special file exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../test_device" ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/55-assert-10-assert_block_exists.bats000066400000000000000000000040031447150276500232410ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { bats_sudo mknod ${TEST_FIXTURE_ROOT}/dir/blockfile b 89 1 } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/blockfile } # Correctness @test 'assert_block_exists() : returns 0 if block special file exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/blockfile" run assert_block_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_block_exists() : returns 1 and displays path if block special file does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_block_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- block special file does not exist --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_block_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_block_exists "${TEST_FIXTURE_ROOT}/dir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- block special file does not exist --' ] [ "${lines[1]}" == "path : ../dir" ] [ "${lines[2]}" == '--' ] } @test 'assert_block_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_block_exists "${TEST_FIXTURE_ROOT}/dir/file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- block special file does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_block_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_block_exists "${TEST_FIXTURE_ROOT}/dir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- block special file does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/55-assert-11-assert_block_not_exists.bats000066400000000000000000000043441447150276500241320ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { bats_sudo mknod ${TEST_FIXTURE_ROOT}/dir/blockfile b 89 1 } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/blockfile } # Correctness @test 'assert_block_not_exists() : returns 0 if block special does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_block_not_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_block_not_exists() : returns 1 and displays path if block special file exists, but it was expected to be absent' { local -r file="${TEST_FIXTURE_ROOT}/dir/blockfile" run assert_block_not_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- block special file exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_block_not_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_block_not_exists "${TEST_FIXTURE_ROOT}/dir/blockfile" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- block special file exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ../dir/blockfile" ] [ "${lines[2]}" == '--' ] } @test 'assert_block_not_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%blockfile' local -r BATSLIB_FILE_PATH_ADD='..' run assert_block_not_exists "${TEST_FIXTURE_ROOT}/dir/blockfile" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- block special file exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_block_not_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_block_not_exists "${TEST_FIXTURE_ROOT}/dir/blockfile" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- block special file exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../blockfile" ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/56-assert-10-assert_fifo_exists.bats000066400000000000000000000036221447150276500231010ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { mkfifo ${TEST_FIXTURE_ROOT}/dir/testpipe } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/testpipe } # Correctness @test 'assert_fifo_exists() : returns 0 if fifo exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/testpipe" run assert_fifo_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_fifo_exists() : returns 1 and displays path if fifo does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_fifo_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- fifo does not exist --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_fifo_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_fifo_exists "${TEST_FIXTURE_ROOT}/dir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- fifo does not exist --' ] [ "${lines[1]}" == "path : ../dir" ] [ "${lines[2]}" == '--' ] } @test 'assert_fifo_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_fifo_exists "${TEST_FIXTURE_ROOT}/dir/file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- fifo does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_fifo_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_fifo_exists "${TEST_FIXTURE_ROOT}/dir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- fifo does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/56-assert-11-assert_fifo_not_exists.bats000066400000000000000000000041641447150276500237640ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { mkfifo ${TEST_FIXTURE_ROOT}/dir/testpipe } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/testpipe } # Correctness @test 'assert_fifo_not_exists() : returns 0 if fifo does not exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_fifo_not_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_fifo_not_exists() : returns 1 and displays path if fifo exists, but it was expected to be absent' { local -r file="${TEST_FIXTURE_ROOT}/dir/testpipe" run assert_fifo_not_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- fifo exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_fifo_not_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_fifo_not_exists "${TEST_FIXTURE_ROOT}/dir/testpipe" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- fifo exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ../dir/testpipe" ] [ "${lines[2]}" == '--' ] } @test 'assert_fifo_not_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%testpipe' local -r BATSLIB_FILE_PATH_ADD='..' run assert_fifo_not_exists "${TEST_FIXTURE_ROOT}/dir/testpipe" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- fifo exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_fifo_not_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_fifo_not_exists "${TEST_FIXTURE_ROOT}/dir/testpipe" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- fifo exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../testpipe" ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/57-assert-10-assert_socket_exists.bats000066400000000000000000000037731447150276500234560ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { python -c "import socket as s; sock = s.socket(s.AF_UNIX); sock.bind('${TEST_FIXTURE_ROOT}/dir/somesocket')" } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/somesocket } # Correctness @test 'assert_socket_exists() : returns 0 if socket exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/somesocket" run assert_socket_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_socket_exists() : returns 1 and displays path if socket does not exist' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_socket_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- socket does not exist --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_socket_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_socket_exists "${TEST_FIXTURE_ROOT}/dir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- socket does not exist --' ] [ "${lines[1]}" == "path : ../dir" ] [ "${lines[2]}" == '--' ] } @test 'assert_socket_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_socket_exists "${TEST_FIXTURE_ROOT}/dir/file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- socket does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_socket_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_socket_exists "${TEST_FIXTURE_ROOT}/dir" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- socket does not exist --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/57-assert-11-assert_socket_not_exists.bats000066400000000000000000000043471447150276500243350ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { python -c "import socket as s; sock = s.socket(s.AF_UNIX); sock.bind('${TEST_FIXTURE_ROOT}/dir/somesocket')" } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/somesocket } # Correctness @test 'assert_socket_not_exists() : returns 0 if socket does not exists' { local -r file="${TEST_FIXTURE_ROOT}/dir/file" run assert_socket_not_exists "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_socket_not_exists() : returns 1 and displays path if socket exists, but it was expected to be absent' { local -r file="${TEST_FIXTURE_ROOT}/dir/somesocket" run assert_socket_not_exists "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- socket exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_socket_not_exists() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_socket_not_exists "${TEST_FIXTURE_ROOT}/dir/somesocket" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- socket exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ../dir/somesocket" ] [ "${lines[2]}" == '--' ] } @test 'assert_socket_not_exists() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%somesocket' local -r BATSLIB_FILE_PATH_ADD='..' run assert_socket_not_exists "${TEST_FIXTURE_ROOT}/dir/somesocket" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- socket exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_socket_not_exists() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_socket_not_exists "${TEST_FIXTURE_ROOT}/dir/somesocket" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- socket exists, but it was expected to be absent --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../somesocket" ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/58-assert-10-assert_equal_files.bats000066400000000000000000000063771447150276500230640ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/file_with_text ${TEST_FIXTURE_ROOT}/dir/same_file_with_text } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/file_with_text ${TEST_FIXTURE_ROOT}/dir/same_file_with_text } # Correctness @test 'assert_files_equal() : returns 0 if and are the same' { local -r file1="${TEST_FIXTURE_ROOT}/dir/file_with_text" local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" run assert_files_equal "$file1" "$file2" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_files_equal() : returns 1 if and are not the same' { local -r file1="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" local -r file2="${TEST_FIXTURE_ROOT}/dir/file" run assert_files_equal "$file1" "$file2" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- files are not the same --' ] [ "${lines[1]}" == "path : $file1" ] [ "${lines[2]}" == "path : $file2" ] [ "${lines[3]}" == "--" ] } # Transforming path @test 'assert_files_equal() : used as a directory' { local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" local -r file1="${TEST_FIXTURE_ROOT}/dir" run assert_files_equal "$file1" "$file2" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 5 ] REGEX="cmp: ${TEST_FIXTURE_ROOT}/dir: (Is a directory|I/O error)" [[ "${lines[0]}" =~ $REGEX ]] || false [ "${lines[1]}" == "-- files are not the same --" ] [ "${lines[2]}" == "path : $file1" ] [ "${lines[3]}" == "path : $file2" ] [ "${lines[4]}" == "--" ] } @test 'assert_files_equal() : replace prefix of displayed path' { local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" local -r file1="${TEST_FIXTURE_ROOT}/dir/file" local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_files_equal "$file1" "$file2" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- files are not the same --' ] [ "${lines[1]}" == "path : ../dir/file" ] [ "${lines[2]}" == "path : ../dir/same_file_with_text" ] [ "${lines[3]}" == "--" ] } @test 'assert_files_equal() : replace suffix of displayed path' { local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" local -r file1="${TEST_FIXTURE_ROOT}/same_file_with_text" local -r BATSLIB_FILE_PATH_REM='%same_file_with_text' local -r BATSLIB_FILE_PATH_ADD='..' run assert_files_equal "$file1" "$file2" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- files are not the same --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[3]}" == "--" ] } @test 'assert_files_equal() : replace infix of displayed path' { local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" local -r file1="${TEST_FIXTURE_ROOT}/dir/file" local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_files_equal "$file1" "$file2" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- files are not the same --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../file" ] [ "${lines[2]}" == "path : ${TEST_FIXTURE_ROOT}/../same_file_with_text" ] [ "${lines[3]}" == "--" ] } bats-file-0.4.0/test/58-assert-11-assert_not_equal_files.bats000066400000000000000000000063141447150276500237340ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/file_with_text ${TEST_FIXTURE_ROOT}/dir/same_file_with_text } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/file_with_text ${TEST_FIXTURE_ROOT}/dir/same_file_with_text } # Correctness @test 'assert_files_not_equal() : returns 0 if and are not the same' { local -r file1="${TEST_FIXTURE_ROOT}/dir/file_with_text" local -r file2="${TEST_FIXTURE_ROOT}/dir/file" run assert_files_not_equal "$file1" "$file2" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_files_not_equal() : returns 1 if and are the same' { local -r file1="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" local -r file2="${TEST_FIXTURE_ROOT}/dir/file_with_text" run assert_files_not_equal "$file1" "$file2" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- files are the same --' ] [ "${lines[1]}" == "path : $file1" ] [ "${lines[2]}" == "path : $file2" ] [ "${lines[3]}" == "--" ] } # Transforming path @test 'assert_files_not_equal() : used as a directory' { local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" local -r file1="${TEST_FIXTURE_ROOT}/dir" run assert_files_not_equal "$file1" "$file2" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 1 ] REGEX="cmp: ${TEST_FIXTURE_ROOT}/dir: (Is a directory|I/O error)" [[ "${lines[0]}" =~ $REGEX ]] || false } @test 'assert_files_not_equal() : replace prefix of displayed path' { local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" local -r file1="${TEST_FIXTURE_ROOT}/dir/file_with_text" local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_files_not_equal "$file1" "$file2" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- files are the same --' ] [ "${lines[1]}" == "path : ../dir/file_with_text" ] [ "${lines[2]}" == "path : ../dir/same_file_with_text" ] [ "${lines[3]}" == "--" ] } @test 'assert_files_not_equal() : replace suffix of displayed path' { local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" local -r file1="${TEST_FIXTURE_ROOT}/dir/file_with_text" local -r BATSLIB_FILE_PATH_REM='%same_file_with_text' local -r BATSLIB_FILE_PATH_ADD='..' run assert_files_not_equal "$file1" "$file2" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- files are the same --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/file_with_text" ] [ "${lines[2]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[3]}" == "--" ] } @test 'assert_files_not_equal() : replace infix of displayed path' { local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text" local -r file1="${TEST_FIXTURE_ROOT}/dir/file_with_text" local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_files_not_equal "$file1" "$file2" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- files are the same --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../file_with_text" ] [ "${lines[2]}" == "path : ${TEST_FIXTURE_ROOT}/../same_file_with_text" ] [ "${lines[3]}" == "--" ] } bats-file-0.4.0/test/59-assert-10-assert_file_owner.bats000066400000000000000000000052241447150276500227130ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/owner ${TEST_FIXTURE_ROOT}/dir/notowner # There is PATH addition to /usr/sbin which won't come by default on bash3 # on macOS chown_path=$(PATH="$PATH:/usr/sbin" command -v chown 2>/dev/null) bats_sudo "$chown_path" root ${TEST_FIXTURE_ROOT}/dir/owner bats_sudo "$chown_path" daemon ${TEST_FIXTURE_ROOT}/dir/notowner } teardown () { bats_sudo rm -f ${TEST_FIXTURE_ROOT}/dir/owner ${TEST_FIXTURE_ROOT}/dir/notowner } # Correctness @test 'assert_file_owner() : returns 0 if user root is the owner of the file' { local -r owner="root" local -r file="${TEST_FIXTURE_ROOT}/dir/owner" run assert_file_owner "$owner" "$file" [ "$status" -eq 0 ] echo ${#lines[@]} [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_owner() : returns 1 and displays path if user root is not the owner of the file' { local -r owner="root" local -r file="${TEST_FIXTURE_ROOT}/dir/notowner" run assert_file_owner "$owner" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user root is not the owner of the file --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_file_owner() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' local -r owner="root" local -r file="${TEST_FIXTURE_ROOT}/dir/notowner" run assert_file_owner "$owner" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user root is not the owner of the file --' ] [ "${lines[1]}" == "path : ../dir/notowner" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_owner() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/notowner' local -r BATSLIB_FILE_PATH_ADD='..' local -r owner="root" local -r file="${TEST_FIXTURE_ROOT}/dir/notowner" run assert_file_owner "$owner" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user root is not the owner of the file --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_file_owner() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/notowner' local -r BATSLIB_FILE_PATH_ADD='..' local -r owner="root" local -r file="${TEST_FIXTURE_ROOT}/dir/notowner" run assert_file_owner "$owner" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user root is not the owner of the file --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/59-assert-11-assert_not_file_owner.bats000066400000000000000000000054151447150276500235760ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/owner ${TEST_FIXTURE_ROOT}/dir/notowner # There is PATH addition to /usr/sbin which won't come by default on bash3 # on macOS chown_path=$(PATH="$PATH:/usr/sbin" command -v chown 2>/dev/null) bats_sudo "$chown_path" root ${TEST_FIXTURE_ROOT}/dir/owner bats_sudo "$chown_path" daemon ${TEST_FIXTURE_ROOT}/dir/notowner } teardown () { bats_sudo rm -f ${TEST_FIXTURE_ROOT}/dir/owner ${TEST_FIXTURE_ROOT}/dir/notowner } # Correctness @test 'assert_not_file_owner() : returns 0 if user is not the owner' { local -r owner="daemon" local -r file="${TEST_FIXTURE_ROOT}/dir/owner" run assert_not_file_owner "$owner" "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_not_file_owner() : returns 1 and displays path if user root is the owner of the file, but it was expected not to be' { local -r owner="root" local -r file="${TEST_FIXTURE_ROOT}/dir/owner" run assert_not_file_owner "$owner" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user root is the owner of the file, but it was expected not to be --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_not_file_owner() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' local -r owner="root" local -r file="${TEST_FIXTURE_ROOT}/dir/owner" run assert_not_file_owner "$owner" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user root is the owner of the file, but it was expected not to be --' ] [ "${lines[1]}" == "path : ../dir/owner" ] [ "${lines[2]}" == '--' ] } @test 'assert_not_file_owner() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/owner' local -r BATSLIB_FILE_PATH_ADD='..' local -r owner="root" local -r file="${TEST_FIXTURE_ROOT}/dir/owner" run assert_not_file_owner "$owner" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user root is the owner of the file, but it was expected not to be --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_not_file_owner() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/owner' local -r BATSLIB_FILE_PATH_ADD='..' local -r owner="root" local -r file="${TEST_FIXTURE_ROOT}/dir/owner" run assert_not_file_owner "$owner" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user root is the owner of the file, but it was expected not to be --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/60-assert-10-assert_file_permission.bats000066400000000000000000000046231447150276500237430ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/permission chmod 777 ${TEST_FIXTURE_ROOT}/dir/permission } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/permission } # Correctness @test 'assert_file_permission() : returns 0 if file has 777' { local -r permission="777" local -r file="${TEST_FIXTURE_ROOT}/dir/permission" run assert_file_permission "$permission" "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_permission() : returns 1 and displays path if file does not have permissions 777' { local -r permission="644" local -r file="${TEST_FIXTURE_ROOT}/dir/permission" run assert_file_permission "$permission" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file does not have permissions 644 --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_file_permission() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' local -r permission="644" local -r file="${TEST_FIXTURE_ROOT}/dir/permission" run assert_file_permission "$permission" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file does not have permissions 644 --' ] [ "${lines[1]}" == "path : ../dir/permission" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_permission() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/permission' local -r BATSLIB_FILE_PATH_ADD='..' local -r permission="644" local -r file="${TEST_FIXTURE_ROOT}/dir/permission" run assert_file_permission "$permission" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file does not have permissions 644 --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_file_permission() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/permission' local -r BATSLIB_FILE_PATH_ADD='..' local -r permission="644" local -r file="${TEST_FIXTURE_ROOT}/dir/permission" run assert_file_permission "$permission" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file does not have permissions 644 --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/60-assert-11-assert_file_no_permissions.bats000066400000000000000000000053031447150276500246170ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/permission ${TEST_FIXTURE_ROOT}/dir/nopermission chmod 777 ${TEST_FIXTURE_ROOT}/dir/permission chmod 644 ${TEST_FIXTURE_ROOT}/dir/nopermission } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/permission ${TEST_FIXTURE_ROOT}/dir/nopermission } # Correctness @test 'assert_not_file_permission() : returns 0 if file does not have permissions 777' { local -r permission="777" local -r file="${TEST_FIXTURE_ROOT}/dir/nopermission" run assert_not_file_permission "$permission" "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_not_file_permission() : returns 1 and displays path if file has permissions 777, but it was expected not to have' { local -r permission="777" local -r file="${TEST_FIXTURE_ROOT}/dir/permission" run assert_not_file_permission "$permission" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file has permissions 777, but it was expected not to have --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_not_file_permission() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' local -r permission="777" local -r file="${TEST_FIXTURE_ROOT}/dir/permission" run assert_not_file_permission "$permission" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file has permissions 777, but it was expected not to have --' ] [ "${lines[1]}" == "path : ../dir/permission" ] [ "${lines[2]}" == '--' ] } @test 'assert_not_file_permission() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/permission' local -r BATSLIB_FILE_PATH_ADD='..' local -r permission="777" local -r file="${TEST_FIXTURE_ROOT}/dir/permission" run assert_not_file_permission "$permission" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file has permissions 777, but it was expected not to have --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_not_file_permission() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/permission' local -r BATSLIB_FILE_PATH_ADD='..' local -r permission="777" local -r file="${TEST_FIXTURE_ROOT}/dir/permission" run assert_not_file_permission "$permission" "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file has permissions 777, but it was expected not to have --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/61-assert-10-size_zero.bats000066400000000000000000000040051447150276500211770ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { readonly ZERO_FILE=${TEST_FIXTURE_ROOT}/dir/zerobyte touch "$ZERO_FILE" readonly NOTZERO_FILE="${TEST_FIXTURE_ROOT}/dir/notzerobyte" echo "not empty" > "$NOTZERO_FILE" } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/zerobyte ${TEST_FIXTURE_ROOT}/dir/notzerobyte } # Correctness @test 'assert_size_zero() : returns 0 if file is 0 byte' { run assert_size_zero "$ZERO_FILE" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_size_zero() : returns 1 and displays path if file is greater than 0 byte' { run assert_size_zero "$NOTZERO_FILE" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is greater than 0 byte --' ] [ "${lines[1]}" == "path : $NOTZERO_FILE" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_size_zero() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_size_zero "$NOTZERO_FILE" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is greater than 0 byte --' ] [ "${lines[1]}" == "path : ../dir/notzerobyte" ] [ "${lines[2]}" == '--' ] } @test 'assert_size_zero() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/notzerobyte' local -r BATSLIB_FILE_PATH_ADD='..' run assert_size_zero "$NOTZERO_FILE" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is greater than 0 byte --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_size_zero() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/notzerobyte' local -r BATSLIB_FILE_PATH_ADD='..' run assert_size_zero "$NOTZERO_FILE" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is greater than 0 byte --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/61-assert-11-size_not_zero.bats000066400000000000000000000041221447150276500220600ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { readonly ZERO_FILE="${TEST_FIXTURE_ROOT}/dir/zerobyte" touch "$ZERO_FILE" readonly NOTZERO_FILE="${TEST_FIXTURE_ROOT}/dir/notzerobyte" echo "not empty" > "$NOTZERO_FILE" } teardown () { rm -f "$ZERO_FILE" "$NOTZERO_FILE" } # Correctness @test 'assert_size_not_zero() : returns 0 if file is greater than 0 byte' { run assert_size_not_zero "$NOTZERO_FILE" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_size_not_zero() : returns 1 and displays path if file is 0 byte, but it was expected not to be' { run assert_size_not_zero "$ZERO_FILE" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is 0 byte, but it was expected not to be --' ] [ "${lines[1]}" == "path : $ZERO_FILE" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_size_not_zero() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_size_not_zero "$ZERO_FILE" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is 0 byte, but it was expected not to be --' ] [ "${lines[1]}" == "path : ../dir/zerobyte" ] [ "${lines[2]}" == '--' ] } @test 'assert_size_not_zero() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/zerobyte' local -r BATSLIB_FILE_PATH_ADD='..' run assert_size_not_zero "$ZERO_FILE" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is 0 byte, but it was expected not to be --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_size_not_zero() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/zerobyte' local -r BATSLIB_FILE_PATH_ADD='..' run assert_size_not_zero "$ZERO_FILE" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file is 0 byte, but it was expected not to be --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/62-assert-10-assert_file_group_id_set.bats000066400000000000000000000043101447150276500242310ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/groupidset ${TEST_FIXTURE_ROOT}/dir/groupidnotset chmod g+s ${TEST_FIXTURE_ROOT}/dir/groupidset } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/groupidset ${TEST_FIXTURE_ROOT}/dir/groupidnotset } # Correctness @test 'assert_file_group_id_set() : returns 0 if set-group-ID is set' { local -r file="${TEST_FIXTURE_ROOT}/dir/groupidset" run assert_file_group_id_set "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_group_id_set() : returns 1 and displays path if set-group-ID is not set' { local -r file="${TEST_FIXTURE_ROOT}/dir/groupidnotset" run assert_file_group_id_set "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- set-group-ID is not set --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_file_group_id_set() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_group_id_set "${TEST_FIXTURE_ROOT}/dir/groupidnotset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- set-group-ID is not set --' ] [ "${lines[1]}" == "path : ../dir/groupidnotset" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_group_id_set() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/groupidnotset' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_group_id_set "${TEST_FIXTURE_ROOT}/dir/groupidnotset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- set-group-ID is not set --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_file_group_id_set() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/groupidnotset' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_group_id_set "${TEST_FIXTURE_ROOT}/dir/groupidnotset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- set-group-ID is not set --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/62-assert-11-file_not_group_id_set.bats000066400000000000000000000045161447150276500235410ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/groupidset ${TEST_FIXTURE_ROOT}/dir/groupidnotset chmod g+s ${TEST_FIXTURE_ROOT}/dir/groupidset } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/groupidset ${TEST_FIXTURE_ROOT}/dir/groupidnotset } # Correctness @test 'assert_file_not_group_id_set() : returns 0 if group id is not set' { local -r file="${TEST_FIXTURE_ROOT}/dir/groupidnotset" run assert_file_not_group_id_set "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_not_group_id_set() : returns 1 and displays path if group id is set, but it was expected not to be' { local -r file="${TEST_FIXTURE_ROOT}/dir/groupidset" run assert_file_not_group_id_set "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- group id is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_file_not_group_id_set() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_group_id_set "${TEST_FIXTURE_ROOT}/dir/groupidset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- group id is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : ../dir/groupidset" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_not_group_id_set() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/groupidset' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_group_id_set "${TEST_FIXTURE_ROOT}/dir/groupidset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- group id is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_file_not_group_id_set() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/groupidset' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_group_id_set "${TEST_FIXTURE_ROOT}/dir/groupidset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- group id is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/63-assert-10-assert_file_user_id_set.bats000066400000000000000000000042521447150276500240610ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/useridset ${TEST_FIXTURE_ROOT}/dir/useridnotset chmod u+s ${TEST_FIXTURE_ROOT}/dir/useridset } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/useridset ${TEST_FIXTURE_ROOT}/dir/useridnotset } # Correctness @test 'assert_file_user_id_set() : returns 0 if set-user-ID is set' { local -r file="${TEST_FIXTURE_ROOT}/dir/useridset" run assert_file_user_id_set "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_user_id_set() : returns 1 and displays path if set-user-ID is not set' { local -r file="${TEST_FIXTURE_ROOT}/dir/useridnotset" run assert_file_user_id_set "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- set-user-ID is not set --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_file_user_id_set() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_user_id_set "${TEST_FIXTURE_ROOT}/dir/useridnotset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- set-user-ID is not set --' ] [ "${lines[1]}" == "path : ../dir/useridnotset" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_user_id_set() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/useridnotset' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_user_id_set "${TEST_FIXTURE_ROOT}/dir/useridnotset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- set-user-ID is not set --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_file_user_id_set() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/useridnotset' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_user_id_set "${TEST_FIXTURE_ROOT}/dir/useridnotset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- set-user-ID is not set --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/63-assert-11-file_not_user_id_set.bats000066400000000000000000000044621447150276500233640ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/useridset ${TEST_FIXTURE_ROOT}/dir/useridnotset chmod u+s ${TEST_FIXTURE_ROOT}/dir/useridset } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/useridset ${TEST_FIXTURE_ROOT}/dir/useridnotset } # Correctness @test 'assert_file_not_user_id_set() : returns 0 if user id is not set' { local -r file="${TEST_FIXTURE_ROOT}/dir/useridnotset" run assert_file_not_user_id_set "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_not_user_id_set() : returns 1 and displays path if user id is set, but it was expected not to be' { local -r file="${TEST_FIXTURE_ROOT}/dir/useridset" run assert_file_not_user_id_set "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user id is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_file_not_user_id_set() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_user_id_set "${TEST_FIXTURE_ROOT}/dir/useridset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user id is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : ../dir/useridset" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_not_user_id_set() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/useridset' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_user_id_set "${TEST_FIXTURE_ROOT}/dir/useridset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user id is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_file_not_user_id_set() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/useridset' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_user_id_set "${TEST_FIXTURE_ROOT}/dir/useridset" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- user id is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/64-assert-10-assert_sticky_bit.bats000066400000000000000000000041431447150276500227210ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/stickybit ${TEST_FIXTURE_ROOT}/dir/notstickybit chmod +t ${TEST_FIXTURE_ROOT}/dir/stickybit } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/stickybit ${TEST_FIXTURE_ROOT}/dir/notstickybit } # Correctness @test 'assert_sticky_bit() : returns 0 if stickybit is set' { local -r file="${TEST_FIXTURE_ROOT}/dir/stickybit" run assert_sticky_bit "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_sticky_bit() : returns 1 and displays path if stickybit is not set' { local -r file="${TEST_FIXTURE_ROOT}/dir/notstickybit" run assert_sticky_bit "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- stickybit is not set --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_sticky_bit() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_sticky_bit "${TEST_FIXTURE_ROOT}/dir/notstickybit" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- stickybit is not set --' ] [ "${lines[1]}" == "path : ../dir/notstickybit" ] [ "${lines[2]}" == '--' ] } @test 'assert_sticky_bit() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/notstickybit' local -r BATSLIB_FILE_PATH_ADD='..' run assert_sticky_bit "${TEST_FIXTURE_ROOT}/dir/notstickybit" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- stickybit is not set --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_sticky_bit() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/notstickybit' local -r BATSLIB_FILE_PATH_ADD='..' run assert_sticky_bit "${TEST_FIXTURE_ROOT}/dir/notstickybit" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- stickybit is not set --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/64-assert-11-assert_no_sticky_bit.bats000066400000000000000000000043711447150276500234210ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'exist' setup () { touch ${TEST_FIXTURE_ROOT}/dir/stickybit ${TEST_FIXTURE_ROOT}/dir/notstickybit chmod +t ${TEST_FIXTURE_ROOT}/dir/stickybit } teardown () { rm -f ${TEST_FIXTURE_ROOT}/dir/stickybit ${TEST_FIXTURE_ROOT}/dir/notstickybit } # Correctness @test 'assert_no_sticky_bit() : returns 0 if stickybit is not set' { local -r file="${TEST_FIXTURE_ROOT}/dir/notstickybit" run assert_no_sticky_bit "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_no_sticky_bit() : returns 1 and displays path if stickybit is set, but it was expected not to be' { local -r file="${TEST_FIXTURE_ROOT}/dir/stickybit" run assert_no_sticky_bit "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- stickybit is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_no_sticky_bit() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_no_sticky_bit "${TEST_FIXTURE_ROOT}/dir/stickybit" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- stickybit is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : ../dir/stickybit" ] [ "${lines[2]}" == '--' ] } @test 'assert_no_sticky_bit() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%dir/stickybit' local -r BATSLIB_FILE_PATH_ADD='..' run assert_no_sticky_bit "${TEST_FIXTURE_ROOT}/dir/stickybit" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- stickybit is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_no_sticky_bit() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir/stickybit' local -r BATSLIB_FILE_PATH_ADD='..' run assert_no_sticky_bit "${TEST_FIXTURE_ROOT}/dir/stickybit" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- stickybit is set, but it was expected not to be --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/.." ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/65-assert-10-assert_symlink_to.bats000066400000000000000000000030351447150276500227450ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'symlink' setup () { touch "${TEST_FIXTURE_ROOT}/file" "${TEST_FIXTURE_ROOT}/notasymlink" ln -s "${TEST_FIXTURE_ROOT}/file" "${TEST_FIXTURE_ROOT}/symlink" TEMP_FOLDER="$(temp_make)" } teardown () { rm -f "${TEST_FIXTURE_ROOT}/file" "${TEST_FIXTURE_ROOT}/notasymlink" "${TEST_FIXTURE_ROOT}/symlink" temp_del "${TEMP_FOLDER}" } # Correctness @test 'assert_symlink_to() : returns 0 if exists and is a symbolic link to ' { local -r file="${TEST_FIXTURE_ROOT}/file" local -r link="${TEST_FIXTURE_ROOT}/symlink" run assert_symlink_to "${file}" "${link}" [ "${status}" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_symlink_to() : returns 1 and displays path if is not a symbolic link to ' { local -r file="${TEST_FIXTURE_ROOT}/dir/file.does_not_exists" local -r link="${TEST_FIXTURE_ROOT}/symlink" run assert_symlink_to "${file}" "${link}" [ "${status}" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- symbolic link does not have the correct target --' ] [ "${lines[1]}" == "path : ${link}" ] [ "${lines[2]}" == '--' ] } @test 'assert_symlink_to() : returns 0 if exists and is a symbolic link to ' { touch "${TEMP_FOLDER}/file" "${TEMP_FOLDER}/notasymlink" ln -s "${TEMP_FOLDER}/file" "${TEMP_FOLDER}/symlink" local -r file="${TEMP_FOLDER}/file" local -r link="${TEMP_FOLDER}/symlink" run assert_symlink_to "${file}" "${link}" [ "${status}" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } bats-file-0.4.0/test/65-assert-11-assert_not_symlink_to.bats000066400000000000000000000022461447150276500236310ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'symlink' setup () { touch ${TEST_FIXTURE_ROOT}/file ${TEST_FIXTURE_ROOT}/notasymlink ln -s ${TEST_FIXTURE_ROOT}/file ${TEST_FIXTURE_ROOT}/symlink } teardown () { rm -f ${TEST_FIXTURE_ROOT}/file ${TEST_FIXTURE_ROOT}/notasymlink ${TEST_FIXTURE_ROOT}/symlink } # Correctness @test 'assert_not_symlink_to() : returns 0 if exists and is a not symbolic link to ' { local -r file="${TEST_FIXTURE_ROOT}/file" local -r link="${TEST_FIXTURE_ROOT}/notasymlink" run assert_not_symlink_to $file $link [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_not_symlink_to() : returns 1 and displays path if is a symbolic link to ' { local -r file="${TEST_FIXTURE_ROOT}/file" local -r link="${TEST_FIXTURE_ROOT}/symlink" run assert_not_symlink_to $file $link [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 6 ] [ "${lines[0]}" == '-- file is a symbolic link --' ] [ "${lines[1]}" == "path : $link" ] [ "${lines[2]}" == '--' ] [ "${lines[3]}" == '-- symbolic link does have the correct target --' ] [ "${lines[4]}" == "path : $link" ] [ "${lines[5]}" == '--' ] } bats-file-0.4.0/test/66-assert-10-assert_file_size_equals.bats000066400000000000000000000030031447150276500240740ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'empty' # Correctness @test 'assert_file_size_equals() : returns 0 if correct' { local -r file="${TEST_FIXTURE_ROOT}/dir/empty-file" run assert_file_size_equals "$file" "0" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_size_equals() : returns 1 if is not correct' { local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" run assert_file_size_equals "$file" "5" [ "$status" -eq 1 ] } @test 'assert_file_size_equals() : returns 0 if is correct, non-zero case' { local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" run assert_file_size_equals "$file" "10" [ "$status" -eq 0 ] } # Transforming path @test 'assert_file_size_equals() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_size_equals "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "5" [ "$status" -eq 1 ] } @test 'assert_file_size_equals() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%non-empty-file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_size_equals "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "5" [ "$status" -eq 1 ] } @test 'assert_file_size_equals() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_size_equals "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "5" [ "$status" -eq 1 ] } bats-file-0.4.0/test/67-assert-10-assert_file_contains.bats000066400000000000000000000032651447150276500234010ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'empty' # Correctness @test 'assert_file_contains() : returns 0 and displays content if matches string' { local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" run assert_file_contains "$file" "Not empty" [ "$status" -eq 0 ] } @test 'assert_file_contains() : returns 1 and displays content if does not match string' { local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" run assert_file_contains "$file" "XXX" [ "$status" -eq 1 ] } # Transforming path @test 'assert_file_contains() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_contains "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "XXX" [ "$status" -eq 1 ] } @test 'assert_file_contains() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%non-empty-file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_contains "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "XXX" [ "$status" -eq 1 ] } @test 'assert_file_contains() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_contains "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "XXX" [ "$status" -eq 1 ] } @test 'assert_file_contains() : show missing regex in case of failure' { local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" run assert_file_contains "$file" "XXX" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- file does not contain regex --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == "regex : XXX" ] [ "${lines[3]}" == '--' ] } bats-file-0.4.0/test/67-assert-10-assert_file_not_contains.bats000066400000000000000000000042051447150276500242540ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'empty' # Correctness @test 'assert_file_not_contains() : returns 0 and displays content if does not match string' { local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" run assert_file_not_contains "$file" "XXX" [ "$status" -eq 0 ] } @test 'assert_file_not_contains() : returns 1 and displays content if does match string' { local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" run assert_file_not_contains "$file" "Not empty" [ "$status" -eq 1 ] } # Transforming path @test 'assert_file_not_contains() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_contains "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "Not empty" [ "$status" -eq 1 ] } @test 'assert_file_not_contains() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%non-empty-file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_contains "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "Not empty" [ "$status" -eq 1 ] } @test 'assert_file_not_contains() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_contains "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "Not empty" [ "$status" -eq 1 ] } @test 'assert_file_not_contains() : show missing regex in case of failure' { local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" run assert_file_not_contains "$file" "Not empty" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- file contains regex --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == "regex : Not empty" ] [ "${lines[3]}" == '--' ] } @test 'assert_file_not_contains() : returns 1 and displays path if does not exist' { local -r file="${TEST_FIXTURE_ROOT}/missing" run assert_file_not_contains "$file" "XXX" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- file does not exist --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == "regex : XXX" ] [ "${lines[3]}" == '--' ] } bats-file-0.4.0/test/68-assert-10-assert_file_empty.bats000066400000000000000000000041011447150276500227100ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'empty' # Correctness @test 'assert_file_empty() : returns 0 if empty' { local -r file="${TEST_FIXTURE_ROOT}/dir/empty-file" run assert_file_empty "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_empty() : returns 1 and displays content if is not empty' { local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" run assert_file_empty "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- file is not empty --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/non-empty-file" ] [ "${lines[2]}" == 'output : Not empty' ] [ "${lines[3]}" == '--' ] } # Transforming path @test 'assert_file_empty() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_empty "${TEST_FIXTURE_ROOT}/dir/non-empty-file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- file is not empty --' ] [ "${lines[1]}" == "path : ../dir/non-empty-file" ] [ "${lines[2]}" == 'output : Not empty' ] [ "${lines[3]}" == '--' ] } @test 'assert_file_empty() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%non-empty-file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_empty "${TEST_FIXTURE_ROOT}/dir/non-empty-file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- file is not empty --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == 'output : Not empty' ] [ "${lines[3]}" == '--' ] } @test 'assert_file_empty() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_empty "${TEST_FIXTURE_ROOT}/dir/non-empty-file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == '-- file is not empty --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../non-empty-file" ] [ "${lines[2]}" == 'output : Not empty' ] [ "${lines[3]}" == '--' ] } bats-file-0.4.0/test/68-assert-11-assert_file_not_empty.bats000066400000000000000000000040611447150276500235760ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'empty' # Correctness @test 'assert_file_not_empty() : returns 0 if is not empty' { local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" run assert_file_not_empty "$file" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } @test 'assert_file_not_empty() : returns 1 and displays path if emptys' { local -r file="${TEST_FIXTURE_ROOT}/dir/empty-file" run assert_file_not_empty "$file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file empty, but it was expected to contain something --' ] [ "${lines[1]}" == "path : $file" ] [ "${lines[2]}" == '--' ] } # Transforming path @test 'assert_file_not_empty() : replace prefix of displayed path' { local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_empty "${TEST_FIXTURE_ROOT}/dir/empty-file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file empty, but it was expected to contain something --' ] [ "${lines[1]}" == "path : ../dir/empty-file" ] [ "${lines[2]}" == '--' ] } @test 'assert_file_not_empty() : replace suffix of displayed path' { local -r BATSLIB_FILE_PATH_REM='%empty-file' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_empty "${TEST_FIXTURE_ROOT}/dir/empty-file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file empty, but it was expected to contain something --' ] echo [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ] [ "${lines[2]}" == '--' ] } @test 'assert_file_not_empty() : replace infix of displayed path' { local -r BATSLIB_FILE_PATH_REM='dir' local -r BATSLIB_FILE_PATH_ADD='..' run assert_file_not_empty "${TEST_FIXTURE_ROOT}/dir/empty-file" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- file empty, but it was expected to contain something --' ] [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../empty-file" ] [ "${lines[2]}" == '--' ] } bats-file-0.4.0/test/70-temp-10-temp_make.bats000077500000000000000000000052131447150276500206010ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'temp' # Correctness @test 'temp_make() : returns 0, creates a temporary directory and displays its path' { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make)" echo $TEST_TEMP_DIR local -r literal="${BATS_TMPDIR}/${BATS_TEST_FILENAME##*/}-" local -r pattern='[1-9][0-9]*-.{6}' [[ $TEST_TEMP_DIR =~ ^"${literal}"${pattern}$ ]] || false [ -e "$TEST_TEMP_DIR" ] } @test 'temp_make() : returns 1 and displays an error message if the directory can not be created' { local -r BATS_TMPDIR='/does/not/exist' run temp_make [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- ERROR: temp_make --' ] if [[ "$OSTYPE" == darwin* ]]; then REGEX="mktemp: mkdtemp failed on $BATS_TMPDIR/.*: No such file or directory" else REGEX="mktemp: (failed to create directory via template|(\(null\): )?No such file or directory)" fi [[ ${lines[1]} =~ $REGEX ]] || false [ "${lines[2]}" == '--' ] } @test "temp_make() : works when called from \`setup'" { bats "${TEST_FIXTURE_ROOT}/temp_make-setup.bats" } @test "temp_make() : works when called from \`setup_file'" { bats "${TEST_FIXTURE_ROOT}/temp_make-setup_file.bats" } @test "temp_make() : works when called from \`@test'" { bats "${TEST_FIXTURE_ROOT}/temp_make-test.bats" } @test "temp_make() : works when called from \`teardown'" { bats "${TEST_FIXTURE_ROOT}/temp_make-teardown.bats" } @test "temp_make() : works when called from \`teardown_file'" { bats "${TEST_FIXTURE_ROOT}/temp_make-teardown_file.bats" } @test "temp_make() : does not work when called from \`main'" { run bats "${TEST_FIXTURE_ROOT}/temp_make-main.bats" [ "$status" -eq 1 ] [[ "${output}" == *'-- ERROR: temp_make --'* ]] || false [[ "${output}" == *"Must be called from \`setup', \`@test' or \`teardown'"* ]] || false } # Options test_p_prefix() { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make "$@" 'test-')" local -r literal="${BATS_TMPDIR}/test-${BATS_TEST_FILENAME##*/}-" local -r pattern='[1-9][0-9]*-.{6}' [[ $TEST_TEMP_DIR =~ ^"${literal}"${pattern}$ ]] || false [ -e "$TEST_TEMP_DIR" ] } @test 'temp_make() -p : returns 0 and creates a temporary directory with prefix' { test_p_prefix -p } @test 'temp_make() --prefix : returns 0 and creates a temporary directory with prefix' { test_p_prefix --prefix } @test "temp_make() --prefix : works if starts with a \`-'" { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make --prefix -)" [ -e "$TEST_TEMP_DIR" ] } bats-file-0.4.0/test/70-temp-11-temp_del.bats000077500000000000000000000124401447150276500204310ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' fixtures 'temp' # Correctness @test 'temp_del() : returns 0 and deletes ' { TEST_TEMP_DIR="$(temp_make)" run temp_del "$TEST_TEMP_DIR" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] [ ! -e "$TEST_TEMP_DIR" ] } @test 'temp_del() : works even if wrote-protected file/directory exists within' { TEST_TEMP_DIR="$(temp_make)" touch $TEST_TEMP_DIR/nowritefile chmod -w $TEST_TEMP_DIR/nowritefile mkdir -p $TEST_TEMP_DIR/nowritefolder chmod -w $TEST_TEMP_DIR/nowritefolder run temp_del "$TEST_TEMP_DIR" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] [ ! -e "$TEST_TEMP_DIR" ] } @test 'temp_del() : returns 1 and displays an error message if can not be deleted' { local -r path="${TEST_FIXTURE_ROOT}/does/not/exist" run temp_del "$path" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- ERROR: temp_del --' ] # Travis CI's Ubuntu 12.04, quotes the path with a backtick and an # apostrophe, instead of just apostrophes. [[ ${lines[1]} == 'rm:'*"${path}"*': No such file or directory' ]] || false [ "${lines[2]}" == '--' ] } @test "temp_del() : works if starts with a \`-'" { TEST_TEMP_DIR="$(temp_make --prefix -)" run temp_del "$TEST_TEMP_DIR" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] [ ! -e "$TEST_TEMP_DIR" ] } # Environment variables @test "temp_del() : returns 0 and does not delete if \`BATSLIB_TEMP_PRESERVE' is set to \`1'" { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make)" local -r BATSLIB_TEMP_PRESERVE=1 run temp_del "$TEST_TEMP_DIR" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] [ -e "$TEST_TEMP_DIR" ] } @test "temp_del() : returns 0 and does not delete if \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' is set to \`1' and the test have failed" { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make)" export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-fail.bats" [ "$status" -eq 1 ] [ -e "$TEST_TEMP_DIR" ] } @test "temp_del() : returns 0 and deletes if \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' is set to \`1' and the test have passed" { TEST_TEMP_DIR="$(temp_make)" export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-pass.bats" [ "$status" -eq 0 ] [ ! -e "$TEST_TEMP_DIR" ] } @test "temp_del() : returns 0 and deletes if \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' is set to \`1' and the test have been skipped" { TEST_TEMP_DIR="$(temp_make)" export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-skip.bats" [ "$status" -eq 0 ] [ ! -e "$TEST_TEMP_DIR" ] } @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' works when called from \`teardown'" { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make)" export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-teardown.bats" [ "$status" -eq 1 ] [ -e "$TEST_TEMP_DIR" ] } @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' works when called from \`teardown_file'" { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make)" export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-teardown_file.bats" [ "$status" -eq 1 ] [ -e "$TEST_TEMP_DIR" ] } @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' does not work when called from \`main'" { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make)" export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-main.bats" [ "$status" -eq 1 ] [[ "$output" == *'-- ERROR: temp_del --'* ]] || false [[ "$output" == *"Must be called from \`teardown' or \`teardown_file' when using \`BATSLIB_TEMP_PRESERVE_ON_FAILURE'"* ]] || false } @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' does not work when called from \`setup'" { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make)" export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-setup.bats" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 10 ] [[ ${lines[6]} == *'-- ERROR: temp_del --' ]] || false [[ ${lines[7]} == *"Must be called from \`teardown' or \`teardown_file' when using \`BATSLIB_TEMP_PRESERVE_ON_FAILURE'" ]] || false [[ ${lines[8]} == *'--' ]] || false } @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' does not work when called from \`setup_file'" { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make)" export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-setup_file.bats" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 10 ] [[ ${lines[6]} == *'-- ERROR: temp_del --' ]] || false [[ ${lines[7]} == *"Must be called from \`teardown' or \`teardown_file' when using \`BATSLIB_TEMP_PRESERVE_ON_FAILURE'" ]] || false [[ ${lines[8]} == *'--' ]] || false } @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' does not work when called from \`@test'" { teardown() { rm -r -- "$TEST_TEMP_DIR"; } TEST_TEMP_DIR="$(temp_make)" export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-test.bats" [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 10 ] [[ ${lines[6]} == *'-- ERROR: temp_del --' ]] || false [[ ${lines[7]} == *"Must be called from \`teardown' or \`teardown_file' when using \`BATSLIB_TEMP_PRESERVE_ON_FAILURE'" ]] || false [[ ${lines[8]} == *'--' ]] || false } bats-file-0.4.0/test/fixtures/000077500000000000000000000000001447150276500162245ustar00rootroot00000000000000bats-file-0.4.0/test/fixtures/empty/000077500000000000000000000000001447150276500173625ustar00rootroot00000000000000bats-file-0.4.0/test/fixtures/empty/dir/000077500000000000000000000000001447150276500201405ustar00rootroot00000000000000bats-file-0.4.0/test/fixtures/empty/dir/empty-file000066400000000000000000000000001447150276500221240ustar00rootroot00000000000000bats-file-0.4.0/test/fixtures/empty/dir/non-empty-file000066400000000000000000000000121447150276500227170ustar00rootroot00000000000000Not empty bats-file-0.4.0/test/fixtures/exist/000077500000000000000000000000001447150276500173605ustar00rootroot00000000000000bats-file-0.4.0/test/fixtures/exist/dir/000077500000000000000000000000001447150276500201365ustar00rootroot00000000000000bats-file-0.4.0/test/fixtures/exist/dir/.gitignore000066400000000000000000000001071447150276500221240ustar00rootroot00000000000000# Ignore everything in this directory * # Except this file !.gitignore bats-file-0.4.0/test/fixtures/symlink/000077500000000000000000000000001447150276500177125ustar00rootroot00000000000000bats-file-0.4.0/test/fixtures/symlink/.gitignore000066400000000000000000000001071447150276500217000ustar00rootroot00000000000000# Ignore everything in this directory * # Except this file !.gitignore bats-file-0.4.0/test/fixtures/temp/000077500000000000000000000000001447150276500171715ustar00rootroot00000000000000bats-file-0.4.0/test/fixtures/temp/temp_del-fail.bats000066400000000000000000000004371447150276500225520ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' @test "temp_del() : returns 0 and does not delete if \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' is set to \`1' and the test have failed" { false } teardown() { local -ir BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 temp_del "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/temp_del-main.bats000066400000000000000000000001751447150276500225620ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 temp_del "$TEST_TEMP_DIR" @test empty { : } bats-file-0.4.0/test/fixtures/temp/temp_del-pass.bats000066400000000000000000000004261447150276500226030ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' @test "temp_del() : returns 0 and deletes if \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' is set to \`1' and the test have passed" { true } teardown() { local -ir BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 temp_del "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/temp_del-setup.bats000066400000000000000000000003631447150276500227750ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' setup() { local -ir BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 temp_del "$TEST_TEMP_DIR" } @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' does not work when called from \`setup'" { true } bats-file-0.4.0/test/fixtures/temp/temp_del-setup_file.bats000066400000000000000000000003751447150276500237770ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' setup_file() { local -ir BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 temp_del "$TEST_TEMP_DIR" } @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' does not work when called from \`setup_file'" { true } bats-file-0.4.0/test/fixtures/temp/temp_del-skip.bats000066400000000000000000000004341447150276500226020ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' @test "temp_del() : returns 0 and deletes if \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' is set to \`1' and the test have been skipped" { skip } teardown() { local -ir BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 temp_del "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/temp_del-teardown.bats000066400000000000000000000003621447150276500234570ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' works when called from \`teardown'" { false } teardown() { local -ir BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 temp_del "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/temp_del-teardown_file.bats000066400000000000000000000003741447150276500244610ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' works when called from \`teardown_file'" { false } teardown_file() { local -ir BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 temp_del "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/temp_del-test.bats000066400000000000000000000003371447150276500226150ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' does not work when called from \`@test'" { local -ir BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 temp_del "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/temp_make-main.bats000066400000000000000000000001371447150276500227310ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' TEST_TEMP_DIR="$(temp_make)" @test "empty" { : } bats-file-0.4.0/test/fixtures/temp/temp_make-setup.bats000066400000000000000000000003071447150276500231440ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' setup() { TEST_TEMP_DIR="$(temp_make)" } @test "temp_make() : works when called from \`setup'" { true } teardown() { rm -r -- "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/temp_make-setup_file.bats000066400000000000000000000003261447150276500241440ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' setup_file() { TEST_TEMP_DIR="$(temp_make)" } @test "temp_make() : works when called from \`setup_file'" { true } teardown_file() { rm -r -- "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/temp_make-teardown.bats000066400000000000000000000002751447150276500236330ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' @test "temp_make() : works when called from \`teardown'" { true } teardown() { TEST_TEMP_DIR="$(temp_make)" rm -r -- "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/temp_make-teardown_file.bats000066400000000000000000000003071447150276500246260ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' @test "temp_make() : works when called from \`teardown_file'" { true } teardown_file() { TEST_TEMP_DIR="$(temp_make)" rm -r -- "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/temp_make-test.bats000066400000000000000000000002631447150276500227640ustar00rootroot00000000000000#!/usr/bin/env bats load 'test_helper' @test "temp_make() : works when called from \`@test'" { TEST_TEMP_DIR="$(temp_make)" } teardown() { rm -r -- "$TEST_TEMP_DIR" } bats-file-0.4.0/test/fixtures/temp/test_helper.bash000066400000000000000000000003331447150276500223450ustar00rootroot00000000000000export TEST_MAIN_DIR="${BATS_TEST_DIRNAME}/../../.." export TEST_DEPS_DIR="${TEST_DEPS_DIR-${TEST_MAIN_DIR}/..}" # Load dependencies. bats_load_library "bats-support" # Load library. load "${TEST_MAIN_DIR}/load.bash" bats-file-0.4.0/test/test_helper.bash000066400000000000000000000014601447150276500175310ustar00rootroot00000000000000# Set variables for easily accessing sub-directories of `./fixtures'. # # Globals: # BATS_TEST_DIRNAME # TEST_FIXTURE_ROOT # TEST_RELATIVE_FIXTURE_ROOT # Arguments: # $1 - name of sub-directory # Returns: # none fixtures() { TEST_FIXTURE_ROOT="${BATS_TEST_DIRNAME}/fixtures/$1" TEST_RELATIVE_FIXTURE_ROOT=$(bats_trim_filename "${TEST_FIXTURE_ROOT}" TEST_RELATIVE_FIXTURE_ROOT) } bats_sudo() { local sudo_path=$(command -v sudo 2>/dev/null) if [[ "$(whoami)" != 'root' ]] && [ -x "$sudo_path" ]; then "$sudo_path" "$@" else "$@" fi } export TEST_MAIN_DIR="${BATS_TEST_DIRNAME}/.." export TEST_DEPS_DIR="${TEST_DEPS_DIR-${TEST_MAIN_DIR}/..}" # validate that bats-file is safe to use under -u set -u # Load dependencies. bats_load_library 'bats-support' # Load library. load '../load'