Commit Graph

44 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
54877f91a3 testsuite: change the testcase filename from "test.py" to "run_test.py"
This is a small step towards migrating this testsuite towards
a pytest-based framework: The filename currently used for testcases
is "test.py", and that filename does not match the nomenclature
that pytest expects for testcase files. So this commit renames
all our testcases to something that pytest can identify as a testcase
file to load and execute, and then adjusts the current testsuite
framework accordingly.

Change-Id: I77fba65e8ea20612259c6ad10459fe96ef77a2fc
2021-04-18 18:57:38 +04:00
Joel Brobecker
a075b1653e reformat all the code using black
Change-Id: Idbc70777233ab2d40ab59765abb9cbbeeb88ec63
2021-04-18 14:59:01 +04:00
Joel Brobecker
17ab129046 get_testcases: Use "_" instead of unused variable as loop control variable
This fixes an error flagged by flake8 as B007.

Change-Id: I6c9f6d9cf5af13580648e62eedb7b11e05127891
2021-04-18 14:53:37 +04:00
Joel Brobecker
7ce38d4803 testsuite/lib/utils.py: Fix various flake8 violations
This commit fixes the following flake8 violations:

    utils.py:7:1: E302 expected 2 blank lines, found 1
    utils.py:24:1: E302 expected 2 blank lines, found 1
    utils.py:33:1: W391 blank line at end of file

Change-Id: I925809e1b0baa21c726bc2096ba3edb242e2f688
2020-11-23 12:11:49 +01:00
Simon Marchi
a2909b2c8d Convert print statements to print function
In preparation for the transition to Python 3, convert to using the
print function.  The special import

    from __future__ import print_function

in Python 2.7 makes "print" become the function and not the statement.
In Python 3, it has no effect.  Once the transition is done and we
exclusively use Python 3, we can simply remove the imports.

The testsuite shows no regressions.
2020-11-22 19:29:38 -05: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
153fbe32fc lib/testsuite: Remove Env import. Not used. 2013-12-30 14:24:56 +04:00
Joel Brobecker
50fd97b3e6 testsuite: Print summary at end of testsuite run. 2013-12-30 14:24:21 +04:00