示例#1
0
func TestCmds(t *testing.T) {
	os.Args[0] = "ql.test"
	app.Debug = testing.Verbose() && false
	app.Verb = testing.Verbose() && false
	app.New()
	app.AppCtx().Debug = testing.Verbose()
	dbg.ExitDumpsStacks = testing.Verbose()
	defer app.Exiting()
	inc := make(chan interface{}, 3)
	inc <- []byte("hi\n")
	inc <- []byte("there\n")
	close(inc)
	app.SetIO(inc, 0)
	ql := func() {
		app.AppCtx().Debug = testing.Verbose()
		Run()
	}
	for _, c := range cmds {
		args := []string{"ql", "-c", c}
		if testing.Verbose() {
			args = []string{"ql", "-X", "-c", c}
		}
		x := app.Go(ql, args...)
		<-x.Wait
		if x.Sts != nil {
			t.Logf("did fail with sts %v", x.Sts)
		}
	}
}
示例#2
0
func TestParseStdin(t *testing.T) {
	r, w, err := os.Pipe()
	if err != nil {
		t.Fatalf("pipe: %s", err)
	}
	fd, err := os.Open("example")
	if err != nil {
		t.Fatalf("ex: %s", err)
	}
	defer fd.Close()
	go func() {
		io.Copy(w, fd)
		w.Close()
	}()
	os.Stdin = r
	app.New()
	defer app.Exiting()
	ql := func() {
		c := app.AppCtx()
		c.Debug = testing.Verbose()
		app.SetIO(app.OSIn(), 0)
		Run()
	}
	x := app.Go(ql, "ql", "-n")
	<-x.Wait
	if x.Sts != nil {
		t.Fatalf("did fail")
	}
}
示例#3
0
func (t *Text) refer(el *Elem) {
	if t.bib == nil && t.biberr == nil {
		c := app.AppCtx()
		old := c.Debug
		c.Debug = false
		t.bib, t.biberr = refs.Load(t.refsdir)
		c.Debug = old
		if t.biberr != nil {
			el.Warn("bib: %s: %s\n", refs.Dir, t.biberr)
		}
	}
	nbs := []string{}
	for _, b := range strings.Split(el.Data, ",") {
		b = strings.TrimSpace(b)
		if len(b) == 0 {
			continue
		}
		brefs := t.bib.Cites(strings.Fields(b)...)
		bs := []string{b}
		if len(brefs) == 0 {
			el.Warn("bib '%s' not found", b)
		} else {
			bref := brefs[0]
			bs = bref.Reference()
			if len(brefs) > 1 {
				el.Warn("%d refs for '%s'; using '%s'", len(brefs), b, bs[0])
			}
		}
		nb := t.addRefer(bs)
		nbs = append(nbs, strconv.Itoa(nb))
	}
	el.Data = strings.Join(nbs, ",")
}
示例#4
0
// runs here
func runFlag(x *xEnv, argv ...string) error {
	c := app.AppCtx()
	app.Dprintf("flag %v\n", argv)
	switch len(argv) {
	case 1:
		flgs := ""
		if c.Debug {
			flgs += "D"
		}
		if x.debugX {
			flgs += "X"
		}
		if x.debugL {
			flgs += "L"
		}
		if x.iflag {
			flgs += "i"
		}
		app.Printf("flags %s\n", flgs)
		return nil
	case 2:
	default:
		app.Eprintf("usage: flags [±]flags\n")
		return dbg.ErrUsage
	}
	flg := argv[1]
	set := flg[0] == '+'
	clear := flg[0] != '-'
	if !set && !clear {
		// clear all flags
		c.Debug = false
		x.debugX = false
		x.debugL = false
		// then set those named
		set = true
	} else {
		flg = flg[1:]
	}
	for _, r := range flg {
		switch r {
		case 'D':
			c.Debug = (c.Debug && !clear) || set
		case 'X':
			x.debugX = (x.debugX && !clear) || set
		case 'L':
			x.debugL = (x.debugL && !clear) || set
		case 'i':
			app.Warn("'-i' cannot be changed")
		default:
			app.Warn("unknown flag '%c'", r)
		}
	}
	return nil
}
示例#5
0
func TestParseCmd(t *testing.T) {
	app.New()
	defer app.Exiting()
	ql := func() {
		app.AppCtx().Debug = testing.Verbose()
		Run()
	}
	x := app.Go(ql, "ql", "-n", "-c", "pwd")
	<-x.Wait
	if x.Sts != nil {
		t.Fatalf("did fail")
	}
}
示例#6
0
func TestParseError(t *testing.T) {
	app.New()
	defer app.Exiting()
	ql := func() {
		app.AppCtx().Debug = testing.Verbose()
		Run()
	}
	x := app.Go(ql, "ql", "-n", "-c", "pw{d")
	<-x.Wait
	if x.Sts == nil {
		t.Logf("warn: ql didn't fail")
	}
}