Commit Graph

13 Commits

Author SHA1 Message Date
Jun Wu
b1cbb08eb8 unit: scan extensions to run extra tests
If a test enables extension X, then changes to extension X should trigger
that test to run.

This avoids issues like D123 not updating all tests that need change.

Test Plan:
Make a test commit touching `fbamend/__init__.py`, and run `unit.py`:

  37 tests to run: test-smartlog-tweakdefaults.t test-fbamend-metaedit.t test-fbamend-split.t test-check-execute-hg.t test-check-shbang-hg.t test-fbamend-restack.t test-sqldirstate-fbhistedit.t test-fbamend-previous.t test-fbhistedit-stop.t test-fbamend-next.t test-tweakdefaults.t test-copytrace-amend.t test-fastpartialmatch-obsolete.t test-fbamend-nextrebase.t test-fbamend-hiddenoverride.t test-fbamend-fold.t test-check-config-hg.t test-fbhistedit-exec.t test-smartlog-obsolete.t test-infinitepush-bundlestore.t test-fbamend-rebase.t test-fbamend-to.t test-reset.t test-infinitepush-pullback-obsolete.t test-tweakdefaults-opawarecommands.t test-fbamend-userestack.t test-fbamend-noinhibit.t test-smartlog-inhibit.t test-check-commit-hg.t test-cleanobsstore.t test-infinitepush-backup.t test-check-code-hg.t test-check-pyflakes-hg.t test-fbamend.t test-pull-createmarkers.t test-pull-createmarkers-hide-later.t test-tweakdefaults-bookmarks.t

Note `test-smartlog-tweakdefaults.t` does not have `fbamend` in its filename
and is also triggered.

Differential Revision: https://phab.mercurial-scm.org/D148
2017-07-19 10:43:01 -07:00
Jun Wu
83c88e7a24 modcheck: check if external modules are imported
Summary:
When testing code in this repo, it's an easy mistake to import a module of a
same name installed in the system or specified by `PYTHONPATH`. This diff
adds a test module to detect that. It's included in `unit.py` so `arc unit`
will be able to find such issues

It will be more effective if all our extensions are moved to hgext3rd.

Test Plan:
Append a blank line to every `.t` files, and run `unit.py` with `hg-dev`
environment, and make sure nothing got reported.

Reviewers: durham, #mercurial, mitrandir

Reviewed By: mitrandir

Subscribers: mitrandir, medson, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D5274454

Signature: t1:5274454:1497976474:1b25881f022e148b89829ed3f4d6a79437f2533f
2017-06-20 13:40:53 -07:00
Adam Simpkins
6d24f86d76 arcanist: support arc unit --all
Summary: Update the MercurialTestEngine and unit.py script to support running all tests.

Test Plan: Ran `arc unit --all`

Reviewers: #sourcecontrol, quark

Reviewed By: quark

Subscribers: net-systems-diffs@fb.com, yogeshwer, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4856665

Signature: t1:4856665:1491623577:da0b639121d9df6b933d160d4776ec3515a91187
2017-04-10 11:44:32 -07:00
Adam Simpkins
dd746f1765 unittests: add option to skip the test-check* tests
Summary:
Update scripts/unit.py with an option to skip running all of the test-check*
tests.  This makes it easier to run just a single specific test when developing
a unit test itself.

Test Plan:
Used "./scripts/unit.py --skip-checks tests/test-smartlog.t" when adding new
tests to test-smartlog.g

Reviewers: #sourcecontrol, stash, mjpieters, rmcelroy

Reviewed By: rmcelroy

Subscribers: net-systems-diffs@, yogeshwer, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4430919

Signature: t1:4430919:1484820777:08da5f8fd4144bf05c7596db846d827b3680bc3e
2017-01-19 12:52:54 -08:00
Jun Wu
2698cf1d22 scripts: unify spwaning run-test logic
Summary:
Previously, lint.py and unit.py have different logic spawning
run-tests.py.

The logic in `unit.py` is more robust: it sets `PYTHONPATH` and
`cwd`. It sets `-j` according to CPU cores. It can find `run-tests.py`
even if `MERCURIALRUNTESTS` is not set. You can run the script
from any directory (not only reporoot).

Test Plan: Run `lint.py` and `unit.py`, from the `scripts` directory and reporoot.

Reviewers: #sourcecontrol, stash

Reviewed By: stash

Subscribers: stash, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4095437

Signature: t1:4095437:1477663516:13a7ac4270435c272077132915f9d02cc98a5afb
2016-10-28 13:58:48 +01:00
Jun Wu
dc57735d63 arc: include test-check-code-hg in unit tests
Summary:
Previously, `arc unit` does not run `test-check-code-hg.t` and if people
have ignored lint errors, they may be ignored forever.

Since test-check-code-hg.t is relatively fast (3 seconds), let's also
run it during `arc unit`.

Test Plan: `arc unit` and confirm test-check-code-hg shows up.

Reviewers: #sourcecontrol, durham

Reviewed By: durham

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4051073

Signature: t1:4051073:1476985307:5448827437ecee9add534855a0f87ac3c3bd1f84
2016-10-20 15:44:26 +01:00
Adam Simpkins
27acd63250 [arc] honor paths specified by "arc unit"
Summary:
Update MercurialTestEngine.php and the unit.py script to honor the list of
changed files computed by arcanist.

Previously the unit.py script always used the files that were changed since the
".^" commit.  At best this was doing redundant work since arc had already
computed the list of files to test.  At worst this was testing the wrong files
if arc had been invoked with a list of explicit files to check.

Test Plan:
Ran "arc unit tests/test-mergedriver.t" and confirmed it ran the
test-mergedriver.t test, regardless of the changes in my current commit and
working directory.  Confirmed that "arc unit" with no path arguments still
ran the tests relevant to my local changes.

Reviewers: quark, rmcelroy, mjpieters

Reviewed By: mjpieters

Subscribers: net-systems-diffs@, yogeshwer, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4004727

Signature: t1:4004727:1476258607:d6adb5ec3d677f6d93016a994cadaa7a48df353a
2016-10-13 11:48:02 -07:00
Adam Simpkins
8d1252d8d3 [unit] minor refactoring of interestingtests()
Summary:
This is just a minor performance clean-up of interestingtests(), even though
performance probably isn't a big deal here (unless we eventually get a very
large number of tests).

The old code was calling words(path) once per test file (for each path), rather
than just once.  I cleaned up the code so that we only call it once per path.

I also updated the code to build testwords as a dictionary so we can do an easy
lookup to find relevant tests for a given word, rather than having to do a
linear scan of all tests.  We now also don't bother computing the words for
test-check* tests.

Test Plan:
Manually confirmed that interestingtests() returns the expected test lists for
a variety of input paths.

Reviewers: simonfar, quark

Reviewed By: quark

Subscribers: net-systems-diffs@, yogeshwer, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3935730

Signature: t1:3935730:1475052012:08b9a495c7c3e7fc2d0b9eaa097d5286874edf46
2016-09-28 12:08:10 -07:00
Adam Simpkins
68222e17e9 [unit] fix computation of changed files
Summary:
Make sure a nul byte is printed between the list of files changed in the
working directory and the files changed in the parent commit.

Previously these two lists were printed back-to-back, causing the last path
from the working directory to be joined with the first path from the parent
commit.

Also return the results as a set so we exclude duplicates if a file was changed
both in the working directory and in the current commit.

Test Plan:
Manually printed the changedfiles computed, and confirmed that the lists were
correct.

Reviewers: simonfar, durham, quark

Reviewed By: quark

Subscribers: net-systems-diffs@, yogeshwer, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3935654

Signature: t1:3935654:1475053555:66da9102e312d8d345d00c4d41f76d41ce673069
2016-09-28 11:59:55 -07:00
Adam Simpkins
4f37b53188 Various improvements to scripts/unit.py
Summary:
- Set PYTHONPATH so we actually test the extensions from the local repository
  rather than the versions installed in the system's normal python library
  directories.
- Invoke the test runner directly with subprocess, rather than via a subshell,
  and always wait for it to exit, even if we receive an interrupt during the
  test run.
- Various other minor refactoring of argument parsing and handling of the json
  results file.

Test Plan:
Ran scripts/unit.py and confirmed it tested the local version of remotefilelog,
rather than the system version.

Reviewers: durham, simonfar, quark

Reviewed By: quark

Subscribers: net-systems-diffs@, yogeshwer, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3935628

Tasks: 13595089

Signature: t1:3935628:1475052856:61480fddbf97c830496257b89be3999364ab7c31
2016-09-28 12:10:17 -07:00
Jun Wu
230550558a arc: do not pollute tty when running arc unit
Summary: It breaks CLI vim users.

Test Plan: Code Review

Reviewers: durham

Reviewed By: durham

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3915796

Signature: t1:3915796:1474662158:dfca849d9aa2914e799c267205178db67860d2d1
2016-09-23 21:20:46 +01:00
Adam Simpkins
1a72bd37c9 Make sure "arc unit" doesn't crash if there are no tests to run
Summary:
Make sure we write an empty results lists even if there are no interesting
tests to run.

(Alternatively, I could have made MercurialTestEngine.php handle a null result
from json_decode(), but this could also mean that the json results were
invalid, or that they had encoded data deeper than json_decode()'s recursion
limit.  Making sure unit.py always writes a result means we will still bail out
as desired if the result file was bogus for some reason.)

Test Plan: Ran "arc unit" on this diff.

Reviewers: simonfar, quark

Reviewed By: simonfar, quark

Subscribers: net-systems-diffs@, yogeshwer, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3911461

Signature: t1:3911461:1474623139:f04f78dd5d5fa59f83e1171d21608eb38647142f
2016-09-23 12:35:31 -07:00
Jun Wu
71c96fe8ea arc: implement an arcanist unittest engine for mercurial
Summary:
This makes `arc unit` work for the repo.
Hopefully it helps improve the code quality.

Test Plan:
Run `arc unit`. Make some changes locally to confirm
it can handle skipped and failed tests.

Reviewers: #sourcecontrol, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3889495

Signature: t1:3889495:1474454314:b3fb7e538979c775f8301d9abdad0d6eda71e411
2016-09-19 22:41:58 +01:00