Browse Source

Add command to list imported modules

Alois Mahdal 6 years ago
parent
commit
480e8e666d

+ 6
- 0
src/shellfu.sh.skel View File

@@ -196,6 +196,12 @@ shellfu() {
196 196
             shellfu __debug "found module file: $mpath"
197 197
             shellfu _read_directive "module-version" "$mpath"
198 198
             ;;
199
+        ls_imported)
200
+            #
201
+            # Print list of modules already imported
202
+            #
203
+            echo "$__SHELLFU_IMPORTED" | tr : \\n
204
+            ;;
199 205
 
200 206
         _do_import)
201 207
             #

+ 15
- 1
tests/shellfu_import/TF_RUN View File

@@ -11,6 +11,7 @@ tf_enum_subtests() {
11 11
     echo "try_import_var_fn"
12 12
     echo "import_var_fn_bash"
13 13
     echo "import_var_fn_bash_hint"
14
+    echo "ls_imported"
14 15
 }
15 16
 
16 17
 ignored() {
@@ -51,6 +52,7 @@ mksnippet() {
51 52
     # File _ignored_ is used as list of tokens to always
52 53
     # remove from the info.
53 54
     #
55
+    test "$name" == ls_imported && return 0
54 56
     local target="$1"
55 57
     printf "
56 58
         {
@@ -88,6 +90,11 @@ mktscript_body() {
88 90
         try_import_fn) echo 'shellfu try_import mod_f'          ;;
89 91
         try_import_var) echo 'shellfu try_import mod_v'         ;;
90 92
         try_import_var_fn) echo 'shellfu try_import mod_v_f'    ;;
93
+        ls_imported) echo 'shellfu import mod_v_f'
94
+                     echo 'shellfu try_import mod_v_f_bash'
95
+                     echo 'shellfu import mod_v'
96
+                     echo 'shellfu import mod_v_f'
97
+                     echo 'shellfu ls_imported'                 ;;
91 98
     esac
92 99
 }
93 100
 
@@ -119,9 +126,16 @@ tf_do_subtest() {
119 126
     #
120 127
     local name="$1"
121 128
     mktscript "$name" > "$name.sh"
129
+
122 130
     mkdir -p result
123 131
     chmod +x "$name.sh"
124
-    env -i PATH="$PATH" SHELLFU_DIR="$SHELLFU_DIR" ./"$name.sh"
132
+    env -i PATH="$PATH" SHELLFU_DIR="$SHELLFU_DIR" ./"$name.sh" \
133
+        >"result/$name.out" 2>"result/$name.err"
134
+    test "$name" == ls_imported && {
135
+        diff -u "oracle/$name.out" "result/$name.out" || return 1
136
+        diff -u "oracle/$name.err" "result/$name.err" || return 1
137
+        return 0
138
+    }
125 139
     comm -13 "$name.before" "$name.after" > "result/$name.new"
126 140
     # i.e. lines introduced by import ^^
127 141
     diff -u "oracle/$name.new" "result/$name.new"

+ 1
- 0
tests/shellfu_import/oracle/ls_imported.err View File

@@ -0,0 +1 @@
1
+shellfu: cannot find module: mod_v_f_bash

+ 2
- 0
tests/shellfu_import/oracle/ls_imported.out View File

@@ -0,0 +1,2 @@
1
+mod_v_f
2
+mod_v