summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)AuthorFilesLines
2020-01-21gvariant-new: Correct spacing in expected error messagePhilip Chimento1-1/+1
2020-01-21build: Meson build systemPhilip Chimento3-162/+257
Removes the existing Autotools build system and adds a new Meson one. Also replaces the shell script test driver with a Python one, since Meson already brings in a Python dependency. Common operations: - ./configure -> meson _build - make -> ninja -C _build - make install -> ninja -C _build install - make check -> meson test -C _build - make Tartan.pot-update -> ninja -C _build tartan-pot - make update-po -> ninja -C _build tartan-update-po To run the tests with coverage enabled and make a coverage report: - meson _build -Db_coverage=true - meson test -C _build - ninja -C _build coverage-html
2019-12-16assertion: Handle C++ try statementsPhilip Chimento1-0/+15
We assume that in any catch blocks, program state has already been modified since an exception has been thrown, so we only look for assertion statements in the try block.
2019-12-16assertion: Handle ExprWithCleanupsPhilip Chimento4-6/+32
This type of expression can occur in several instances, but primarily in C++ where a temporary object is created. In is_assertion_stmt() and _simplify_boolean_expr(), only consider the expression and ignore the cleanups. Adds some machinery to the build system and the test runner script so that we can have test files in C++, for testing C++-only features.
2019-12-16clang-plugin: Update to LLVM 7.0Philip Chimento1-3/+0
Some minor API changes are needed for this. We also make 7.0 the minimum required version. It's the version currently shipped in Debian Stable, so that's a good baseline. (At the time of writing, 9.0.0 is the latest released version.) Fixes: #5
2019-12-16clang-plugin: Require LLVM 4.0 or laterPhilip Chimento1-12/+3
Remove all the guards that checked for earlier versions. See: #5
2019-12-16tests: Fix for aberrant output on macOS clangPhilip Chimento1-1/+2
On macOS, clang will unhelpfully print "(framework directory)" after some of its include paths. Filter this out, so that we don't accidentally stick it in the tartan command line.
2019-12-16tests: Look for built tartan plugin in builddirPhilip Chimento1-1/+1
The previous code seems to be accidentally looking in the srcdir.
2019-12-16tests: Look for template files in srcdirPhilip Chimento1-2/+2
2019-12-16tests: Handle srcdir that is relative to builddirPhilip Chimento2-1/+3
If $srcdir is a relative path, for example starts with "../", then the temp files in this script will escape their temp dir. To prevent this, use $(mktemp -d)/$abs_top_builddir as the temp dir, so that the relative path has somewhere to go.
2019-12-16scripts: Always enable core checkersPhilip Chimento2-20/+8
I was told by a Clang static analyzer developer that running the analyzer without the core checkers enabled is not supported, and I've seen that it can lead to crashes. For this we need to make a few changes to the test programs. In gvariant-iter we need to avoid tripping a warning from a core checker, and in gerror-api we can remove two tests for cases that a core checker already detects. See https://bugs.llvm.org/show_bug.cgi?id=42816
2015-01-27tests: Improve support for testing against LLVM 3.4 and 3.5Philip Withnall1-2/+12
As described in commit 0743df4033967c18a5009e4f01ccf709f7c06c86, LLVM changed an error message between 3.4 and 3.5. We ignored the problem before, but actually it’s easy (if hacky) to fix by checking against both versions of the error message in the wrapper script.
2014-12-22tests: Include some more headers in the generic test headerPhilip Withnall1-0/+2
They turn out to be useful.
2014-11-20tests: Add a non-GLib testPhilip Withnall4-0/+19
As a follow up to commit 915a744037d93abfcaab8b35e98e281cf88bb132, add a non-GLib test, which checks that scanning a file which doesn’t include glib.h succeeds.
2014-11-17gerror: Add a GError checkerPhilip Withnall4-0/+701
This is a path-sensitive checker which detects various invalid usages of the GError API from GLib, such as overwriting GErrors which have not been cleared to NULL, or double-freeing GErrors. It can statically detect all run time errors from preconditions in GError methods. Includes a full unit test suite with > 95% coverage.
2014-11-17fixup! tests: Add a comment about viewing the ExplodedGraphPhilip Withnall1-1/+1
2014-11-17tests: Add a comment about viewing the ExplodedGraphPhilip Withnall1-0/+3
This should aid future debugging.
2014-11-03tests: Update non-null warning messages to support LLVM 3.5Philip Withnall3-43/+43
The wording of the non-null warning messages changed between LLVM 3.4 and LLVM 3.5, so the tests were all arbitrarily failing. This change makes them work on LLVM 3.5 at the expense of failing on LLVM 3.4. There’s no satisfactory way to improve this, short of duplicating the test files and having one copy for 3.4 and one for 3.5.
2014-07-03gsignal: Allow swapped object instances to have actual type gpointerPhilip Withnall2-0/+42
It seems common to use a gpointer argument for the swapped instance parameter (i.e. the last argument) to a signal callback, even though this is not the most specific type known for the variable. Allow this behaviour — hopefully the programmer is correctly dynamically casting the gpointer to something more concrete in the callback body. Either that, or (more likely), ignoring it entirely.
2014-06-30gsignal: Fix expected types for enums and flags in signalsPhilip Withnall2-0/+21
Previously they were expected to be passed as pointers, which was not correct. Now they are expected to be passed by value.
2014-06-30tests: Fix a few expected test outputs for gvariant-new.cPhilip Withnall1-10/+10
Fallout from 234ba46cd95026e763d6a8d7c19cd561c0520ee6.
2014-06-30gvariant: Check for use of architecture-dependent typesPhilip Withnall1-0/+40
If the user passes an architecture-dependent type into a GVariant variadic function, the behaviour will differ between architectures, which we really do not want — essentially the code would be using the wrong width integer on one architecture but not another, which would be hard to track down. This is mostly a problem with ‘long’, which is 32 bits wide on 32-bit systems, and 64 bits wide on 64-bit systems. This was a problem encountered in the wild in telepathy-gabble. Thanks to Simon McVittie for suggesting that Tartan check for it.
2014-06-30gvariant: Explicitly use fixed-width GLib types in error messagesPhilip Withnall1-3/+3
Otherwise we can end up with error messages which recommend using a C standard ‘long’, whose width varies between architectures. Using that is a bad idea.
2014-06-29gsignal: Fix callback instance type checking for supertypesPhilip Withnall2-0/+23
Previously, Tartan would enforce the type relationship: actual <: static but this was wrong, as then the callback could legitimately be invoked with an instance of type T, where: actual <: T and T <: static and it could proceed to call methods defined on actual which are not defined on T, and crash. Instead, the following relationship has to hold: static <: actual which guarantees that for any T passed to the callback, since we have to have T <: static, we definitely also have T <: actual, which is the necessary condition for type safety of function parameters on invocation. Additionally, check whether static = actual and emit a remark if that relationship does not hold, as the callback is most likely performing unnecessary and inefficient dynamic type checks in this case.
2014-06-29tests: Enable quiet mode when running the testsPhilip Withnall1-0/+1
So that extraneous test output does not affect the result matching.
2014-06-28gsignal: Handle signal names containing underscoresPhilip Withnall1-0/+10
It is perfectly valid to specify a signal name with hyphens or with underscores, so support both in the checker.
2014-06-27gsignal: Assume GError types will be GError* in signalsPhilip Withnall2-0/+22
…rather than GError**. If that were the case, multiple handlers for the signal would collide on setting the GError. There is no way it could work sensibly.
2014-06-27gsignal: Improve warning messages if type information cannot be foundPhilip Withnall1-1/+1
It is most likely due to a GIR containing the signal information not being available. As such, make the messages remarks rather than warnings.
2014-06-27gsignal: Add support for signals defined on interfacesPhilip Withnall2-0/+36
Previously the checker would not find the information about a signal which was defined on an interface implemented by the dynamic instance object (or one of its superclasses).
2014-06-27gsignal: Correctly handle incorrect parameter counts in signal callbacksPhilip Withnall2-6/+60
This is a minefield. g_signal_connect_swapped() is intended to be used in situations where the number of formal parameters in the callback function differs from the number of actual parameters emitted by the signal. This allows the common idiom of (e.g.) calling gtk_widget_hide() on a signal callback from another object, with the widget being passed in the user_data. It turns out that these situations are entirely implementation defined. The C specification disavows all knowledge of how parameter passing should work when the callback function prototype isn’t known, leaving this to the calling convention to define. All calling conventions that we care about handle this sensibly, explicitly covering the case of the number of actual parameters exceeding the number of formal parameters, just like they handle varargs. However, there are a few calling conventions which won’t handle this properly, and will cause explosions should you try. For example, I believe that passing a WinAPI function (calling convention: stdcall) as a signal callback will cause problems. I haven’t verified this experimentally though. The gsignal-checker now allows for the number of formal and actual parameters to differ, but only if the calling convention for the callback function is safe. That should cover things.
2014-06-22gsignal: Add support for G_CONNECT_SWAPPEDPhilip Withnall2-0/+102
It was mysteriously missing before, because it is actually a hard problem than it looks to check correctly. This adds support for g_signal_connect_swapped() and g_signal_connect_data() with the G_CONNECT_SWAPPED flag. Currently, the user_data parameter is validated as being any kind of pointer. This could potentially be tightened up in future to check that it is a subtype of the closure variable passed into g_signal_connect() (even in the non-G_CONNECT_SWAPPED case). However, this is best left to a separate checker which examines closure types.
2014-06-09gsignal: Ensure string parameters to signal callbacks are expected constPhilip Withnall2-0/+37
Otherwise the handlers could modify the strings.
2014-06-09gvariant: Add suggestions for GVariant format strings to error messagesPhilip Withnall1-3/+3
When an unexpected extra parameter is passed to a GVariant variadic function, it is useful to tell the programmer what format string they can use for it. This is a first draft, and only covers basic types.
2014-05-30gvariant: Add a unit test for abusing g_variant_lookup()Philip Withnall1-0/+21
This is the first real bug found in the wild by Tartan, in tp-glib.
2014-05-25clang-plugin: Fix error message formatting in GVariant checkerPhilip Withnall6-53/+53
The Clang QualType formatting adds quotation marks, but our error messages already contained them. Loath as I am to revert to using ASCII quotation marks, the formatting provided by QualType is quite good (since it adds aka information), so drop the old Tartan Unicode quotation marks.
2014-05-09tests: Check for all expected error lines rather than just onePhilip Withnall4-21/+32
Previously, the wrapper-compiler-errors script was assuming a test was successful if it could see at least one of the expected error message lines in the compiler output. Since several of those lines are boilerplate, this hid legitimate test failures. Fix it so that *all* expected lines are checked for (although there are no checks which test that *only* those lines were output), and fix up a few tests.
2014-05-08clang-plugin: Add a g_signal_connect() checkerPhilip Withnall4-0/+263
This validates that: • The named signal exists on the given GObject subclass. • The type of the callback function matches that declared for the signal. Unit tests are included.
2014-05-07build: Rename from gnome-clang to TartanPhilip Withnall2-9/+9
Make the name a little less GNOME-centric, since the plugin actually only (currently) deals with GLib, so has much wider application than just on GNOME code. Also, ‘Tartan’ sounds cooler.
2014-05-06tests: Use the uninstalled gnome-clang and plugin in the testsPhilip Withnall1-2/+8
Rather than assuming they’re installed.
2014-05-06tests: Fix builddir ≠ srcdir problemsPhilip Withnall1-3/+8
Also ensure all the right test files are distributed.
2014-05-06tests: Add tests for existing assertion extraction codePhilip Withnall7-0/+332
Test that extracting non-NULL checks from g_return[_val]_if_fail() calls works.
2014-05-06clang-plugin: Automatically promote int to uint with constant varargsPhilip Withnall1-0/+14
If an integer constant is passed as a vararg, it will be passed as a signed integer to the function. For integers less than G_MAXINT this is not a problem (as the bit representations of int and uint are the same to that point). Modify the GVariant checker to accept low-valued signed integers for unsigned integer GVariant elements.
2014-05-06clang-plugin: Don’t confuse integer constants with NULLPhilip Withnall1-0/+8
The integer constant 0 can be interpreted as NULL, so only perform NULL pointer checks when the expected type is a pointer.
2014-05-06tests: Move templates out of wrapper-compiler-errors into new filesPhilip Withnall13-23/+64
This makes the tests a little less hard-coded.
2014-05-06clang-plugin: Support (optional) and (nullable) attributesPhilip Withnall2-0/+32
This loosely depends on the GLib patch in bug #719966.
2014-05-05clang-plugin: Enable GVariant checks for other methodsPhilip Withnall6-2/+210
This enables GVariant format string checking for: • g_variant_get_child() • g_variant_lookup() • g_variant_iter_next() • g_variant_iter_loop() • g_variant_builder_add() and adds basic unit tests for all of them. GVariant support is now complete!
2014-05-05clang-plugin: Add support for checking g_variant_get() callsPhilip Withnall4-3/+517
This required a little further work on top of the work for checking g_variant_new() calls, as g_variant_get() takes outbound arguments, rather than inbound ones, so has an extra level of indirection. Further to that, integer promotion doesn’t occur, and nullable arguments are treated a little differently. This includes a set of unit tests for g_variant_get().
2014-05-03clang-plugin: Add support for a GVariant checkerPhilip Withnall3-0/+1085
This checker will examine the code for GVariant method calls, such as those to g_variant_new(), and will proceed to check the types of the variadic arguments in the call against the GVariant format string in the call (assuming this format string is constant). For GVariant methods such as g_variant_new_va(), which take a va_list rather than varargs, the validity of the GVariant format string is checked, but the va_list itself cannot be. There are a few limitations to the checker at the moment. These are noted in FIXME comments, but are minor and don’t affect correctness. (Implementing them would, however, make the checker more strict.) A test suite is included with over 100 tests for parsing valid and invalid g_variant_new() and g_variant_new_va() calls. The test suite uses a custom test harness which splits up the test file, adds boilerplate, and then attempts to compile it with gnome-clang enabled. It then compares the compiler output to an expected error message.