summaryrefslogtreecommitdiff
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* oid: `is_zero` instead of `iszero`Edward Thomson2019-06-161-10/+10
| | | | | | The only function that is named `issomething` (without underscore) was `git_oid_iszero`. Rename it to `git_oid_is_zero` for consistency with the rest of the library.
* Merge pull request #5110 from pks-t/pks/wildmatchEdward Thomson2019-06-154-28/+305
|\ | | | | Replace fnmatch with wildmatch
| * attr_file: convert to use `wildmatch`Patrick Steinhardt2019-06-151-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream git has converted to use `wildmatch` instead of `fnmatch`. Convert our gitattributes logic to use `wildmatch` as the last user of `fnmatch`. Please, don't expect I know what I'm doing here: the fnmatch parser is one of the most fun things to play around with as it has a sh*tload of weird cases. In all honesty, I'm simply relying on our tests that are by now rather comprehensive in that area. The conversion actually fixes compatibility with how git.git parser "**" patterns when the given path does not contain any directory separators. Previously, a pattern "**.foo" erroneously wouldn't match a file "x.foo", while git.git would match. Remove the new-unused LEADINGDIR/NOLEADINGDIR flags for `git_attr_fnmatch`.
| * config_file: use `wildmatch` to evaluate conditionalsPatrick Steinhardt2019-06-151-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | We currently use `p_fnmatch` to compute whether a given "gitdir:" or "gitdir/i:" conditional matches the current configuration file path. As git.git has moved to use `wildmatch` instead of `p_fnmatch` throughout its complete codebase, we evaluate conditionals inconsistently with git.git in some special cases. Convert `p_fnmatch` to use `wildmatch`. The `FNM_LEADINGDIR` flag cannot be translated to `wildmatch`, but in fact git.git doesn't use it here either. And in fact, dropping it while we go increases compatibility with git.git.
| * config_file: do not include trailing '/' for "gitdir" conditionalsPatrick Steinhardt2019-06-151-26/+28
| | | | | | | | | | | | | | | | | | | | | | When evaluating "gitdir:" and "gitdir/i:" conditionals, we currently compare the given pattern with the value of `git_repository_path`. Thing is though that `git_repository_path` returns the gitdir path with trailing '/', while we actually need to match against the gitdir without it. Fix this issue by stripping the trailing '/' previous to matching. Add various tests to ensure we get this right.
| * global: convert trivial `fnmatch` users to use `wildcard`Patrick Steinhardt2019-06-151-3/+3
| | | | | | | | | | | | | | | | | | | | Upstream git.git has converted its codebase to use wildcard in favor of fnmatch in commit 70a8fc999d (stop using fnmatch (either native or compat), 2014-02-15). To keep our own regex-matching in line with what git does, convert all trivial instances of `fnmatch` usage to use `wildcard`, instead. Trivial usage is defined to be use of `fnmatch` with either no flags or flags that have a 1:1 equivalent in wildmatch (PATHNAME, IGNORECASE).
| * posix: remove implicit include of "fnmatch.h"Patrick Steinhardt2019-06-151-0/+2
| | | | | | | | | | | | | | | | We're about to phase out our bundled fnmatch implementation as git.git has moved to wildmatch long ago in 2014. To make it easier to spot which files are stilll using fnmatch, remove the implicit "fnmatch.h" include in "posix.h" and instead include it explicitly.
| * wildmatch: import wildmatch from git.gitPatrick Steinhardt2019-06-151-0/+248
| | | | | | | | | | | | | | | | | | | | | | In commit 70a8fc999d (stop using fnmatch (either native or compat), 2014-02-15), upstream git has switched over all code from their internal fnmatch copy to its new wildmatch code. We haven't followed suit, and thus have developed some incompatibilities in how we match regular expressions. Import git's wildmatch from v2.22.0 and add a test suite based on their t3070-wildmatch.sh tests.
* | posix: remove `p_fallocate` abstractionPatrick Steinhardt2019-06-141-41/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By now, we have repeatedly failed to provide a nice cross-platform implementation of `p_fallocate`. Recent tries to do that escalated quite fast to a set of different CMake checks, implementations, fallbacks, etc., which started to look real awkward to maintain. In fact, `p_fallocate` had only been introduced in commit 4e3949b73 (tests: test that largefiles can be read through the tree API, 2019-01-30) to support a test with large files, but given the maintenance costs it just seems not to be worht it. As we have removed the sole user of `p_fallocate` in the previous commit, let's drop it altogether.
* | tests: object: refactor largefile test to not use `p_fallocate`Patrick Steinhardt2019-06-141-25/+15
|/ | | | | | | | | | | | | | The `p_fallocate` platform is currently in use in our tests, only, but it proved to be quite burdensome to get it implemented in a cross-platform way. The only "real" user is the test object::tree::read::largefile, where it's used to allocate a large file in the filesystem only to commit it to the repo and read its object back again. We can simplify this quite a bit by just using an in-memory buffer of 4GB. Sure, this cannot be used on platforms with low resources. But creating 4GB files is not any better, and we already skip the test if the environment variable "GITTEST_INVASIVE_FS_SIZE" is not set. So we're arguably not worse off than before.
* Merge pull request #5109 from pks-t/pks/test-mergeanalysis-variantEdward Thomson2019-06-144-202/+27
|\ | | | | tests: merge::analysis: use test variants to avoid duplicated test suites
| * tests: merge::analysis: use variants to deduplicate test suitesPatrick Steinhardt2019-06-134-202/+27
| | | | | | | | | | | | | | | | Since commit 394951ad4 (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.
* | apply: add an options struct initializerethomson/opts_initEdward Thomson2019-06-141-0/+5
| |
* | Rename opt init functions to `options_init`Edward Thomson2019-06-145-21/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | In libgit2 nomenclature, when we need to verb a direct object, we name a function `git_directobject_verb`. Thus, if we need to init an options structure named `git_foo_options`, then the name of the function that does that should be `git_foo_options_init`. The previous names of `git_foo_init_options` is close - it _sounds_ as if it's initializing the options of a `foo`, but in fact `git_foo_options` is its own noun that should be respected. Deprecate the old names; they'll now call directly to the new ones.
* | Merge pull request #5097 from pks-t/pks/ignore-escapesEdward Thomson2019-06-134-1336/+157
|\ \ | | | | | | gitignore with escapes
| * | attr_file: account for escaped escapes when searching trailing spacePatrick Steinhardt2019-06-131-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When determining the trailing space length, we need to honor whether spaces are escaped or not. Currently, we do not check whether the escape itself is escaped, though, which might generate an off-by-one in that case as we will simply treat the space as escaped. Fix this by checking whether the backslashes preceding the space are themselves escaped.
| * | attr_file: fix unescaping of escapes required for fnmatchPatrick Steinhardt2019-06-131-0/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When parsing attribute patterns, we will eventually unescape the parsed pattern. This is required because we require custom escapes for whitespace characters, as normally they are used to terminate the current pattern. Thing is, we don't only unescape those whitespace characters, but in fact all escaped sequences. So for example if the pattern was "\*", we unescape that to "*". As this is directly passed to fnmatch(3) later, fnmatch would treat it as a simple glob matching all files where it should instead only match a file with name "*". Fix the issue by unescaping spaces, only. Add a bunch of tests to exercise escape parsing.
| * | path: only treat paths starting with '\' as absolute on Win32Patrick Steinhardt2019-06-131-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Windows-based systems treat paths starting with '\' as absolute, either referring to the current drive's root (e.g. "\foo" might refer to "C:\foo") or to a network path (e.g. "\\host\foo"). On the other hand, (most?) systems that are not based on Win32 accept backslashes as valid characters that may be part of the filename, and thus we cannot treat them to identify absolute paths. Change the logic to only paths starting with '\' as absolute on the Win32 platform. Add tests to avoid regressions and document behaviour.
| * | tests: unify ignore tests into their own dirPatrick Steinhardt2019-06-072-68/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We had several occasions where tests for the gitignore had been added to status::ignore instead of the easier-to-handle attr::ignore test suite. This most likely resulted from the fact that the attr::ignore test suite is not easy to discover inside of the attr folder. Furthermore, ignore being part of the attributes code is an implementation detail, only, and thus shouldn't be stressed as much. Improve this by moving both attr::ignore and status::ignore tests into a new ignore test suite.
| * | tests: remove accidentally checked in backup filePatrick Steinhardt2019-06-071-1268/+0
| | | | | | | | | | | | | | | | | | | | | The "ignore.c.bak" file has accidentally been checked in via commit 191649010 (ignore: test that leading whitespace is significant, 2019-05-19) and should obviously not be part of our test suites. Delete it.
* | | Merge pull request #5108 from libgit2/ethomson/urlparse_empty_portEdward Thomson2019-06-131-0/+24
|\ \ \ | |_|/ |/| | Handle URLs with a colon after host but no port
| * | net: handle urls with a colon after host but no portEdward Thomson2019-06-111-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Core git copes with URLs that have a colon after the port, but no actual numeric value. eg `http://example.com:/foo.git` or `http://example.com:`. That's horrible, but RFC 3986 says: > URI producers and normalizers should omit the port component and its > ":" delimiter if port is empty or if its value would be the same as > that of the scheme's default. Which indicates that they may and therefore we must accept it. Test that we can handle URLs with a colon but no following port number.
* | | Merge pull request #5022 from rcoup/merge-analysis-bare-repo-5017Patrick Steinhardt2019-06-134-112/+301
|\ \ \ | | | | | | | | Merge analysis support for bare repos
| * | | Fix memleaks in analysis tests.Robert Coup2019-06-101-5/+9
| | | | | | | | | | | | | | | | Wrap some missed setup api calls in asserts.
| * | | Review fixes:Robert Coup2019-06-103-118/+129
| | | | | | | | | | | | | | | | | | | | | | | | - whitespace -> tabs - comment style - improve repo naming in merge/trees/analysis tests.
| * | | Refactor testing:Robert Coup2019-06-10478-806/+224
| | | | | | | | | | | | | | | | | | | | - move duplication between merge/trees/ and merge/workdir/ into merge/analysis{.c,.h} - remove merge-resolve.git resource, open the existing merge-resolve as a bare repo instead.
| * | | merge: add doc header to analysis testsRobert Coup2019-06-102-0/+6
| | | |
| * | | merge: tests for bare repo merge analysisRobert Coup2019-06-10475-0/+750
| | |/ | |/| | | | | | | dupe of workdir/analysis.c against a bare repo.
* | | Merge pull request #5104 from rcoup/patch-1Patrick Steinhardt2019-06-131-0/+26
|\ \ \ | |_|/ |/| | Add memleak check docs
| * | Add memleak check docsRobert Coup2019-06-121-0/+26
| | | | | | | | | | | | Document how to run it locally on macOS & Linux
* | | Merge pull request #5098 from pks-t/pks/clar-data-drivenEdward Thomson2019-06-112-82/+86
|\ \ \ | | | | | | | | Data-driven tests
| * | | tests: object: consolidate cache testsPatrick Steinhardt2019-06-071-68/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The object::cache test module has two tests that do nearly the same thing: given a cache limit, load a certain set of objects and verify if those objects have been cached or not. Convert those tests to the new data-driven initializers to demonstrate how these are to be used. Furthermore, add some additional test data. This conversion is mainly done to show this new facility.
| * | | tests: allow for simple data-driven testsPatrick Steinhardt2019-06-071-14/+29
| | |/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now, we're not able to use data-driven tests at all. E.g. given a set of tests which we'd like to repeat with different test data, one has to hand-write any outer loop that iterates over the test data and then call each of the test functions. Next to being bothersome, this also has the downside that error reporting is quite lacking, as one never knows which test data actually produced failures. So let's implement the ability to re-run complete test modules with changing test data. To retain backwards compatibility and enable trivial addition of new runs with changed test data, we simply extend clar's generate.py. Instead of scanning for a single `_initialize` function, each test module may now implement multiple `_initialize_foo` functions. The generated test harness will then run all test functions for each of the provided initializer functions, making it possible to provide different test data inside of each of the initializer functions. Example: ``` void test_git_example__initialize_with_nonbare_repo(void) { g_repo = cl_git_sandbox_init("testrepo"); } void test_git_example__initialize_with_bare_repo(void) { g_repo = cl_git_sandbox_init("testrepo.git"); } void test_git_example__cleanup(void) { cl_git_sandbox_cleanup(); } void test_git_example__test1(void) { test1(); } void test_git_example__test2(void) { test2(); } ``` Executing this test module will cause the following output: ``` $ ./libgit2_clar -sgit::example git::example (with nonbare repo).. git::example (with bare repo).. ```
* | | ci: enable all proxy testsEdward Thomson2019-06-101-1/+1
| | |
* | | winhttp: support default credentials for proxiesEdward Thomson2019-06-101-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We did not properly support default credentials for proxies, only for destination servers. Refactor the credential handling to support sending either username/password _or_ default credentials to either the proxy or the destination server. This actually shares the authentication logic between proxy servers and destination servers. Due to copy/pasta drift over time, they had diverged. Now they share a common logic which is: first, use credentials specified in the URL (if there were any), treating empty username and password (ie, "http://:@foo.com/") as default credentials, for compatibility with git. Next, call the credential callbacks. Finally, fallback to WinHTTP compatibility layers using built-in authentication like we always have. Allowing default credentials for proxies requires moving the security level downgrade into the credential setting routines themselves. We will update our security level to "high" by default which means that we will never send default credentials without prompting. (A lower setting, like the WinHTTP default of "medium" would allow WinHTTP to handle credentials for us, despite what a user may have requested with their structures.) Now we start with "high" and downgrade to "low" only after a user has explicitly requested default credentials.
* | | network: don't add arbitrary url rulesEdward Thomson2019-06-101-6/+0
| | | | | | | | | | | | | | | There's no reason a git repository couldn't be at the root of a server, and URLs should have an implicit path of '/' when one is not specified.
* | | net: rename gitno_connection_data to git_net_urlEdward Thomson2019-06-102-169/+206
| |/ |/| | | | | | | | | | | | | | | | | "Connection data" is an imprecise and largely incorrect name; these structures are actually parsed URLs. Provide a parser that takes a URL string and produces a URL structure (if it is valid). Separate the HTTP redirect handling logic from URL parsing, keeping a `gitno_connection_data_handle_redirect` whose only job is redirect handling logic and does not parse URLs itself.
* | tests: checkout: fix symlink.git being created outside of sandboxPatrick Steinhardt2019-06-071-1/+5
|/ | | | | | | | | The function `populate_symlink_workdir` creates a new "symlink.git" repository with a relative path "../symlink.git". As the current working directory is the sandbox, the new repository will be created just outside of the sandbox. Fix this by using `clar_sandbox_path`.
* Merge pull request #5095 from pks-t/pks/ignore-escaped-trailing-spaceEdward Thomson2019-06-061-0/+46
|\ | | | | ignore: handle escaped trailing whitespace
| * ignore: handle escaped trailing whitespacePatrick Steinhardt2019-06-061-0/+46
| | | | | | | | | | | | | | | | | | | | The gitignore's pattern format specifies that "Trailing spaces are ignored unless they are quoted with backslash ("\")". We do not honor this currently and will treat a pattern "foo\ " as if it was "foo\" only and a pattern "foo\ \ " as "foo\ \". Fix our code to handle those special cases and add tests to avoid regressions.
* | Merge pull request #5074 from libgit2/ethomson/ignore_leading_slashEdward Thomson2019-06-061-0/+24
|\ \ | |/ |/| Ignore: only treat one leading slash as a root identifier
| * ignore: test multiple leading slashesEdward Thomson2019-05-191-0/+24
| |
* | online tests: use gitlab for auth failuresethomson/auth_failureEdward Thomson2019-06-051-1/+1
| | | | | | | | | | | | | | | | GitHub recently changed their behavior from returning 401s for private or nonexistent repositories on a clone to returning 404s. For our tests that require an auth failure (and 401), move to GitLab to request a missing repository. This lets us continue to test our auth failure case, at least until they decide to mimic that decision.
* | attr: ensure regular attr files can have whitespaceethomson/ignore_spacesEdward Thomson2019-05-243-7/+33
| | | | | | | | | | | | Unlike ignore files, gitattribute files can have flexible whitespace at the beginning of the line. Ensure that by adding new ignore rules that we have not impeded correct parsing of attribute files.
* | ignore: test that comments begin at position 0Edward Thomson2019-05-241-0/+4
| | | | | | | | | | | | Comments must have a '#' at the beginning of the line. For compatibility with git, '#' after a whitespace is a literal part of the filename.
* | ignore: test that leading whitespace is significantEdward Thomson2019-05-242-0/+1294
| | | | | | | | | | | | Ensure that leading whitespace is treated as being part of the filename, eg ` foo` in an ignore file indicates that a file literally named ` foo` is ignored.
* | cache: fix cache eviction using deallocated keyPatrick Steinhardt2019-05-241-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When evicting cache entries, we first retrieve the object that is to be evicted, delete the object and then finally delete the key from the cache. In case where the cache eviction caused us to free the cached object, though, its key will point to invalid memory now when trying to remove it from the cache map. On my system, this causes us to not properly remove the key from the map, as its memory has been overwritten already and thus the key lookup it will fail and we cannot delete it. Fix this by only decrementing the refcount of the evictee after we have removed it from our cache map. Add a test that caused a segfault previous to that change.
* | config: validate quoted section valueEdward Thomson2019-05-221-0/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | When we reach a whitespace after a section name, we assume that what will follow will be a quoted subsection name. Pass the current position of the line being parsed to the subsection parser, so that it can validate that subsequent characters are additional whitespace or a single quote. Previously we would begin parsing after the section name, looking for the first quotation mark. This allows invalid characters to embed themselves between the end of the section name and the first quotation mark, eg `[section foo "subsection"]`, which is illegal.
* | Merge pull request #5060 from pks-t/pks/refspec-nested-globsEdward Thomson2019-05-222-11/+25
|\ \ | | | | | | Loosen restriction on wildcard "*" refspecs
| * | refspec: fix transforming nested starsPatrick Steinhardt2019-04-261-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When we transform a refspec with a component containing a glob, then we simply copy over the component until the next separator from the matching ref. E.g. if we have a ref "refs/heads/foo/bar" and a refspec "refs/heads/*/bar:refs/remotes/origin/*/bar", we: 1. Copy over everything until hitting the glob from the <dst> part: "refs/remotes/origin/". 2. Strip the common prefix of ref and <src> part until the glob, which is "refs/heads/". This leaves us with a ref of "foo/bar". 3. Copy from the ref until the next "/" separator, resulting in "refs/remotes/origin/foo". 4. Copy over the remaining part of the <dst> spec, which is "bar": "refs/remotes/origin/foo/bar". This worked just fine in a world where globs in refspecs were restricted such that a globbing component may only contain a single "*", only. But this restriction has been lifted, so that a glob component may be nested between other characters, causing the above algorithm to fail. Most notably the third step, where we copy until hitting the next "/" separator, might result in a wrong transformation. Given e.g. a ref "refs/gbranchg/head" and a refspec "refs/g*g/head:refs/remotes/origin/*", we'd also be copying the "g" between "branch" and "/" and end up with the wrong transformed ref "refs/remotes/origin/branchg". Instead of copying until the next component separator, we should copy until we hit the pattern after the "*". So in the above example, we'd copy until hitting the string "g/head".