main.mx raw

   1  // mxcover turns a -cover run into a coverage report.
   2  //
   3  // Usage:
   4  //
   5  //	mxcover <sites.json> <counts> [path-prefix]
   6  //
   7  // sites.json is the <output>.cover_sites.json the compiler writes beside a
   8  // -cover build; counts is the file the instrumented program dumped into
   9  // (MOXIE_COVER_OUT), whose lines look like "coversite 12 count=3". An optional
  10  // path prefix limits the report to files under it, which is how a relay build
  11  // reports on its own tree while the runtime and stdlib are compiled in too.
  12  //
  13  // The join itself lives in pkg/mxcover, so `moxie test -cover` can print the
  14  // same report for the package it just ran without shelling out to this tool.
  15  package main
  16  
  17  import (
  18  	"fmt"
  19  	"os"
  20  
  21  	"git.smesh.lol/moxie/pkg/mxcover"
  22  )
  23  
  24  func main() {
  25  	args := os.Args
  26  	if len(args) < 3 {
  27  		fmt.Println("usage: mxcover <sites.json> <counts> [path-prefix]")
  28  		os.Exit(2)
  29  	}
  30  	prefix := ""
  31  	if len(args) > 3 {
  32  		prefix = args[3]
  33  	}
  34  	out, errText := mxcover.Report(args[1], args[2], prefix)
  35  	if errText != "" {
  36  		fmt.Println("mxcover: " | errText)
  37  		os.Exit(1)
  38  	}
  39  	fmt.Print(out)
  40  }
  41