Skip to main content

Crate gix_testtools

Crate gix_testtools 

Source
Expand description

Utilities for testing gitoxide crates, many of which might be useful for testing programs that use git in general.

§Environment Variables

§GIX_TEST_FIXTURE_HASH

Set this variable to control which hash function is used when creating or loading test fixtures. Valid values are the names of hash functions supported by gix_hash::Kind (e.g., sha1, sha256). If not set, the default hash function via gix_hash::Kind::default() is used.

§Feature Flags

  • worktree-exclusions (enabled by default) — Use the current repository’s complete ignore rules to decide if generated fixture archives should be written. Without this feature, only the .gitignore next to the archive is consulted using a fallback matcher that supports literal patterns and *, but not the full .gitignore syntax.
  • repo-snapshot (enabled by default) — Capture repository snapshots using gix-* plumbing crates instead of invoking Git. Without this feature, repository snapshots use the Git executable selected by gix-path.
  • sha1 — Enable support for SHA-1 fixture repositories and object IDs.
  • sha256 — Enable support for SHA-256 fixture repositories and object IDs.
  • xz — Use instead of plain tar files, compress these to produce tar.xz files instead. This is useful if archives are uploaded into git-lfs, which doesn’t have built-in compression and metering counts towards uncompressed bytes transferred.

Re-exports§

pub use bstr;
pub use is_ci;
pub use tempfile;

Modules§

repository
Capture complete, stable repository state for integration-test assertions. Stable snapshots of the Git and filesystem state of a test repository.
signature
Shared setup for tests involving Git-compatible signatures. Test support for Git signing without using the user’s identities or configuration.

Structs§

AutoRevertToPreviousCWD
A utility to set the current working dir to the given value, on drop.
Env
A utility to set and unset environment variables, while restoring or removing them on drop.
GitDaemon
A wrapper for a running git-daemon which is stopped automatically on drop.

Enums§

Creation
Define how scripted_fixture_writable_with_args(), scripted_fixture_writable_with_args_with_git_version(), and rust_fixture_writable() produce the writable fixture.
FixtureState
Indicates the state of a fixture when a closure is called.

Statics§

GIT_VERSION
The major, minor and patch level of the git version on the system.

Functions§

apply_git_config_by_environment
Apply command-scoped Git config to cmd, and return it.
bash_program
Get the path attempted as a bash interpreter, for fixture scripts having no #! we can use.
build_example_for_test
Build example from package and copy the executable to this test process’ temporary target directory.
copy_recursively_into_existing_dir
A utility to copy the entire contents of src_dir into dst_dir.
fixture_bytes
Load the fixture from <crate-root>/tests/fixtures/<path> and return its data, or panic.
fixture_path
Return the path to the <crate-root>/tests/fixtures/<path> directory.
git
Run git in current_dir with shell-like whitespace-separated arguments, returning stdout as UTF-8.
invoke_bash
Run script with bash_program() in cwd.
normalize_debug_snapshot
Normalize debug-formatted value so one snapshot can be reused for SHA-1 and SHA-256 fixtures.
normalize_hashes
Normalize 40- and 64-character hexadecimal object IDs in input.
object_hash
Like object_hash_from_env(), but returns the default hash if GIX_TEST_FIXTURE_HASH is not set.
object_hash_from_env
Returns the hash function that is used when creating or loading test fixtures.
run_git
Run git in working_dir with all provided args.
rust_fixture_read_only
Execute a Rust closure in a directory, returning a read-only fixture path.
rust_fixture_writable
Execute a Rust closure in a directory, returning a writable temporary directory.
scripted_fixture_read_only
Run the executable at script_name, like make_repo.sh or my_setup.py to produce a read-only directory to which the path is returned.
scripted_fixture_read_only_needs_archive
Like scripted_fixture_read_only(), but uses a matching existing archive even if GIX_TEST_IGNORE_ARCHIVES is set.
scripted_fixture_read_only_with_args
Like scripted_fixture_read_only(), but passes args to script_name.
scripted_fixture_read_only_with_args_single_archive
Like scripted_fixture_read_only()], but passes args to script_name.
scripted_fixture_read_only_with_args_single_archive_with_git_version
Like scripted_fixture_read_only_with_args_with_git_version(), but uses a single archive for all argument sets.
scripted_fixture_read_only_with_args_single_archive_with_post
Like scripted_fixture_read_only_with_args_single_archive, but runs a Rust closure after the script completes.
scripted_fixture_read_only_with_args_single_archive_with_post_with_git_version
Like scripted_fixture_read_only_with_args_single_archive_with_git_version(), but runs a Rust closure after the script completes.
scripted_fixture_read_only_with_args_with_git_version
Like scripted_fixture_read_only_with_git_version(), but passes args to script_name.
scripted_fixture_read_only_with_args_with_post
Like scripted_fixture_read_only_with_args, but runs a Rust closure after the script completes.
scripted_fixture_read_only_with_args_with_post_with_git_version
Like scripted_fixture_read_only_with_args_with_git_version(), but runs a Rust closure after the script completes.
scripted_fixture_read_only_with_git_version
Produce a read-only scripted fixture when the installed Git version is compatible, or extract it from a matching archive otherwise.
scripted_fixture_read_only_with_post
Like scripted_fixture_read_only, but runs a Rust closure after the script completes.
scripted_fixture_read_only_with_post_with_git_version
Like scripted_fixture_read_only_with_git_version(), but runs a Rust closure after the script completes.
scripted_fixture_writable
Run the executable at script_name, like make_repo.sh to produce a writable directory to which the tempdir is returned. It will be removed automatically, courtesy of tempfile::TempDir.
scripted_fixture_writable_with_args
Like scripted_fixture_writable(), but passes args to script_name while providing control over the way files are created with mode.
scripted_fixture_writable_with_args_single_archive
Like scripted_fixture_writable(), but passes args to script_name while providing control over the way files are created with mode.
scripted_fixture_writable_with_args_single_archive_with_git_version
Like scripted_fixture_writable_with_args_with_git_version(), but uses a single archive for all argument sets.
scripted_fixture_writable_with_args_single_archive_with_post
Like scripted_fixture_writable_with_args_single_archive, but runs a Rust closure after the script completes.
scripted_fixture_writable_with_args_single_archive_with_post_with_git_version
Like scripted_fixture_writable_with_args_single_archive_with_git_version(), but runs a Rust closure after the script completes.
scripted_fixture_writable_with_args_with_git_version
Like scripted_fixture_writable_with_git_version(), but passes args to script_name while providing control over the way files are created with mode.
scripted_fixture_writable_with_args_with_post
Like scripted_fixture_writable_with_args, but runs a Rust closure after the script completes.
scripted_fixture_writable_with_args_with_post_with_git_version
Like scripted_fixture_writable_with_args_with_git_version(), but runs a Rust closure after the script completes.
scripted_fixture_writable_with_git_version
Produce a writable scripted fixture when the installed Git version is compatible, or extract it from a matching archive otherwise.
scripted_fixture_writable_with_post
Like scripted_fixture_writable, but runs a Rust closure after the script completes.
scripted_fixture_writable_with_post_with_git_version
Like scripted_fixture_writable_with_git_version(), but runs a Rust closure after the script completes.
set_current_dir
Set the current working dir to new_cwd and return a type that returns to the previous working dir on drop.
should_skip_as_git_version_is_smaller_than
Returns true if the given major, minor and patch is smaller than the actual git version on the system to facilitate skipping a test on the caller. Will never return true on CI which is expected to have a recent enough git version.
size_ok
Check data structure size, comparing strictly on 64-bit targets.
spawn_git_daemon
Spawn a git daemon to host all repositories at or below working_dir.
umaskUnix
Get the umask in a way that is safe, but may be too slow for use outside of tests.

Type Aliases§

PostResult
A result type for post-processing closures in *_with_post fixture functions.
Result
A result type to allow using the try operator ? in unit tests.