166 Commits

Author SHA1 Message Date
Joel Brobecker
d39541321e Add support for recognizing C++ files, with same checks as C files
This commit adds support for C++ files, which were previously
not recognized (unless they used C file extensions). The same
checks as for C files are applied, in fact, the same checker
is used for both.

Change-Id: Ic98a68530b4cb280ef2846e282511e3c7e550c25
TN: W105-011
2023-01-06 08:38:08 +04:00
Joel Brobecker
d8e3cc3646 run-validation-tests: disable PIP version check when calling pip3
The run-validation-tests has a pre-testing phase where it verifies
that all necessary dependencies for running the testsuite without
error are present. One of those checks is the list of Python modules
being installed, which we get by calling pip3, asking for the list
in JSON format.

This commit avoids a testsuite crash when the version of pip being
installed is not the latest one:

| $ ./run-validation-tests
| Traceback (most recent call last):
| [...]
|   File "/[...]/./run-validation-tests", line 117, in check_dependencies
|     package_list_from_pip3 = json.loads(p.out)
| [...]
|     raise JSONDecodeError("Extra data", s, end)
| json.decoder.JSONDecodeError: Extra data: line 3 column 1 (char 5379)

The error happens because pip added the following warning
after the JSON output:

    | $ pip3 list --format=json
    | [JSON data snipped]
    |
    | [notice] A new release of pip available: xxxx -> yyyy
    | [notice] To update, run: python -m pip install --upgrade pip

This commit avoids this issue by telling pip3 to not do a version check.

Found while working on W105-011.

Change-Id: I00cfd6203d113c28e6ddb2991d6eae3834308f8b
2023-01-06 07:35:23 +04:00
Joel Brobecker
6893f51cf4 explicitly recognize .txt files as text files requiring no style checking
We had a situation where the style_check incorrectly thought that
a .txt file was a Python file, and thereore activated the corresponding
checkers, leading to a spurious error. This comes from the fact that,
by default, we use the "file" command to analyze files whose extension
we don't explicitly already recognize. The problem, here, is that "file"
returns something unexpected, leading us down the wrong path.

Since I don't see a .txt extension being used for anything but pure
text files, it seems reasonable to recognize those explicitly and
then disable all style checks on those.

Change-Id: I1377647f727b9d1e7cf00d04e15ad574536f1050
TN: V614-013
2022-06-14 10:01:01 -07:00
Joel Brobecker
81317a4d04 Update black to version 21.5b1, and flake8 to version 3.9.1
This commit upgrades the pre-commit checks to using newer versions
of black and flake8. The code was then reformatted with this new
version of black.

Change-Id: I146b6529c0c4521266367cda5a4a55cfc7d8f054
2022-06-14 09:19:21 -07:00
Joel Brobecker
53321a47e5 replace use of distutils.version by packaging.version
distutils.version is deprecated, unfortunately, so this commit
changes the testsuite to use packaging.version instead.

Change-Id: I2140eb72d0f2e5221586bcd7e666cc15a1728ef9
2022-06-14 09:19:21 -07:00
Joel Brobecker
423d4fdb26 Run the testsuite with -vv to get more detailed info in case of error
This commit adds -vv to the list of command-line arguments we pass
to pytest when running the testsuite. This doesn't change anything
when the test is successful, but increases the amount of information
being provided when a test fails. In particular, when a string equality
test fails, it'll show the whole diff, rather than just an abbreviated
version of the expanded strings. Without this, if the strings are
are a few lines long, it becomes impossible to diagnose the issue
just from the testsuite report alone.

Change-Id: I5ecdbb3a9badf12f33ea9fd1091f6e170310492c
2022-06-14 09:19:14 -07:00
Joel Brobecker
e77cfbf3fc Add test for UB09-015 (force -gnatX for all GNAT runtime files)
Change-Id: I7e83c4c878792660d77fe186a11dc8255c70c8ed
2022-06-14 06:16:52 -07:00
Joel Brobecker
a82082fcdf Update various tests' expected output after V103-009
In V103-009, I updated the list of valid copyright holders
to add a couple more names, but clearly I forgot to run
the testsuite, because this of course causes some changes
to the style_checker's output when a file should have a valid
copyright, but does not.

This commit fixes that omission, allowing us to get clean testing
again.

Change-Id: I652d88d81cb91c04126cb0fc00219ab1fb1a85e0
TN: V103-009
2022-06-14 06:14:48 -07:00
Joel Brobecker
f8804ab767 Add 'Capgemini Engineering' as valid copyright holder
Change-Id: I1ca0f5c90172b3cca990fea11d1e9d52e0f965d3
TN: V103-009
2022-01-05 03:25:17 +00:00
Joel Brobecker
e498794183 Force -gnatX for all GNAT runtime files
For Ada runtimes, we were relying on -gnatg to imply -gnatX
to allow GNAT extensions in those files. However, this isn't
always the case, so this commit changes the style_checker to
always call the compiler with -gnatX when checking a file
that's identified as a GNAT runtime file.

Change-Id: I913417e4b70b4cd13925b6f3b95887562a678bee
TN: UB09-015
2021-11-12 14:53:18 +04:00
Joel Brobecker
93091469a1 Add new "BIDI" rule to reject potentially dangerous unicode characters
A new rule is added to reject certain unicode characters that
an attacker could use to exploit the Unicode Bidi algorithm
and construct source code that would appear innocuous when rendered
in an editor, but that would actually contain malicious code.

This new rule is applied to all files which are known by
the style_checker to be a programming language.

Change-Id: Ic0e4a7d17d316effcfe9c74ef5b57b8bcf5b1779
TN: UB03-053
2021-11-12 07:52:23 +04:00
Joel Brobecker
a4ea3e1777 Adjust expected output from newer version of checkstyle (java checker)
For the record, this is the output when using checkstyle version 8.36.1.

Change-Id: I2d4272ce5269b1a806467971caeb3bd43edf58e8
2021-11-12 07:52:13 +04:00
Joel Brobecker
17108ebfc4 Allow Ada 2022 features by default
Change-Id: I9b3c99e0eff691a89a67c1fb7c7ca1f667cb5cb6
TN: U618-006
2021-06-28 10:02:57 -07:00
Joel Brobecker
2ecbe84a40 testsuite/conftest.py::env_setup: run testcase inside <tmp>/src
This commit fixes a small thinko: The "env_setup" fixture creates
a temporary directory, and then creates inside that temporary
directory two more subdirectories: A "tmp" directory, and an "src"
directory. The intent for that "src" directory was to be the working
directory inside which the testcase's sources would be copied and
the testcase itself be run.

The problem is that we os.chdir-ed to the temporary directory,
rather than the "src" subdirectory inside that temporary directory.
As a result, the testcase ended up not using our "src" subdirectory
at all. It's cleaner to run our testcase in that "src" subdirectory
because it is guaranteed to be empty at the time we copy the testcase's
sources over, so this commit fixes this issue by chdir-ing to
the "src" subdirectory.

Change-Id: I4047d805a7c658faee0cb8bc4f5094ae5110d61e
2021-04-25 14:48:32 +04:00
Joel Brobecker
7ada3b92c0 Rename all testcase scripts to all use the same name "run_test.py"
Up until recently, having unique filenames for the testcases was
required by pytest due to the way pytest was called and the testsuite
architected. But now that we're using --import-mode=importlib,
there is no such limitation anymore. So this commit renames all
current testcase scripts to a simpler, shorter and more consistent
"run_test.py".

For the record, the shell command used to do the renaming was:

    for i in */test_*.py; do
      tc_dir=`echo $i | cut -d/ -f1`
      git mv $i ${tc_dir}/run_test.py
    done

Change-Id: If8592e7812a2d8549d8c35a2272e93725f21377d
2021-04-20 06:55:31 +04:00
Joel Brobecker
d1eb130958 run-validation-tests: use pytest with --import-mode=importlib
Add a comment explaining why.

Change-Id: I186371cede9d021fa35d07665673d18aa2ebf93d
2021-04-20 06:55:23 +04:00
Joel Brobecker
71a81796a9 run-validation-tests: Run the style validation testing first...
... and abort the testing if this testing returned some errors.
Basically: We know that we're going to have to fix any style
violation found, which means modifying the code, which in turn
means we'll need to re-run the testsuite anyway. Might as well
just abort the testing early... Users who still want to do
the testing regardless of style violations can always bypass
this via --no-style-checking.

Change-Id: I2c68420243f36222a7f5a95102a20ca725b18d15
2021-04-20 06:55:17 +04:00
Joel Brobecker
283daae611 Use pre-commit instead of just flake8 to perform style conformance testing
Now that we have the pre-commits configured to use a variety of
tools, re-use this to perform the style conformance testing.

This commit also adapts the list of required Python packages
accordingly.

Change-Id: Ie908ee9934c3dcda407890f0e33e98985920a4f0
2021-04-20 06:55:09 +04:00
Joel Brobecker
3c4fb1eed0 .pre-commit-config.yaml: Add flake8 and black checks
Change-Id: Iaf91151c3169a20c1047e998e81d3c24ae6e7514
2021-04-20 06:55:02 +04:00
Joel Brobecker
033a11a00f pre-commit config: exclude testsuite/tests/ rather than all of testsuite/
This allows the files used as part of the testsuite's framework to
still be covered by the precommit-check.

Change-Id: I195842105d85e43e4f27ba4ce615c383bb5d91fa
2021-04-20 06:54:55 +04:00
Joel Brobecker
a42c2a57cf Reformat code with black
This commit simply runs "black" on all our Python files except
those in testsuites/tests/.

Note that I ran into one small difficulty when reformatting setup.py,
where black was reformatting a couple of lines in the code in a way
that it triggered the following E231 flake8 violations:

    setup.py:23:69: E231 missing whitespace after ','
    setup.py:25:74: E231 missing whitespace after ','

This is a known issue with black...

    https://github.com/psf/black/issues/1288

... which is fortunately easily worked around by simply removing
the offending comma (black does not add it back).

Change-Id: I492eb1ca5fa371d063e691f7fe06c47daae60d4c
2021-04-20 06:54:47 +04:00
Joel Brobecker
1eb13e8c8b setup.cfg [flake8]: Add max-line-length = 88 (prep for black formatting)
Change-Id: I0761a8e13fdceb2abc7967cd2850d3161ba34cb9
2021-04-20 06:54:37 +04:00
Joel Brobecker
aedd9636da setup.cfg [flake8]: Use "extend-ignore" instead of "ignore"
That way, we do not have to hardcode the list of rules that flake8
ignores by default just so we could add our own list of extra ignores.
This also brings the ignore list in line with what AdaCore's style_check
does.

Change-Id: I717e2918dd23a46440e96b2319129cddd23df8f9
2021-04-20 06:54:30 +04:00
Joel Brobecker
90f02fe4a3 run-validation-tests: Improve our check for the pytest-cov plugin install
Instead of checking for the "coverage" executable as a roundabout way
to check if the "pytest-cov" pluggin has been installed, just use
the new pip3-based mechanism. It brings this check in line with
the check for the pytest-xdist plugin.

Change-Id: Ie020b63078d87b356038eeba92b9f107563729f6
2021-04-20 06:54:25 +04:00
Joel Brobecker
5b5aee4af9 run-validation-tests: Sort items in list in alpha order (cosmetic)
This commit sorts the list of required_packages in alphabetical order,
so as to make it easier and faster to scan it when looking for
a specific entry.

Change-Id: I91e1d187dd86ff6b1318b922197c09817be11b3c
2021-04-20 06:54:18 +04:00