Commit graph

17 commits

Author SHA1 Message Date
Martin von Zweigbergk
802e21bf25 operations: allow overriding timestamps for tests
It would be nice to be able to use snapshot testing and not have to
parse the output of `jj op log`. This patch lets us do that by
providing a new environment variable and config for overriding the
timestamps. Unlike `operation.hostname` and `operation.username`,
these are only meant for tests.
2022-11-24 16:00:20 -10:00
Martin von Zweigbergk
8d7a9e729b tests: set test hostname and username for operation log
This makes the tests more hermetic, even though I don't think the
default values (taken from `whoami`) can break any tests (then we
would have already seen them break). Now we just need to make the
operation log's timestamps predictable and then we can start using
operation IDs in snapshot tests.
2022-11-24 16:00:20 -10:00
Waleed Khan
9607d954e4 tests: assert result of TestEnvironment::jj_cmd_cli_error
In the test case `test_branch_mutually_exclusive_actions`, we weren't actually testing anything useful, because the interface has since changed to use subcommands instead of options. The test has been deleted in this commit, and `TestEnvironment::jj_cmd_cli_error` has been changed to return a `#[must_use]` `String` representing stderr. I also added `#[must_use]` to `TestEnvironment::jj_cmd_failure` while I was here.
2022-11-20 05:08:35 -08:00
Martin von Zweigbergk
3c7c4e9f5c tests: move testutils module into separate crate
The `testutils` module should ideally not be part of the library
dependencies. Since they're used by the integration tests (and the CLI
tests), we need to move them to a separate crate to achieve that.
2022-11-08 07:29:35 -08:00
Martin von Zweigbergk
650853401d tests: replace test env path in output by $TEST_ENV
Mercurial's test runner does something like this.

I considered replacing `\` by `/` everywhere, but we use `\` in
graph-log output quite frequently, so it doesn't seem worth it.
2022-11-03 19:27:17 -07:00
Martin von Zweigbergk
efce1e54e6 tests: extract setup of libgit2 config to lib crate
We have some problems with non-hermetic tests in the lib crate, so
we'll want to reuse the setup code there.
2022-10-23 11:08:22 -07:00
Yuya Nishihara
872081c867 tests: use testutils::new_temp_dir() thoroughly 2022-09-07 23:49:46 +09:00
Jonathan Tan
a9606a8269 tests: stop libgit2 from accessing config files
libgit2 by default will respect config files present on a user's
machine---in particular, when creating a new repo, it will read
`init.defaultBranch` to determine what the name of the default branch
should be. This makes the tests non-hermetic, so disable that feature.

On my machine, `init.defaultBranch` is set in system config. Without
this patch, `test_git_colocated` and
`test_git_colocated_rebase_on_import` fail, but with this patch, they
pass.
2022-08-30 14:45:02 -07:00
Martin von Zweigbergk
1faffbb5aa tests: check exit code on failure, and fix a bug in argument parsing
We didn't have any testing of exit codes on failure, other than
checking that they were not 0. This patch changes that so we always
check. Since we have the special exit code 2 (set by `clap`) for
incorrect command line, I've replaced some testing of error messages
by testing of just the exit code.

As part of this, I also fixed `jj branch --allow-backwards` to
actually require `-r` (it didn't before because having a default value
means the argument is considered always provided).
2022-05-10 04:02:24 -07:00
Martin von Zweigbergk
f8724ee5a9 tests: add tests for jj describe 2022-04-10 09:13:51 -07:00
Martin von Zweigbergk
486f49435b cli: if $JJ_CONFIG points to a directory, read all files in it
It's annoying especially for tests to not be able to append to a
config file without knowing the contents (as you have to do with
TOML). Let's read all files in a directory if `$JJ_CONFIG` points to a
directory. Mercurial does that for its `$HGRCPATH` variable.
2022-04-10 09:13:51 -07:00
Martin von Zweigbergk
bc3c2db828 cli: print errors to stderr 2022-04-09 16:13:01 -07:00
Martin von Zweigbergk
f21a069a47 tests: add tests for jj restore -i 2022-04-02 14:22:58 -07:00
Martin von Zweigbergk
9b44822dc1 tests: add helper for failing tests as well 2022-04-02 14:22:58 -07:00
Martin von Zweigbergk
6344faa3fe tests: allow setting env var for all commands in TestEnvironment
Sometimes it's useful to have an environment variable set for all
commands in a test. This patch lets you do that by adding environment
variables to the `TestEnvironment` itself. These will then be set on
all subsequent commands.
2022-04-02 14:22:58 -07:00
Martin von Zweigbergk
257b85a1b5 test: add helper for writing config file to TestEnvironment 2022-04-02 14:22:58 -07:00
Martin von Zweigbergk
710d51c45b tests: move testutils from src/ to tests/ 2022-04-02 14:22:58 -07:00