asdf

Форк
0
/
asdf_elvish.bats 
123 строки · 2.8 Кб
1
#!/usr/bin/env bats
2
# shellcheck disable=SC2030,SC2031
3

4
load test_helpers
5

6
setup() {
7
  export XDG_CONFIG_HOME=
8
  export XDG_DATA_HOME=
9
  export XDG_DATA_DIRS=
10

11
  if ! command -v elvish &>/dev/null && [ -z "$GITHUB_ACTIONS" ]; then
12
    skip 'Elvish not installed'
13
  fi
14

15
  local ver_major=
16
  local ver_minor=
17
  local ver_patch=
18
  IFS='.' read -r ver_major ver_minor ver_patch <<<"$(elvish -version)"
19

20
  if ((ver_major == 0 && ver_minor < 18)) && [ -z "$GITHUB_ACTIONS" ]; then
21
    skip "Elvish version is not at least 0.18. Found ${ver_major}.${ver_minor}.${ver_patch}"
22
  fi
23
}
24

25
cleaned_path() {
26
  echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ' '
27
}
28

29
@test "exports ASDF_DIR" {
30
  run elvish -norc -c "
31
    unset-env ASDF_DIR
32
    set paths = [$(cleaned_path)]
33
    use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
34
    echo \$E:ASDF_DIR"
35

36
  [ "$status" -eq 0 ]
37
  [ "$output" = "$HOME/.asdf" ]
38
}
39

40
@test "retains ASDF_DIR" {
41
  run elvish -norc -c "
42
    set-env ASDF_DIR \"/path/to/asdf\"
43
    set paths = [$(cleaned_path)]
44
    use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
45
    echo \$E:ASDF_DIR"
46

47
  [ "$status" -eq 0 ]
48
  [ "$output" = "/path/to/asdf" ]
49
}
50

51
@test "retains ASDF_DATA_DIR" {
52
  run elvish -norc -c "
53
    set-env ASDF_DATA_DIR \"/path/to/asdf-data\"
54
    set paths = [$(cleaned_path)]
55
    use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
56
    echo \$E:ASDF_DATA_DIR"
57

58
  [ "$status" -eq 0 ]
59
  [ "$output" = "/path/to/asdf-data" ]
60
}
61

62
@test "adds asdf dirs to PATH" {
63
  run elvish -norc -c "
64
    unset-env ASDF_DIR
65
    set paths = [$(cleaned_path)]
66
    use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
67
    echo \$E:PATH"
68

69
  [ "$status" -eq 0 ]
70

71
  result=$(echo "$output" | grep "asdf")
72
  [ "$result" != "" ]
73
}
74

75
@test "defines the _asdf namespace" {
76
  run elvish -norc -c "
77
    unset-env ASDF_DIR
78
    set paths = [$(cleaned_path)]
79
    use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
80
    pprint \$_asdf:"
81

82
  [ "$status" -eq 0 ]
83
  [[ "$output" =~ "<ns " ]]
84
}
85

86
@test "does not add paths to PATH more than once" {
87
  run elvish -norc -c "
88
    unset-env ASDF_DIR
89
    set paths = [$(cleaned_path)]
90

91
    use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
92
    use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
93
    echo \$E:PATH"
94

95
  [ "$status" -eq 0 ]
96

97
  result=$(echo "$result" | tr ':' '\n' | grep "asdf" | sort | uniq -d)
98
  [ "$result" = "" ]
99
}
100

101
@test "defines the asdf function" {
102
  run elvish -norc -c "
103
    unset-env ASDF_DIR
104
    set paths = [$(cleaned_path)]
105
    use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
106
    pprint \$asdf~"
107

108
  [ "$status" -eq 0 ]
109
  [[ "$output" =~ "<closure " ]]
110
}
111

112
@test "function calls asdf command" {
113
  run elvish -norc -c "
114
    set-env ASDF_DIR $(pwd) # checkstyle-ignore
115
    set paths = [$(cleaned_path)]
116
    use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
117
    asdf info"
118

119
  [ "$status" -eq 0 ]
120

121
  result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
122
  [ "$result" != "" ]
123
}
124

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

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

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

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