Commit 6f5ccf7e authored by Philip Chimento's avatar Philip Chimento

coverage: Expose GjsCoverage in public API

This exposes the GjsCoverage type, its constructor gjs_coverage_new(),
and its method gjs_coverage_write_statistics(), for GJS embedders who
would like to gather code coverage statistics. (gnome-shell doesn't
currently do this, but it could.)

https://bugzilla.gnome.org/show_bug.cgi?id=775776
parent be554f06
......@@ -37,6 +37,7 @@ gjs_public_includedir = $(includedir)/gjs-1.0
########################################################################
nobase_gjs_public_include_HEADERS = \
gjs/context.h \
gjs/coverage.h \
gjs/gjs.h \
util/error.h \
$(NULL)
......@@ -151,7 +152,6 @@ libgjs_la_SOURCES += $(libgjs_private_source_files)
# These used to be public headers for external modules
libgjs_la_SOURCES += \
gjs/coverage.h \
gjs/byteArray.h \
gjs/importer.h \
gjs/jsapi-util.h \
......
......@@ -9,6 +9,11 @@ NEXT
[1] https://github.com/calvinmetcalf/lie
[2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
- News for GJS embedders such as gnome-shell:
* New API: The GjsCoverage type and its methods are now exposed. Use this if
you are embedding GJS and need to output code coverage statistics.
Version 1.47.3
--------------
......
......@@ -30,8 +30,6 @@
#include <gjs/gjs.h>
#include "coverage.h"
static char **include_path = NULL;
static char **coverage_prefixes = NULL;
static char *coverage_output_path = NULL;
......
......@@ -29,7 +29,11 @@
#include "jsapi-util-args.h"
#include "util/error.h"
struct _GjsCoveragePrivate {
struct _GjsCoverage {
GObject parent;
};
typedef struct {
gchar **prefixes;
GjsContext *context;
JS::Heap<JSObject *> coverage_statistics;
......@@ -38,7 +42,7 @@ struct _GjsCoveragePrivate {
GFile *cache;
/* tells whether priv->cache == NULL means no cache, or not specified */
bool cache_specified;
};
} GjsCoveragePrivate;
G_DEFINE_TYPE_WITH_PRIVATE(GjsCoverage,
gjs_coverage,
......@@ -1163,6 +1167,19 @@ coverage_statistics_has_stale_cache(GjsCoverage *coverage)
static unsigned int _suppressed_coverage_messages_count = 0;
/**
* gjs_coverage_write_statistics:
* @coverage: A #GjsCoverage
* @output_directory: A directory to write coverage information to. Scripts
* which were provided as part of the coverage-paths construction property will be written
* out to output_directory, in the same directory structure relative to the source dir where
* the tests were run.
*
* This function takes all available statistics and writes them out to either the file provided
* or to files of the pattern (filename).info in the same directory as the scanned files. It will
* provide coverage data for all files ending with ".js" in the coverage directories, even if they
* were never actually executed.
*/
void
gjs_coverage_write_statistics(GjsCoverage *coverage)
{
......
......@@ -21,57 +21,16 @@
#define _GJS_COVERAGE_H
#include <glib-object.h>
#include <gio/gio.h>
#include "context.h"
G_BEGIN_DECLS
#define GJS_TYPE_COVERAGE gjs_coverage_get_type()
#define GJS_COVERAGE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GJS_TYPE_COVERAGE, GjsCoverage))
#define GJS_COVERAGE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GJS_TYPE_COVERAGE, GjsCoverageClass))
#define GJS_IS_COVERAGE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
GJS_TYPE_COVERAGE))
#define GJS_IS_COVERAGE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
GJS_TYPE_COVERAGE))
#define GJS_COVERAGE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
GJS_TYPE_COVERAGE, GjsCoverageClass))
typedef struct _GFile GFile;
typedef struct _GjsContext GjsContext;
G_DECLARE_FINAL_TYPE(GjsCoverage, gjs_coverage, GJS, COVERAGE, GObject);
typedef struct _GjsCoverage GjsCoverage;
typedef struct _GjsCoverageClass GjsCoverageClass;
typedef struct _GjsCoveragePrivate GjsCoveragePrivate;
struct _GjsCoverage {
GObject parent;
};
struct _GjsCoverageClass {
GObjectClass parent_class;
};
GType gjs_coverage_get_type(void);
/**
* gjs_coverage_write_statistics:
* @self: A #GjsCoverage
*
* This function takes all available statistics and writes them out to either the file provided
* or to files of the pattern (filename).info in the same directory as the scanned files. It will
* provide coverage data for all files ending with ".js" in the coverage directories, even if they
* were never actually executed.
*/
void gjs_coverage_write_statistics(GjsCoverage *self);
GjsCoverage * gjs_coverage_new(const char * const *coverage_prefixes,
......
......@@ -25,6 +25,7 @@
#define __GJS_GJS_H__
#include <gjs/context.h>
#include <gjs/coverage.h>
#include <util/error.h>
#endif /* __GJS_GJS_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment