Commit Graph

35 Commits

Author SHA1 Message Date
Joel Brobecker
a6adcae92b TestCase.run_unit_test_script: Reuse self.bare_repo_dir
TN: U530-006
Change-Id: I37e7cc3107a02e7963e3712680513686fc9b7bd7
2021-07-07 10:42:02 -07:00
Joel Brobecker
23efd593fb testsuite: Replace the "TEST_DIR" global by a TestCase.work_dir property
This is another preparation patch towards the transition to pytest where
testsuite support code is accessed through fixtures, rather than imports.
Having the equivalent of this information available as a property rather
than a global means we have access to this information though the "testcase"
object, something that works both with the current testsuite framework
and with the future pytest-based testsuite framework.

Note that the changes in the testcases themselves have been semi-automated.
I started with...

    $ cd testsuite/tests
    $ perl -pi -e 's/TEST_DIR/testcase.work_dir/g' */run_test.py

And then fixed up by hand the 30 testcases or so which had failures
in them. For the most part, it was about removing the import of
TEST_CASE, which had been replaced by an import of testsuite.work_dir.

TN: U530-006
Change-Id: I154dd58832dc10909623b869c488aa39edaf4c2d
2021-07-04 19:15:13 -07:00
Joel Brobecker
6310e92598 testsuite/lib/support.py: Remove import of "cd"
This import is no longer used by any testcase, and can be removed.
This ensures we don't re-introduce calls to this function in the future.

This is part of the transition of the testsuite to pytest, where
testcase should not be changing the global environment (such as
the current working directory).

TN: U530-006
Change-Id: I13b0f4882295ad5980c92c0ee726d48614448284
2021-07-04 19:14:22 -07:00
Joel Brobecker
05da61edb8 TestCase._run: run command in non-bare repo directory by default
This is another preparatory step towards being able to remove
the remaining calls to "cd" in our various testcases (something
that we cannot do once we transition to pytest, as it changes
the global environment).

Since the vast majority of commands being run by our testcases
are git commands to be run inside the non-bare repository,
this commit adjusts the TestCase._run method such that, if
a specific cwd is not specified, then run the command from
the directory of the non-bare repository.

TN: U530-006
Change-Id: I00d0685e02da24d83f652b035d37479eff310b1f
2021-07-04 19:12:42 -07:00
Joel Brobecker
cf8e3f7beb Introduce new TestCase.repo_dir property
The purpose of this change is to help avoid the same code being
duplicated in the testcases themselves.

No testcase is changed to use this, yet, but some followup commits
will.

Found while working on the transition to pytest, where we'll need
to avoid changing the global environment, which means we'll need
to be more explicit about directories (avoid changing the working
directory, and/or avoid assuming what the current working directory
is).

TN: U530-006
Change-Id: Ieb90bd3c1ae09a8261ac88322c87a2ab6f8ec35f
2021-07-04 19:09:35 -07:00
Joel Brobecker
c2f0cfb1da Make TestCase.run a method rather than a (callable) attribute
The purpose of this change is to allow us to change the semantics
when calling testcase.run, by implementing these slight semantic
changes in that new method.

The ulterior goal of this change is to change the directory we run
commands from when the "cwd" parameter is None, changing it from
the current working directory, to the the directory where the test
repository is used. From there, we'll then be able to remove most
of the calls to "cd", something we have to do as part of the transition
of this testsuite to pytest.

TN: U530-006
Change-Id: I8ea69363aac28e1cbc4886dd387a191fd0f4bd03
2021-07-04 19:08:41 -07:00
Joel Brobecker
df860a0a40 Introduce new TestCase.bare_repo_dir property and use it in testcases
The goal of this commit is to factorize the code in a few of
the testcases that computes the path to the testcase's bare
repository. That way, the reference to TEST_DIR, a global variable
that we're planning on eliminating in favor of a TestCase attribute,
gets factorized in the TestCase class, outside of the testcases.

Done while working on the testsuite transition to pytest (itself also
part of the transition to Python 3.x.

TN: U530-006
Change-Id: Ib47b02a8f9eccc54ad13332786e560203fb7b80e
2021-07-04 19:06:56 -07:00
Joel Brobecker
39caeb6fa1 Delete TestCase.enable_unit_test
This method should no longer be used, as it has unwanted side-effects.
Now that the testsuite is free of it, this commit removes it.

TN: U627-007
Change-Id: I0e405fb25563816fd3615d39fbbfd3560ea76bcb
2021-06-30 07:25:43 -07:00
Joel Brobecker
149dc10050 TestCase: Add support for unit testing via script as separate process
This commit adds a new method to the TestCase class used by
the testsuite whose goal is to facilitate the calling of a script
which can then perform unit testing as a separate process from
the testcase's process.

This is preparation work for the transition out of gnatpython
(Python 2.x only) and towards pytest, where all the testing is done
within the same process. When that happens, changing globals such as
the environment should not be done, as the changes would cause
side-effects with other testcases that are run concurrently.

The "logger_error" is then re-implemented using this new method.
This allows us to greatly simplify this testcase as we don't have
to work so hard at creating a scenario resulting in a call to
the "syslog" function. As it happens, the scenario that we used
for this testcase involves some code which we want to get rid of
(now OBE), and the few other locations where "syslog" is called
do not lend themselves to traditional testing (those are current
covered via unit testing too).

TN: U627-004 (remove support for $HOME/.no_cvs_check)
TN: U627-007 (avoid changing testsuite environment in testcase)
TN: U530-006 (transition to Python 3.x)
Change-Id: I8f47dc4bc877387d52edddbcde10dd14a49b9b6b
2021-06-30 07:22:46 -07:00
Joel Brobecker
e50b4a23bc Introduce a TestCase.run "method" (for transition to pytest)
This commit introduces a new run attribute in our testsuite's
TestCase class as a way to allow testcases to call this method
instead of instantiating the Run class. All testcases are then
modified to use this method, by running the following perl
command:

    $ cd testsuite/tests
    $ perl -pi -e 's/\bRun\(/testcase.run(/g' **/run_test.py

The testcases are then modified to remove the unused import using
the following perl command:

    $ perl -pi -e 's/\s+Run,//g' **/run_test.py

The goal is to help the transition to pytest, where the testcases
will be using the "run" method to call external commands such as
Git. The difference is that the pytest version of this method
will do more than being a simple wrapper (e.g. it will take care
of the default working directory).

TN: U530-006
Change-Id: I1823ef4331d8d16da6cf5f4a4efdbb667c68848d
2021-06-27 10:07:36 -07:00
Joel Brobecker
8de30044a4 .pre-commit-config.yaml: Update to black version 21.5b1
This commit updates the pre-commit hook to black version 21.5b1.
The hooks where then re-run on all files to update their formatting
to this new version of black.

Change-Id: Ib0866745ef8432cf93380a4d83fa23a479eb4a49
2021-06-15 05:52:32 -07:00
Joel Brobecker
a075b1653e reformat all the code using black
Change-Id: Idbc70777233ab2d40ab59765abb9cbbeeb88ec63
2021-04-18 14:59:01 +04:00
Joel Brobecker
1de3eb14c7 Add support for new config option hooks.commit-extra-check
This option allows projects to ask the git-hooks to perform custom
checks of any kind to validate every new commit being pushed.

This commit also contains a change in hooks/updates/emails.py which
enhances the email-sending debug tracing mechanism used by the testsuite,
adding support for a tracing mode where the traces are just one line
per email. Technically, this change is independent from the rest,
but it is merged with this commit nonetheless because these changes
would show up as uncovered by the testsuite without the testcases
we're adding here. That way, we maintain the principle that we always
have 100% testing coverage for any commit.

Change-Id: I0e446a95d05f5578f977af3eaa547144187eb86b
TN: T209-005
2020-07-19 19:38:58 -07:00
Joel Brobecker
05636d6c06 Remove gnatpython.fileutils wildcard import in testsuite/lib/support.py
Just import the one symbol that's actually used by the various
testcases in its place. This allows us to pass all current
style checks at AdaCore for Python files.

Change-Id: I458060771e18684e097e98131f292e09690a2e6d
2020-06-15 11:32:45 -07:00
Joel Brobecker
847eca781b [testsuite] do not ignore whitespaces when computing diffs
When a test wants to verify the output of a given command, it normally
does this as follow:

    self.assertRunOutputEqual(p, expected_out)

What this does is verify that the command's output matches, and if it
does not, then it not only reports and error, but also provides a diff
at the end, so as to facilitate the analysis.

However, while writing a test where that was unexpected failing
an output comparison, the diff in the error message was empty.
After investigation, it turned out that the function used to compute
that diff has a parameter ignore_white_chars set to True, which is
not what we want, here, and explains the discrepancy.

This commit fixes that by explicitly setting that parameter to False.
In the situation described above, this allowed the difference to
be shown in the diff section.

Change-Id: Ie5df10bcd7990eab928fc6f7fed3f41eaaa5d469
2020-06-15 11:32:45 -07:00
Joel Brobecker
8fb4f9ee34 Fix setting of GIT_HOOKS_STYLE_CHECKER
Do not use os.getcwd to compute the testcase's directory, as one
testcase may have multiple tests, and each test might do a "cd",
thus modifying the current working directory and thus affecting
the next testcase. Luckily, we have TEST_DIR already, so we might
as well use that.
2016-11-01 07:43:16 -07:00
Joel Brobecker
db894bf25c Use hard-coded git user name and email config during testsuite.
This is to make sure that, we the testsuite creates new commits,
the author name and email do not depend on the user who is runing
the testsuite.
2014-12-21 15:25:05 -05:00
Joel Brobecker
73db3edef6 testsuite/lib/support.py: pep8 violation fixes. 2014-12-21 15:25:05 -05:00
Joel Brobecker
461fec9660 testsuite/lib/support.py: Remove unused imports. 2013-12-30 14:27:45 +04:00
Joel Brobecker
62500a702c Avoid use of "cvs_check" in favor of "style-checker" wherever possible.
Since we're about to allow the use of an alternate style-checker,
and since the name "cvs_check" contains the name of an old technology
we abandonned many years ago, it seems like a good idea to introduce
a more neutral name for that tool.

There is one, non-upward-compatible user-visible change: The script
now uses the GIT_HOOKS_STYLE_CHECKER environment variable, instead
of the GIT_HOOKS_CVS_CHECK environement as a backdoor to specifying
an alternate style-checker.  This should be OK, however, as this
feature was really only meant to be used during testing, and is,
in practice, only really usable in that context.

This is prep work before introducing a new config option allowing
the repository to use an alternate style checker.

Part of MA09-043.
2013-10-11 16:42:57 +04:00
Joel Brobecker
cca0aa4e14 Revert "Make sure the info/attributes file is group-writable."
It turns out that making info/attributes group-writable is not
sufficient: A second user is allowed to overwrite the file, but
then the hooks fail when trying to change the file permissions
to make it group-writable.

We will use a different approach which should not need this anymore.

Part of M116-004.
2013-01-18 07:27:23 +04:00
Joel Brobecker
fc20bd3285 Make sure the info/attributes file is group-writable.
A user needs to be able to overwrite this file, so we make it
group-writable.

Update the testsuite to verify this requirement for both
a repository's .gitattribute file, as well as the bare
repository's default_attribute file.
2013-01-16 12:23:04 +04:00
Joel Brobecker
c5bfa403ac New method support.TestCase.assertRunOutputEqual
This method verifies that the output of a Run is equal to the given
expected output, and otherwise prints the command's image, actual
output, followed by a diff. The "diff" is the part that's new, and
allowed to quickly determine the difference, as the expected output
tends to be quite long in a typical test.

Update all testcases accordingly.
2012-12-28 07:04:10 +04:00
Joel Brobecker
f0b370bd9e New method support.Run.diff allowing us to print output diff...
... after printing the actual output. This allows us to spot
differences much faster.  Adjust branch_no_precommit_check to use it.
2012-12-28 06:31:38 +04:00
Joel Brobecker
719f83658d Add handing of small output differences from git version on kani.
kani provides version 1.7.8.2 while my laptop provides 1.7.10.4.
This patch helps provide testing support for both versions.
2012-12-26 12:11:02 +01:00