Commit 70fae43c by Patrick Steinhardt

tests: merge::analysis: use variants to deduplicate test suites

Since commit 394951ad (tests: allow for simple data-driven
tests, 2019-06-07), we have the ability to run a given test suite
with multiple variants. Use this new feature to deduplicate the
test suites for merge::{trees,workdir}::analysis into a single
test suite.
parent 0c1029be
...@@ -13,8 +13,7 @@ You probably want to make changes to both files. ...@@ -13,8 +13,7 @@ You probably want to make changes to both files.
#include "refs.h" #include "refs.h"
#include "posix.h" #include "posix.h"
static git_repository *repo; #define TEST_REPO_PATH "merge-resolve"
static git_index *repo_index;
#define UPTODATE_BRANCH "master" #define UPTODATE_BRANCH "master"
#define PREVIOUS_BRANCH "previous" #define PREVIOUS_BRANCH "previous"
...@@ -25,18 +24,27 @@ static git_index *repo_index; ...@@ -25,18 +24,27 @@ static git_index *repo_index;
#define NOFASTFORWARD_BRANCH "branch" #define NOFASTFORWARD_BRANCH "branch"
#define NOFASTFORWARD_ID "7cb63eed597130ba4abb87b3e544b85021905520" #define NOFASTFORWARD_ID "7cb63eed597130ba4abb87b3e544b85021905520"
static git_repository *sandbox;
static git_repository *repo;
void test_merge_analysis__initialize_with_bare_repository(void)
{
sandbox = cl_git_sandbox_init(TEST_REPO_PATH);
cl_git_pass(git_repository_open_ext(&repo, git_repository_path(sandbox),
GIT_REPOSITORY_OPEN_BARE, NULL));
}
/* Fixture setup and teardown */ void test_merge_analysis__initialize_with_nonbare_repository(void)
void testimpl_merge_analysis__initialize(git_repository *t_repo, git_index *t_repo_index)
{ {
repo = t_repo; sandbox = cl_git_sandbox_init(TEST_REPO_PATH);
repo_index = t_repo_index; cl_git_pass(git_repository_open_ext(&repo, git_repository_workdir(sandbox),
0, NULL));
} }
void testimpl_merge_analysis__cleanup(void) void test_merge_analysis__cleanup(void)
{ {
repo_index = NULL; git_repository_free(repo);
repo = NULL; cl_git_sandbox_cleanup();
} }
static void analysis_from_branch( static void analysis_from_branch(
...@@ -72,7 +80,7 @@ static void analysis_from_branch( ...@@ -72,7 +80,7 @@ static void analysis_from_branch(
git_reference_free(their_ref); git_reference_free(their_ref);
} }
void testimpl_merge_analysis__fastforward(void) void test_merge_analysis__fastforward(void)
{ {
git_merge_analysis_t merge_analysis; git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref; git_merge_preference_t merge_pref;
...@@ -81,7 +89,7 @@ void testimpl_merge_analysis__fastforward(void) ...@@ -81,7 +89,7 @@ void testimpl_merge_analysis__fastforward(void)
cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL|GIT_MERGE_ANALYSIS_FASTFORWARD, merge_analysis); cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL|GIT_MERGE_ANALYSIS_FASTFORWARD, merge_analysis);
} }
void testimpl_merge_analysis__no_fastforward(void) void test_merge_analysis__no_fastforward(void)
{ {
git_merge_analysis_t merge_analysis; git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref; git_merge_preference_t merge_pref;
...@@ -90,7 +98,7 @@ void testimpl_merge_analysis__no_fastforward(void) ...@@ -90,7 +98,7 @@ void testimpl_merge_analysis__no_fastforward(void)
cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis); cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
} }
void testimpl_merge_analysis__uptodate(void) void test_merge_analysis__uptodate(void)
{ {
git_merge_analysis_t merge_analysis; git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref; git_merge_preference_t merge_pref;
...@@ -99,7 +107,7 @@ void testimpl_merge_analysis__uptodate(void) ...@@ -99,7 +107,7 @@ void testimpl_merge_analysis__uptodate(void)
cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis); cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
} }
void testimpl_merge_analysis__uptodate_merging_prev_commit(void) void test_merge_analysis__uptodate_merging_prev_commit(void)
{ {
git_merge_analysis_t merge_analysis; git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref; git_merge_preference_t merge_pref;
...@@ -108,14 +116,14 @@ void testimpl_merge_analysis__uptodate_merging_prev_commit(void) ...@@ -108,14 +116,14 @@ void testimpl_merge_analysis__uptodate_merging_prev_commit(void)
cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis); cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
} }
void testimpl_merge_analysis__unborn(void) void test_merge_analysis__unborn(void)
{ {
git_merge_analysis_t merge_analysis; git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref; git_merge_preference_t merge_pref;
git_buf master = GIT_BUF_INIT; git_buf master = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&master, git_repository_path(repo), "refs/heads/master")); cl_git_pass(git_buf_joinpath(&master, git_repository_path(repo), "refs/heads/master"));
p_unlink(git_buf_cstr(&master)); cl_must_pass(p_unlink(git_buf_cstr(&master)));
analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH); analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD|GIT_MERGE_ANALYSIS_UNBORN, merge_analysis); cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD|GIT_MERGE_ANALYSIS_UNBORN, merge_analysis);
...@@ -123,7 +131,7 @@ void testimpl_merge_analysis__unborn(void) ...@@ -123,7 +131,7 @@ void testimpl_merge_analysis__unborn(void)
git_buf_dispose(&master); git_buf_dispose(&master);
} }
void testimpl_merge_analysis__fastforward_with_config_noff(void) void test_merge_analysis__fastforward_with_config_noff(void)
{ {
git_config *config; git_config *config;
git_merge_analysis_t merge_analysis; git_merge_analysis_t merge_analysis;
...@@ -140,7 +148,7 @@ void testimpl_merge_analysis__fastforward_with_config_noff(void) ...@@ -140,7 +148,7 @@ void testimpl_merge_analysis__fastforward_with_config_noff(void)
git_config_free(config); git_config_free(config);
} }
void testimpl_merge_analysis__no_fastforward_with_config_ffonly(void) void test_merge_analysis__no_fastforward_with_config_ffonly(void)
{ {
git_config *config; git_config *config;
git_merge_analysis_t merge_analysis; git_merge_analysis_t merge_analysis;
...@@ -157,7 +165,7 @@ void testimpl_merge_analysis__no_fastforward_with_config_ffonly(void) ...@@ -157,7 +165,7 @@ void testimpl_merge_analysis__no_fastforward_with_config_ffonly(void)
git_config_free(config); git_config_free(config);
} }
void testimpl_merge_analysis__between_uptodate_refs(void) void test_merge_analysis__between_uptodate_refs(void)
{ {
git_merge_analysis_t merge_analysis; git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref; git_merge_preference_t merge_pref;
...@@ -166,7 +174,7 @@ void testimpl_merge_analysis__between_uptodate_refs(void) ...@@ -166,7 +174,7 @@ void testimpl_merge_analysis__between_uptodate_refs(void)
cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis); cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
} }
void testimpl_merge_analysis__between_noff_refs(void) void test_merge_analysis__between_noff_refs(void)
{ {
git_merge_analysis_t merge_analysis; git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref; git_merge_preference_t merge_pref;
......
#ifndef INCLUDE_cl_merge_analysis_h__
#define INCLUDE_cl_merge_analysis_h__
void testimpl_merge_analysis__initialize(git_repository *t_repo, git_index *t_repo_index);
void testimpl_merge_analysis__cleanup(void);
void testimpl_merge_analysis__fastforward(void);
void testimpl_merge_analysis__no_fastforward(void);
void testimpl_merge_analysis__uptodate(void);
void testimpl_merge_analysis__uptodate_merging_prev_commit(void);
void testimpl_merge_analysis__unborn(void);
void testimpl_merge_analysis__fastforward_with_config_noff(void);
void testimpl_merge_analysis__no_fastforward_with_config_ffonly(void);
void testimpl_merge_analysis__between_uptodate_refs(void);
void testimpl_merge_analysis__between_noff_refs(void);
#endif
/*
NOTE: this is essentially duplicated from tests/merge/workdir/analysis.c
You probably want to make changes to both files.
*/
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "../analysis.h"
static git_repository *repo;
static git_repository *bare_repo;
static git_index *repo_index;
#define TEST_REPO_PATH "merge-resolve"
#define TEST_INDEX_PATH TEST_REPO_PATH "/index"
/* Fixture setup and teardown */
void test_merge_trees_analysis__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
cl_git_pass(git_repository_open_ext(&bare_repo, TEST_REPO_PATH "/.git", GIT_REPOSITORY_OPEN_BARE, NULL));
git_repository_index(&repo_index, bare_repo);
testimpl_merge_analysis__initialize(bare_repo, repo_index);
}
void test_merge_trees_analysis__cleanup(void)
{
testimpl_merge_analysis__cleanup();
git_index_free(repo_index);
repo_index = NULL;
git_repository_free(bare_repo);
bare_repo = NULL;
cl_git_sandbox_cleanup();
repo = NULL;
}
void test_merge_trees_analysis__fastforward(void)
{
testimpl_merge_analysis__fastforward();
}
void test_merge_trees_analysis__no_fastforward(void)
{
testimpl_merge_analysis__no_fastforward();
}
void test_merge_trees_analysis__uptodate(void)
{
testimpl_merge_analysis__uptodate();
}
void test_merge_trees_analysis__uptodate_merging_prev_commit(void)
{
testimpl_merge_analysis__uptodate_merging_prev_commit();
}
void test_merge_trees_analysis__unborn(void)
{
testimpl_merge_analysis__unborn();
}
void test_merge_trees_analysis__fastforward_with_config_noff(void)
{
testimpl_merge_analysis__fastforward_with_config_noff();
}
void test_merge_trees_analysis__no_fastforward_with_config_ffonly(void)
{
testimpl_merge_analysis__no_fastforward_with_config_ffonly();
}
void test_merge_trees_analysis__between_uptodate_refs(void)
{
testimpl_merge_analysis__between_uptodate_refs();
}
void test_merge_trees_analysis__between_noff_refs(void)
{
testimpl_merge_analysis__between_noff_refs();
}
/*
NOTE: this is essentially duplicated with tests/merge/trees/analysis.c
You probably want to make changes to both files.
*/
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "../analysis.h"
static git_repository *repo;
static git_index *repo_index;
#define TEST_REPO_PATH "merge-resolve"
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
/* Fixture setup and teardown */
void test_merge_workdir_analysis__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
git_repository_index(&repo_index, repo);
testimpl_merge_analysis__initialize(repo, repo_index);
}
void test_merge_workdir_analysis__cleanup(void)
{
testimpl_merge_analysis__cleanup();
git_index_free(repo_index);
repo_index = NULL;
cl_git_sandbox_cleanup();
repo = NULL;
}
void test_merge_workdir_analysis__fastforward(void)
{
testimpl_merge_analysis__fastforward();
}
void test_merge_workdir_analysis__no_fastforward(void)
{
testimpl_merge_analysis__no_fastforward();
}
void test_merge_workdir_analysis__uptodate(void)
{
testimpl_merge_analysis__uptodate();
}
void test_merge_workdir_analysis__uptodate_merging_prev_commit(void)
{
testimpl_merge_analysis__uptodate_merging_prev_commit();
}
void test_merge_workdir_analysis__unborn(void)
{
testimpl_merge_analysis__unborn();
}
void test_merge_workdir_analysis__fastforward_with_config_noff(void)
{
testimpl_merge_analysis__fastforward_with_config_noff();
}
void test_merge_workdir_analysis__no_fastforward_with_config_ffonly(void)
{
testimpl_merge_analysis__no_fastforward_with_config_ffonly();
}
void test_merge_workdir_analysis__between_uptodate_refs(void)
{
testimpl_merge_analysis__between_uptodate_refs();
}
void test_merge_workdir_analysis__between_noff_refs(void)
{
testimpl_merge_analysis__between_noff_refs();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment