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.12.0 lcov report (development 22872-edcf83abb) Lines: 0 110 0.0 %
Date: 2018-07-20 05:36:03 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             :   long w;
      70             : 
      71           0 :   matches = pari_completion_matches(&pari_rl, s, pos, &w);
      72           0 :   text = *pari_rl.line_buffer + w;
      73           0 :   printf("%cscheme:(tuple",DATA_BEGIN);
      74           0 :   if (matches)
      75             :   {
      76           0 :     long i, prelen = (rl_line_buffer+pos) - text;
      77           0 :     char *t = (char*)pari_malloc(prelen+1);
      78           0 :     strncpy(t, text, prelen); t[prelen] = 0; /* prefix */
      79           0 :     printf(" ");
      80           0 :     print_escape_string(t); pari_free(t);
      81           0 :     for (i = matches[1]? 1: 0; matches[i]; i++)
      82             :     {
      83           0 :       printf(" ");
      84           0 :       print_escape_string(matches[i] + prelen);
      85           0 :       pari_free(matches[i]);
      86             :     }
      87           0 :     pari_free(matches);
      88             :   }
      89           0 :   printf(")%c", DATA_END);
      90           0 :   fflush(stdout);
      91           0 : }
      92             : #else
      93             : /* no-op */
      94             : static void
      95             : tm_completion(const char *s, long pos) { (void)s; (void)pos; }
      96             : #endif
      97             : 
      98             : typedef struct {
      99             :   char *cmd;
     100             :   long n; /* number of args */
     101             :   char **v; /* args */
     102             : } tm_cmd;
     103             : 
     104             : static void
     105           0 : tm_parse_command(tm_cmd *c, const char *ch)
     106             : {
     107           0 :   long l = strlen(ch);
     108           0 :   char *t, *s = (char*)ch, *send = s+l-1;
     109             :   char **A;
     110             :   pari_stack s_A;
     111             : 
     112           0 :   if (*s != DATA_BEGIN || *send-- != DATA_END)
     113           0 :     pari_err(e_MISC, "missing DATA_[BEGIN | END] in TeXmacs command");
     114           0 :   s++;
     115           0 :   if (strncmp(s, "special:", 8)) pari_err(e_MISC, "unrecognized TeXmacs command");
     116           0 :   s += 8;
     117           0 :   if (*s != '(' || *send-- != ')')
     118           0 :     pari_err(e_MISC, "missing enclosing parentheses for TeXmacs command");
     119           0 :   s++; t = s;
     120           0 :   pari_skip_alpha(&s);
     121           0 :   c->cmd = pari_strndup(t, s - t);
     122           0 :   pari_stack_init(&s_A,sizeof(*A),(void**)&A);
     123           0 :   for (c->n = 0; s <= send; c->n++)
     124             :   {
     125           0 :     char *u = (char*)pari_malloc(strlen(s) + 1);
     126           0 :     pari_skip_space(&s);
     127           0 :     if (*s == '"') s = pari_translate_string(s, u, t);
     128             :     else
     129             :     { /* read integer */
     130           0 :       t = s;
     131           0 :       while (isdigit((int)*s)) s++;
     132           0 :       strncpy(u, t, s - t); u[s-t] = 0;
     133             :     }
     134           0 :     pari_stack_pushp(&s_A, u);
     135             :   }
     136           0 :   c->v = A;
     137           0 : }
     138             : 
     139             : static void
     140           0 : tm_free_cmd(tm_cmd *c)
     141             : {
     142           0 :   while (c->n--) pari_free((void*)c->v[c->n]);
     143           0 :   pari_free((void*)c->v);
     144           0 : }
     145             : 
     146             : static void
     147           0 : tm_handle_command(const char *s)
     148             : {
     149             :   tm_cmd c;
     150           0 :   tm_parse_command(&c, s);
     151           0 :   if (strcmp(c.cmd, "complete"))
     152           0 :     pari_err(e_MISC,"Texmacs command %s not implemented", c.cmd);
     153           0 :   if (c.n != 2)
     154           0 :     pari_err(e_MISC,"was expecting 2 arguments for Texmacs command");
     155           0 :   tm_completion(c.v[0], atol(c.v[1]));
     156           0 :   tm_free_cmd(&c);
     157           0 :   did_complete = 1;
     158           0 : }
     159             : 
     160             : /****/
     161             : 
     162             : int
     163           0 : tm_is_interactive(void) { return 0; }
     164             : 
     165             : static int tm_is_waiting = 0;
     166             : /* tell TeXmacs GP will start outputing data */
     167             : void
     168           0 : tm_start_output(void)
     169             : {
     170           0 :   if (!tm_is_waiting) { printf("%cverbatim:",DATA_BEGIN); fflush(stdout); }
     171           0 :   tm_is_waiting = 1;
     172           0 : }
     173             : /* tell TeXmacs GP is done and is waiting for new data */
     174             : void
     175           0 : tm_end_output(void)
     176             : {
     177           0 :   if (tm_is_waiting) { printf("%c", DATA_END); fflush(stdout); }
     178           0 :   tm_is_waiting = 0;
     179           0 : }
     180             : char *
     181           0 : tm_fgets(char *s, int n, FILE *f)
     182             : {
     183           0 :   if (!did_complete)
     184             :   { /* we need input */
     185           0 :     tm_start_output();
     186           0 :     tm_end_output();
     187             :   }
     188           0 :   return fgets(s,n,f);
     189             : }
     190             : 
     191             : int
     192           0 : tm_get_line(const char *prompt, const char *prompt_cont, filtre_t *F)
     193             : {
     194           0 :   int res = get_line_from_file(prompt, F, pari_infile);
     195             :   (void)prompt_cont;
     196           0 :   if (res)
     197             :   {
     198           0 :     char *s = F->buf->buf;
     199           0 :     did_complete = 0;
     200           0 :     if (pari_infile == stdin && *s == DATA_BEGIN)
     201           0 :     { tm_handle_command(s); *s = 0; }
     202             :     else
     203           0 :       tm_start_output();
     204             :   }
     205           0 :   return res;
     206             : }
     207             : 
     208             : void
     209           0 : tm_output(GEN z)
     210             : {
     211           0 :   char *sz = GENtoTeXstr(z);
     212           0 :   printf("%clatex:", DATA_BEGIN);
     213           0 :   printf("\\magenta\\%%%lu = ", GP_DATA->hist->total);
     214           0 :   printf("$\\blue %s$%c", sz,DATA_END);
     215           0 :   pari_free(sz); fflush(stdout);
     216           0 :   pari_flush();
     217           0 : }
     218             : 
     219             : void
     220           0 : init_texmacs(void)
     221             : {
     222             : #ifdef READLINE
     223           0 :   printf("%ccommand:(cas-supports-completions-set! \"pari\")%c\n",
     224             :          DATA_BEGIN, DATA_END);
     225           0 :   pari_use_readline(pari_rl);
     226             : #endif
     227           0 :   cb_pari_fgets_interactive = tm_fgets;
     228           0 :   cb_pari_get_line_interactive = tm_get_line;
     229             : 
     230           0 :   cb_pari_start_output = tm_start_output;
     231           0 :   cb_pari_end_output = tm_end_output;
     232           0 :   cb_pari_is_interactive = tm_is_interactive;
     233           0 :   cb_gp_output = tm_output;
     234           0 :   disable_color = 1;
     235           0 :   tm_start_output();
     236           0 : }

Generated by: LCOV version 1.13