Exemple #1
0
func TestFrmt(t *testing.T) {
	app.New() // prevent app.Fatal from calling dbg.Fatal
	//app.Debug = testing.Verbose()
	// gf
	pipe := make(chan interface{}, 2)
	pipe <- zx.Dir{"upath": "foo", "path": "foo"}
	pipe <- []byte(testpar)
	close(pipe)
	out := make(chan interface{})
	/*
		go func() {
			c := app.New()
			defer app.Exiting()
			c.Args = []string {"gf", "frmt,"}
			app.DupIO()
			app.SetIO(pipe, 1)
			app.Cd("/zx/sys/src/clive/app")
			lf.Run()
		}()
	*/

	// frmt
	go func() {
		c := app.New()
		//c.Debug = testing.Verbose()
		defer app.Exiting()
		c.Args = []string{"frmt", "-w", "50", "-r"}
		app.DupIO()
		app.SetIO(pipe, 0)
		app.SetIO(out, 1)
		app.Cd("/zx/sys/src/clive/app")
		Run()
	}()
	outs := ""
	for x := range out {
		switch x := x.(type) {
		case zx.Dir:
			dprintf("xgot %T %s\n", x, x["upath"])
		case []byte:
			if len(x) > 0 {
				x = x[:len(x)-1]
			}
			dprintf("[%s]\n", x)
			outs += string(x) + "\n"
		case error:
			dprintf("xgot %T %v\n", x, x)
		default:
			dprintf("xgot %T %v\n", x, x)
		}
	}
	dprintf("outs = `%s`\n", outs)
	err := cerror(out)
	dprintf("got sts %v\n", err)
	if outs != testout {
		t.Fatalf("bad output")
	}
}
Exemple #2
0
func TestLf(t *testing.T) {
	app.New()	// prevent app.Fatal from calling dbg.Fatal
	app.Debug = testing.Verbose()
	for i := range tests {
		lt := tests[i]
		dprintf("run %v\n", lt.args)
		out := make(chan interface{})
		go func() {
			c := app.New()
			c.Args = lt.args
			defer app.Exiting()
			app.DupIO()
			app.SetIO(out, 1)
			app.Cd("/zx/sys/src/clive")
			Run()
		}()
		outs := []string{}
		for x := range out {
			d, ok := x.(zx.Dir)
			if !ok {
				dprintf("got %T %v\n", x, x)
				t.Fatalf("not a dir")
			}
			dprintf("got %T %s\n", d, d["upath"])
			outs = append(outs, d["upath"])
		}
		err := cerror(out)
		dprintf("got sts %v\n", err)
		if lt.fails && err == nil {
			t.Fatalf("didn't fail")
		}
		if !lt.fails && err != nil {
			t.Fatalf("failed: %s", err)
		}
		if lt.out != nil && strings.Join(lt.out, " ") != strings.Join(outs, " ") {
			t.Fatalf("bad output %#v", outs)
		}
		if lt.out == nil {
			dprintf("out: %#v\n", outs)
		}
	}
}
Exemple #3
0
// runs here
func runDup(x *xEnv, argv ...string) error {
	opts := opt.New("dup")
	app.Dprintf("dup %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		return dbg.ErrUsage
	}
	for _, arg := range args {
		switch arg {
		case "ns":
			app.DupNS()
		case "io":
			app.DupIO()
		case "env":
			app.DupEnv()
		case "dot":
			app.DupDot()
		default:
			app.Warn("unknown resource '%s'", arg)
		}
	}
	return nil
}
Exemple #4
0
func TestLg(t *testing.T) {
	app.New()	// prevent app.Fatal from calling dbg.Fatal
	app.Debug = testing.Verbose()
	for i := range gets {
		lt := gets[i]
		dprintf("run %v\n", lt.args)
		out := make(chan interface{})
		go func() {
			c := app.New()
			defer app.Exiting()
			app.DupIO()
			app.SetIO(out, 1)
			app.Cd("/zx/sys/src/clive")
			c.Args = lt.args
			Run()
		}()
		outs := []string{}
		nbytes := 0
		for x := range out {
			switch x := x.(type) {
			case zx.Dir:
				if nbytes > 0 {
					outs = append(outs, "[]")
				}
				nbytes = 0
				dprintf("got %T %s\n", x, x["upath"])
				outs = append(outs, x["upath"])
			case []byte:
				nbytes += len(x)
				dprintf("got %T [%d]\n", x, len(x))
			case error:
				if nbytes > 0 {
					outs = append(outs, "[]")
				}
				nbytes = 0
				dprintf("got %T %v\n", x, x)
				outs = append(outs, "err")
			default:
				dprintf("got %T %v\n", x, x)
				t.Fatalf("unexpected type %T", x)
			}
		}
		if nbytes >0 {
			outs = append(outs, "[]")
		}
		err := cerror(out)
		dprintf("got sts %v\n", err)
		if lt.fails && err == nil {
			t.Fatalf("didn't fail")
		}
		if !lt.fails && err != nil {
			t.Fatalf("failed: %s", err)
		}
		if lt.out != nil && strings.Join(lt.out, " ") != strings.Join(outs, " ") {
			t.Fatalf("bad output %#v", outs)
		}
		if lt.out == nil {
			dprintf("out: %#v\n", outs)
		}
	}
}