Skip to content

Commit 4af747f

Browse files
authored
Fix package path logic in generated stanza.proj (#105)
* - remove buggy and confusing `first` function - remove buggy `dir-name?` function - use `base-name?` for package directory detection - add test cases for `base-name?` function * - include deletion of first - fix nth
1 parent 6a4f2dd commit 4af747f

7 files changed

+25
-12
lines changed

src/commands/init.stanza

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public defn init (cmd-args:CommandArgs) -> False:
6464
val minimal? = flag?(cmd-args, "minimal")
6565
val project-dir = get-proj-dir(cmd-args)
6666

67-
val project-name = dir-name?(project-dir)
67+
val project-name = base-name?(project-dir)
6868
$> value-or{_, project-dir}
6969

7070
val slm-toml-path = path-join(project-dir, SLM_TOML_NAME)

src/file-utils.stanza

-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ lostanza defn int-get-cwd () -> ref<String>:
4545
public defn get-cwd () -> String :
4646
un-norm-path $ int-get-cwd()
4747

48-
public defn dir-name? (path: String) -> Maybe<String>:
49-
split-last(path, '/') $> map{_, first}
50-
5148
public defn base-name? (path: String) -> Maybe<String>:
5249
path
5350
$> entries{parse-path(_)}

src/utils.stanza

+1-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public defn pairs<?K, ?V> (s: Seqable<KeyValue<?K, ?V>>) -> Seq<[K, V]>:
2929
s $> to-seq $> seq{fn (kv): [key(kv), value(kv)], _}
3030

3131
public defn nth?<?T> (c: IndexedCollection<?T>, n: Int) -> Maybe<T>:
32-
if n < length(c):
32+
if n < length(c) and n >= 0:
3333
One(get(c, n))
3434
else:
3535
None()
@@ -41,9 +41,6 @@ public defn last?<?T> (c: Seqable<?T>) -> Maybe<T>:
4141
else:
4242
loop(s, One(next(s)))
4343

44-
public defn first<?T> (t: Tuple<?T>) -> T:
45-
t[1]
46-
4744
defn ssh-locator (locator: String) -> String :
4845
to-string("[email protected]:%_" % [locator])
4946
defn https-locator (locator: String) -> String :

stanza.proj

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ build-test tests:
2727
slm/tests/commands/remove
2828
slm/tests/conan-utils
2929
slm/tests/process-utils
30+
slm/tests/file-utils
3031
pkg: "test-pkgs"
3132
o: "slm-tests"
3233

tests/file-utils.stanza

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#use-added-syntax(tests)
2+
defpackage slm/tests/file-utils:
3+
import core
4+
import slm/file-utils
5+
6+
deftest(file-utils) test-basename:
7+
8+
val test-cases = [
9+
"C:\\Users\\Bad Name with spaces/my_dir"
10+
"C:\\Users\\Bad Name with spaces\\my_dir"
11+
"C:\\Users\\Bad Name with spaces/my_dir/"
12+
"C:\\Users\\Bad Name with spaces/my_dir\\"
13+
]
14+
15+
for tc in test-cases do :
16+
#EXPECT(base-name?(tc) == One("my_dir"))

tests/libgit2.stanza

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ deftest(libgit2) test-error-last :
2424

2525
deftest(libgit2 online) test-clone :
2626
libgit2_init()
27-
val r:git_error_code|GIT_REPOSITORY = libgit2_clone("https://github.com/StanzaOrg/stanza-toml.git", "./foo")
27+
val foo-folder = to-string("./foo-%_" % [current-time-ms()])
28+
val r:git_error_code|GIT_REPOSITORY = libgit2_clone("https://github.com/StanzaOrg/stanza-toml.git", foo-folder)
2829
match(r):
2930
(e:git_error_code) :
3031
println("libgit2_clone returned error: %_" % [e])
@@ -34,3 +35,4 @@ deftest(libgit2 online) test-clone :
3435
libgit2_repository_free(gr)
3536
#EXPECT(true)
3637
libgit2_shutdown()
38+
delete-recursive(foo-folder)

tests/toml.stanza

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ deftest(toml) test-find-dependency:
5757

5858
deftest(toml) test-parse-slm-toml:
5959
set-env("TEST_VAR", "/home/charles")
60-
val uut = parse-slm-toml("./tests/data/test.toml")
60+
val uut = parse-slm-toml-file("./tests/data/test.toml")
6161
unset-env("TEST_VAR")
6262

6363
#EXPECT(name(uut) == "test-slm")
@@ -118,7 +118,7 @@ deftest(toml) test-parse-mutex-error:
118118
set-env("TEST_VAR", "/home/charles")
119119

120120
defn fail-on-mutex-git-path () :
121-
parse-slm-toml("./tests/data/error_git_path_mutex.toml")
121+
parse-slm-toml-file("./tests/data/error_git_path_mutex.toml")
122122

123123
val msg = expect-throw(fail-on-mutex-git-path)
124124

@@ -132,7 +132,7 @@ deftest(toml) test-parse-malformed-error:
132132
set-env("TEST_VAR", "/home/charles")
133133

134134
defn fail-on-no-git-path () :
135-
parse-slm-toml("./tests/data/error_no_git_or_path.toml")
135+
parse-slm-toml-file("./tests/data/error_no_git_or_path.toml")
136136

137137
val msg = expect-throw(fail-on-no-git-path)
138138

0 commit comments

Comments
 (0)