ALR

Форк
1
58 строк · 1.5 Кб
1
/*
2
 * ALR - Any Linux Repository
3
 * Copyright (C) 2024 Евгений Храмов
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

19
package handlers_test
20

21
import (
22
	"bytes"
23
	"context"
24
	"os"
25
	"strings"
26
	"testing"
27

28
	"plemya-x.ru/alr/internal/shutils/handlers"
29
	"mvdan.cc/sh/v3/interp"
30
	"mvdan.cc/sh/v3/syntax"
31
)
32

33
func TestNopExec(t *testing.T) {
34
	ctx := context.Background()
35

36
	fl, err := syntax.NewParser().Parse(strings.NewReader(`/bin/echo test`), "alr.sh")
37
	if err != nil {
38
		t.Fatalf("Expected no error, got %s", err)
39
	}
40

41
	buf := &bytes.Buffer{}
42
	runner, err := interp.New(
43
		interp.ExecHandler(handlers.NopExec),
44
		interp.StdIO(os.Stdin, buf, buf),
45
	)
46
	if err != nil {
47
		t.Fatalf("Expected no error, got %s", err)
48
	}
49

50
	err = runner.Run(ctx, fl)
51
	if err != nil {
52
		t.Fatalf("Expected no error, got %s", err)
53
	}
54

55
	if buf.String() != "" {
56
		t.Fatalf("Expected empty string, got %#v", buf.String())
57
	}
58
}
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.