[gjs] coverage: Expose GjsCoverage in public API



commit 6f5ccf7edb704aae2cee45a87c21eef92f52e74f
Author: Philip Chimento <philip endlessm com>
Date:   Fri Dec 9 18:30:41 2016 -0800

    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

 Makefile.am      |    2 +-
 NEWS             |    5 +++++
 gjs/console.cpp  |    2 --
 gjs/coverage.cpp |   21 +++++++++++++++++++--
 gjs/coverage.h   |   49 ++++---------------------------------------------
 gjs/gjs.h        |    1 +
 6 files changed, 30 insertions(+), 50 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 66c82d5..ddafaa3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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        \
diff --git a/NEWS b/NEWS
index 2d439df..5e3651e 100644
--- a/NEWS
+++ b/NEWS
@@ -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
 --------------
 
diff --git a/gjs/console.cpp b/gjs/console.cpp
index a70e2b7..be20b67 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -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;
diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp
index 406664a..002c79f 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -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)
 {
diff --git a/gjs/coverage.h b/gjs/coverage.h
index 4d91fa0..f460b1d 100644
--- a/gjs/coverage.h
+++ b/gjs/coverage.h
@@ -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,
diff --git a/gjs/gjs.h b/gjs/gjs.h
index 5cb1810..97f9906 100644
--- a/gjs/gjs.h
+++ b/gjs/gjs.h
@@ -25,6 +25,7 @@
 #define __GJS_GJS_H__
 
 #include <gjs/context.h>
+#include <gjs/coverage.h>
 #include <util/error.h>
 
 #endif /* __GJS_GJS_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]