After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 720713 - Support running specific unittests with make check
Support running specific unittests with make check
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks: 581525
 
 
Reported: 2013-12-19 03:55 UTC by Simon Feltman
Modified: 2015-02-07 16:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
tests: Use Automake test harness for scanner diff tests (6.69 KB, patch)
2013-12-23 02:36 UTC, Simon Feltman
committed Details | Review
tests: Use EXTRA_LTLIBRARIES instead of check_LTLIBRARIES (3.43 KB, patch)
2013-12-23 02:36 UTC, Simon Feltman
committed Details | Review
tests: Use Automake test harness for warning tests (1.86 KB, patch)
2013-12-23 02:36 UTC, Simon Feltman
committed Details | Review
tests: Refactor test_parser and test_patterns to use unittest.TestSuite (10.74 KB, patch)
2013-12-23 02:36 UTC, Simon Feltman
committed Details | Review
tests: Use Python unittest module parameterization for annotationparser (8.50 KB, patch)
2013-12-23 02:36 UTC, Simon Feltman
none Details | Review
tests: Use Automake test harness instead of gtester (2.66 KB, patch)
2013-12-23 02:36 UTC, Simon Feltman
none Details | Review
tests: Use Automake test harness for tests/offsets (2.53 KB, patch)
2013-12-23 02:36 UTC, Simon Feltman
committed Details | Review
tests: Use Python unittest module parameterization for annotationparser (8.50 KB, patch)
2013-12-23 06:43 UTC, Simon Feltman
committed Details | Review
tests: Use Automake test harness instead of gtester (2.56 KB, patch)
2013-12-28 13:17 UTC, Simon Feltman
committed Details | Review
tests: Update Python stanza to change directories before running tests (1.60 KB, patch)
2013-12-29 20:17 UTC, Simon Feltman
committed Details | Review

Description Simon Feltman 2013-12-19 03:55:03 UTC
In an effort to make the GI codebase a bit friendlier to rapid unittest driven hacking, a good start would be using some form of test discovery and test specification. The idea is to have the ability to single out of specific test cases for a make check run. In PyGObject it is very nice to be able to run:
 $ make check TEST_NAMES=test_gobject.foo.bar
and have a quickly executed test for a specific function being worked on.

One possibility is to use pythons test discovery, but it might be tricky to single out specific cases when there is also automake test harness usage and check-local hooks used in a make check run. But perhaps it would be a matter of supporting two variables for test specification:
 $ make check AMTESTS="" PYTESTS=test_scanner

As an alternative it might be possible to fully use the automake test harness for everything::
http://www.gnu.org/software/automake/manual/html_node/Parallel-Test-Harness.html

I lack expertise with AM so it would be good to hear from others who might have ideas about this? It is also unclear if it is possible to achieve the level of granularity needed to support per-test method runs in Python with automake.
Comment 1 Simon Feltman 2013-12-23 02:36:37 UTC
Created attachment 264780 [details] [review]
tests: Use Automake test harness for scanner diff tests

Add gi-tester script for dispatching various scanner diff tests based on
their target suffix. Hook the dispatcher script into the Automake test
harness which is passed the diff test target name. Remove usage of
check-local which is always run regardless of whether or not the TESTS
variable is set from the command line. This allows for both the ability to
use the harnesses XFAIL_TESTS variable for expected failures as well as
testing of targets individually, for example:

cd tests/scanner
make check TESTS=GtkFrob-1.0.gir
make check TESTS=Regress-1.0-Python

Add Headeronly-1.0-expected.gir for validating the results of the header
only gir creation test.
Comment 2 Simon Feltman 2013-12-23 02:36:42 UTC
Created attachment 264781 [details] [review]
tests: Use EXTRA_LTLIBRARIES instead of check_LTLIBRARIES

Update tests/Makefile.am and tests/scanner/Makefile.am to use
EXTRA_LTLIBRARIES which minimizes the building of libraries to only
dependencies of specific tests when using: make check TESTS="..."
Comment 3 Simon Feltman 2013-12-23 02:36:45 UTC
Created attachment 264782 [details] [review]
tests: Use Automake test harness for warning tests

Update warning tests to use the Automake test harness per-header
file check. This allows for quicker more granular testing, for example:

cd tests/warn
make check TESTS=return-gobject.h
Comment 4 Simon Feltman 2013-12-23 02:36:48 UTC
Created attachment 264783 [details] [review]
tests: Refactor test_parser and test_patterns to use unittest.TestSuite

Update both test_parser.py and test_patterns.py to dynamically generate
TestCase sub-classes rather than modify a statically defined one.
Use unittest.TestSuite to queue up the generated test cases via the
"load_tests" hook.
Use underscores instead of periods as a seperator for dynamically generated
test cases and methods to match Python identifiers.
Beyond general cleanup, these changes will help the ability to specify
Python tests individually.
Comment 5 Simon Feltman 2013-12-23 02:36:50 UTC
Created attachment 264784 [details] [review]
tests: Use Python unittest module parameterization for annotationparser

Add Python unittest module parameterization support to gi-tester through the
use of a "TESTARGS" variable. Use the Automake test harness along with
gi-tester for running the Python annotationparser tests.
Add tests/scanner/annotationparser/Makefile.am and localize testing
rules and EXTRA_DIST setup to this file. Specific Python tests can now be
run as follows:

cd tests/scanner/annotationparser
make check TESTS=test_patterns.py TESTARGS=TestTagValueStability
Comment 6 Simon Feltman 2013-12-23 02:36:53 UTC
Created attachment 264785 [details] [review]
tests: Use Automake test harness instead of gtester

Switch both cmph-bdz-test and gthash_test to use the Automake test harness.
Use EXTRA_PROGRAMS and EXTRA_LTLIBRARIES along with CLEANUP to allow lazy
dependency evaluation of testing targets.
Comment 7 Simon Feltman 2013-12-23 02:36:55 UTC
Created attachment 264786 [details] [review]
tests: Use Automake test harness for tests/offsets

Replace usage of check-local with the Automake test harness. Change check_
variable usage to EXTRA_ in order to avoid building these dependencies with
targeted testing using TESTS= in parent directories.
Comment 8 Simon Feltman 2013-12-23 02:50:27 UTC
Notes on patches:

The gi-tester script in the first patch states a problem I ran into with target names including relative paths back to srcdir for documentation directory diffs. This seems like it might be a bug in Automake but I am unsure. The script has a workaround.

Targeting specific tests with the TESTS environment from a parent directory doesn't work well. You must first cd into the directory where the test target lives then run: make check TESTS="..." (as exemplified in various commit messages). Furthermore, if there are sub-directories within the targeted tests directory, automake will complain when TESTS is specified (but the targeted test is still run correctly).

Most of this work could also be considered somewhat precursory for using the parallel test harness or tap output if that is desired.

I verified "make distcheck" runs successfully after each of these patches.
Comment 9 Simon Feltman 2013-12-23 06:43:41 UTC
Created attachment 264792 [details] [review]
tests: Use Python unittest module parameterization for annotationparser

Fixed path for running Python test as a module from a VPATH build dir.

cd tests/scanner/annotationparser
make check TESTS=test_patterns.py TESTARGS=TestTagValueStability
Comment 10 Simon Feltman 2013-12-28 13:17:34 UTC
Created attachment 264960 [details] [review]
tests: Use Automake test harness instead of gtester

Updated to not use EXTRA_* when appending to CLEANFILES because 
these variables are "global" and might be modified in other includes.
Comment 11 Colin Walters 2013-12-29 18:57:49 UTC
Review of attachment 264780 [details] [review]:

Makes sense.  Thanks for the excellent patch and commit message!
Comment 12 Colin Walters 2013-12-29 19:02:02 UTC
Review of attachment 264781 [details] [review]:

Makes sense.  I didn't know about EXTRA_ before this.
Comment 13 Colin Walters 2013-12-29 19:10:03 UTC
Review of attachment 264782 [details] [review]:

Having an execution binary in TESTS_ENVIRONMENT is deprecated, right?  Although we do that elsewhere, so...ok
Comment 14 Colin Walters 2013-12-29 19:12:34 UTC
Review of attachment 264783 [details] [review]:

I'm not familiar enough with the Python unittest framework to really review this, but the commit message makes sense, and the code looks reasonable.
Comment 15 Colin Walters 2013-12-29 19:15:44 UTC
Review of attachment 264786 [details] [review]:

::: tests/offsets/Makefile.am
@@ +50,3 @@
+TESTS = gitestoffsets
+TESTS_ENVIRONMENT = \
+	GI_TYPELIB_PATH=:$(top_builddir) ./gitestoffsets$(EXEEXT) offsets.compiled offsets.introspected && \

Won't we be running gitestoffsets twice?

I guess that doesn't really hurt, but if we wanted to fix this we'd probably have to push the "diff" invocation down into gitestoffsets.c.
Comment 16 Colin Walters 2013-12-29 19:33:52 UTC
Review of attachment 264960 [details] [review]:

Looks fine.
Comment 17 Colin Walters 2013-12-29 19:35:02 UTC
Attachment 264781 [details] pushed as c981aa7 - tests: Use EXTRA_LTLIBRARIES instead of check_LTLIBRARIES
Attachment 264782 [details] pushed as beb7a56 - tests: Use Automake test harness for warning tests
Attachment 264960 [details] pushed as 4e88f0e - tests: Use Automake test harness instead of gtester
Comment 18 Colin Walters 2013-12-29 19:43:06 UTC
Comment on attachment 264783 [details] [review]
tests: Refactor test_parser and test_patterns to use unittest.TestSuite

Attachment 264783 [details] pushed as 42bb69a - tests: Refactor test_parser and test_patterns to use unittest.TestSuite
Comment 19 Simon Feltman 2013-12-29 19:45:47 UTC
(In reply to comment #13)
> Review of attachment 264782 [details] [review]:
> 
> Having an execution binary in TESTS_ENVIRONMENT is deprecated, right?  Although
> we do that elsewhere, so...ok

I can update all of this in another pass to use the Parallel Test Harness if that is desired. Would we need to add "parallel-tests" to AM_INIT_AUTOMAKE and make sure we have a minimum version which supports it as well?

(In reply to comment #15)
> Review of attachment 264786 [details] [review]:
> 
> ::: tests/offsets/Makefile.am
> @@ +50,3 @@
> +TESTS = gitestoffsets
> +TESTS_ENVIRONMENT = \
> +    GI_TYPELIB_PATH=:$(top_builddir) ./gitestoffsets$(EXEEXT) offsets.compiled
> offsets.introspected && \
> 
> Won't we be running gitestoffsets twice?

It's a bit hacky but the harness appends gitestoffsets to TEST_ENVIRONMENT which ends with "... && echo". So it is only run once but the program name is echoed at the end :) I didn't have any ideas beyond this to get it working. I guess we could also use a custom bash script runner if my solution seems too hacky.
Comment 20 Colin Walters 2013-12-29 19:49:16 UTC
Review of attachment 264792 [details] [review]:

A little sad at further recursive make usage, but this otherwise looks good.  Thanks!
Comment 21 Colin Walters 2013-12-29 19:50:29 UTC
Comment on attachment 264792 [details] [review]
tests: Use Python unittest module parameterization for annotationparser

Attachment 264792 [details] pushed as f27aff2 - tests: Use Python unittest module parameterization for annotationparser
Comment 22 Simon Feltman 2013-12-29 20:17:58 UTC
Created attachment 265004 [details] [review]
tests: Update Python stanza to change directories before running tests

Ensure PYTHONPATH uses absolute paths for top_builddir and top_srcdir. Use
pushd/popd before and after running tests with "python -m unittest...". This
ensures TESTARGS can be used from within a vpath build directory.
Comment 23 Colin Walters 2014-01-02 14:07:14 UTC
Review of attachment 264786 [details] [review]:

Ah...I see.  Looks OK then, thanks!
Comment 24 Colin Walters 2014-01-02 14:11:01 UTC
Review of attachment 265004 [details] [review]:

One comment, feel free to commit with or without change.

::: tests/gi-tester
@@ +46,3 @@
+        ${PYTHON} -m unittest -v "${modulename}.${TESTARGS}"
+        res=$?
+        popd

(cd $(dirname $targetname) &&  ${PYTHON} -m unittest -v "${modulename}.${TESTARGS}")
exit $?

is easier than pushd/popd and this "res" variable, I think.
Comment 25 Simon Feltman 2014-01-02 22:28:34 UTC
Attachment 264786 [details] pushed as 80b54bd - tests: Use Automake test harness for tests/offsets
Attachment 265004 [details] pushed as 8787aec - tests: Update Python stanza to change directories before running tests
Comment 26 Simon Feltman 2014-01-02 22:30:19 UTC
(In reply to comment #24)
> Review of attachment 265004 [details] [review]:
> (cd $(dirname $targetname) &&  ${PYTHON} -m unittest -v
> "${modulename}.${TESTARGS}")
> exit $?
> 
> is easier than pushd/popd and this "res" variable, I think.

Indeed. I went with this and additionally replace all the backtick usage. I'm still learning bash ;)

Also added an additional comment regarding the tailing echo in TESTS_ENVIRONMENT so it doesn't throw future readers off.
Comment 27 André Klapper 2015-02-07 16:47:31 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]