Debian Codegraph @

cmd/txtar-x/extract_test.go

raw symbols SCIP
1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package main
6
7 import (
8 "bytes"
9 "os"
10 "testing"
11
12 "github.com/rogpeppe/go-internal/testscript"
13 )
14
15 func TestMain(m *testing.M) {
16 testscript.Main(m, map[string]func(){
17 "txtar-x": main,
18 })
19 }
20
21 func TestScripts(t *testing.T) {
22 testscript.Run(t, testscript.Params{
23 Dir: "testdata",
24 Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){
25 "unquote": unquote,
26 },
27 })
28 }
29
30 func unquote(ts *testscript.TestScript, neg bool, args []string) {
31 if neg {
32 ts.Fatalf("unsupported: ! unquote")
33 }
34 for _, arg := range args {
35 file := ts.MkAbs(arg)
36 data, err := os.ReadFile(file)
37 ts.Check(err)
38 data = bytes.Replace(data, []byte("\n>"), []byte("\n"), -1)
39 data = bytes.TrimPrefix(data, []byte(">"))
40 err = os.WriteFile(file, data, 0o666)
41 ts.Check(err)
42 }
43 }