Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - gp - texmacs.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 21331-964717c) Lines: 0 114 0.0 %
Date: 2017-11-17 06:20:57 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /*******************************************************************/
      15             : /*                                                                 */
      16             : /*                    TEXMACS-SPECIFIC STUFF                       */
      17             : /*                                                                 */
      18             : /*******************************************************************/
      19             : #include "pari.h"
      20             : 
      21             : #include "paripriv.h"
      22             : #include "gp.h"
      23             : 
      24             : #define DATA_BEGIN  ((char) 2)
      25             : #define DATA_END    ((char) 5)
      26             : #define DATA_ESCAPE ((char) 27)
      27             : 
      28             : /*******************************************************************/
      29             : /*                                                                 */
      30             : /*                      READLINE INTERFACE                         */
      31             : /*                                                                 */
      32             : /*******************************************************************/
      33             : #ifdef READLINE
      34             : static pari_rl_interface pari_rl;
      35             : #endif
      36             : static int did_complete = 0;
      37             : 
      38             : #ifdef READLINE
      39             : BEGINEXTERN
      40             : #include <readline/readline.h>
      41             : ENDEXTERN
      42             : 
      43             : static void
      44           0 : print_escape_string(char *s)
      45             : {
      46           0 :   long l = strlen(s);
      47           0 :   char *t, *t0 = (char*)pari_malloc(l * 3 + 3);
      48             : 
      49           0 :   t = t0; *t++ = '"';
      50           0 :   for ( ;*s; *t++ = *s++)
      51           0 :     switch(*s)
      52             :     {
      53             :       case DATA_BEGIN:
      54             :       case DATA_END:
      55           0 :       case DATA_ESCAPE: *t++ = DATA_ESCAPE; continue;
      56             : 
      57             :       case '\\':
      58           0 :       case '"': *t++ = '\\'; continue;
      59             :     }
      60           0 :   *t++ = '"';
      61           0 :   *t = '\0'; puts(t0); pari_free(t0);
      62           0 : }
      63             : 
      64             : /* completion required, cursor on s + pos. Complete wrt strict left prefix */
      65             : static void
      66           0 : tm_completion(const char *s, long pos)
      67             : {
      68             :   char **matches, *text;
      69             : 
      70           0 :   if (rl_line_buffer) pari_free(rl_line_buffer);
      71           0 :   rl_line_buffer = pari_strdup(s);
      72           0 :   text = pari_completion_word(&pari_rl, pos);
      73             :   /* text = start of expression we complete */
      74           0 :   rl_end = strlen(s)-1;
      75           0 :   rl_point = pos;
      76           0 :   matches = pari_completion(&pari_rl, text, text - rl_line_buffer, pos);
      77           0 :   printf("%cscheme:(tuple",DATA_BEGIN);
      78           0 :   if (matches)
      79             :   {
      80           0 :     long i, prelen = (rl_line_buffer+pos) - text;
      81           0 :     char *t = (char*)pari_malloc(prelen+1);
      82           0 :     strncpy(t, text, prelen); t[prelen] = 0; /* prefix */
      83           0 :     printf(" ");
      84           0 :     print_escape_string(t); pari_free(t);
      85           0 :     for (i = matches[1]? 1: 0; matches[i]; i++)
      86             :     {
      87           0 :       printf(" ");
      88           0 :       print_escape_string(matches[i] + prelen);
      89           0 :       pari_free(matches[i]);
      90             :     }
      91           0 :     pari_free(matches);
      92             :   }
      93           0 :   printf(")%c", DATA_END);
      94           0 :   fflush(stdout);
      95           0 : }
      96             : #else
      97             : /* no-op */
      98             : static void
      99             : tm_completion(const char *s, long pos) { (void)s; (void)pos; }
     100             : #endif
     101             : 
     102             : typedef struct {
     103             :   char *cmd;
     104             :   long n; /* number of args */
     105             :   char **v; /* args */
     106             : } tm_cmd;
     107             : 
     108             : static void
     109           0 : tm_parse_command(tm_cmd *c, const char *ch)
     110             : {
     111           0 :   long l = strlen(ch);
     112           0 :   char *t, *s = (char*)ch, *send = s+l-1;
     113             :   char **A;
     114             :   pari_stack s_A;
     115             : 
     116           0 :   if (*s != DATA_BEGIN || *send-- != DATA_END)
     117           0 :     pari_err(e_MISC, "missing DATA_[BEGIN | END] in TeXmacs command");
     118           0 :   s++;
     119           0 :   if (strncmp(s, "special:", 8)) pari_err(e_MISC, "unrecognized TeXmacs command");
     120           0 :   s += 8;
     121           0 :   if (*s != '(' || *send-- != ')')
     122           0 :     pari_err(e_MISC, "missing enclosing parentheses for TeXmacs command");
     123           0 :   s++; t = s;
     124           0 :   pari_skip_alpha(&s);
     125           0 :   c->cmd = pari_strndup(t, s - t);
     126           0 :   pari_stack_init(&s_A,sizeof(*A),(void**)&A);
     127           0 :   for (c->n = 0; s <= send; c->n++)
     128             :   {
     129           0 :     char *u = (char*)pari_malloc(strlen(s) + 1);
     130           0 :     pari_skip_space(&s);
     131           0 :     if (*s == '"') s = pari_translate_string(s, u, t);
     132             :     else
     133             :     { /* read integer */
     134           0 :       t = s;
     135           0 :       while (isdigit((int)*s)) s++;
     136           0 :       strncpy(u, t, s - t); u[s-t] = 0;
     137             :     }
     138           0 :     pari_stack_pushp(&s_A, u);
     139             :   }
     140           0 :   c->v = A;
     141           0 : }
     142             : 
     143             : static void
     144           0 : tm_free_cmd(tm_cmd *c)
     145             : {
     146           0 :   while (c->n--) pari_free((void*)c->v[c->n]);
     147           0 :   pari_free((void*)c->v);
     148           0 : }
     149             : 
     150             : static void
     151           0 : tm_handle_command(const char *s)
     152             : {
     153             :   tm_cmd c;
     154           0 :   tm_parse_command(&c, s);
     155           0 :   if (strcmp(c.cmd, "complete"))
     156           0 :     pari_err(e_MISC,"Texmacs command %s not implemented", c.cmd);
     157           0 :   if (c.n != 2)
     158           0 :     pari_err(e_MISC,"was expecting 2 arguments for Texmacs command");
     159           0 :   tm_completion(c.v[0], atol(c.v[1]));
     160           0 :   tm_free_cmd(&c);
     161           0 :   did_complete = 1;
     162           0 : }
     163             : 
     164             : /****/
     165             : 
     166             : int
     167           0 : tm_is_interactive(void) { return 0; }
     168             : 
     169             : static int tm_is_waiting = 0;
     170             : /* tell TeXmacs GP will start outputing data */
     171             : void
     172           0 : tm_start_output(void)
     173             : {
     174           0 :   if (!tm_is_waiting) { printf("%cverbatim:",DATA_BEGIN); fflush(stdout); }
     175           0 :   tm_is_waiting = 1;
     176           0 : }
     177             : /* tell TeXmacs GP is done and is waiting for new data */
     178             : void
     179           0 : tm_end_output(void)
     180             : {
     181           0 :   if (tm_is_waiting) { printf("%c", DATA_END); fflush(stdout); }
     182           0 :   tm_is_waiting = 0;
     183           0 : }
     184             : char *
     185           0 : tm_fgets(char *s, int n, FILE *f)
     186             : {
     187           0 :   if (!did_complete)
     188             :   { /* we need input */
     189           0 :     tm_start_output();
     190           0 :     tm_end_output();
     191             :   }
     192           0 :   return fgets(s,n,f);
     193             : }
     194             : 
     195             : int
     196           0 : tm_get_line(const char *prompt, const char *prompt_cont, filtre_t *F)
     197             : {
     198           0 :   int res = get_line_from_file(prompt, F, pari_infile);
     199             :   (void)prompt_cont;
     200           0 :   if (res)
     201             :   {
     202           0 :     char *s = F->buf->buf;
     203           0 :     did_complete = 0;
     204           0 :     if (pari_infile == stdin && *s == DATA_BEGIN)
     205           0 :     { tm_handle_command(s); *s = 0; }
     206             :     else
     207           0 :       tm_start_output();
     208             :   }
     209           0 :   return res;
     210             : }
     211             : 
     212             : void
     213           0 : tm_output(GEN z)
     214             : {
     215           0 :   char *sz = GENtoTeXstr(z);
     216           0 :   printf("%clatex:", DATA_BEGIN);
     217           0 :   printf("\\magenta\\%%%lu = ", GP_DATA->hist->total);
     218           0 :   printf("$\\blue %s$%c", sz,DATA_END);
     219           0 :   pari_free(sz); fflush(stdout);
     220           0 :   pari_flush();
     221           0 : }
     222             : 
     223             : void
     224           0 : init_texmacs(void)
     225             : {
     226             : #ifdef READLINE
     227           0 :   printf("%ccommand:(cas-supports-completions-set! \"pari\")%c\n",
     228             :          DATA_BEGIN, DATA_END);
     229           0 :   pari_use_readline(pari_rl);
     230             : #endif
     231           0 :   cb_pari_fgets_interactive = tm_fgets;
     232           0 :   cb_pari_get_line_interactive = tm_get_line;
     233             : 
     234           0 :   cb_pari_start_output = tm_start_output;
     235           0 :   cb_pari_end_output = tm_end_output;
     236           0 :   cb_pari_is_interactive = tm_is_interactive;
     237           0 :   cb_gp_output = tm_output;
     238           0 :   disable_color = 1;
     239           0 :   tm_start_output();
     240           0 : }

Generated by: LCOV version 1.11