Skip to content

Commit

Permalink
Added unit tests for the remove command.
Browse files Browse the repository at this point in the history
  • Loading branch information
callendorph committed Dec 6, 2023
1 parent d33db13 commit 0f8329a
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
1 change: 1 addition & 0 deletions stanza.proj
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ build-test tests:
slm/tests/utils
slm/tests/toml
slm/tests/commands/add
slm/tests/commands/remove
pkg: "test-pkgs"
o: "slm-tests"
129 changes: 129 additions & 0 deletions tests/commands/remove.stanza
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#use-added-syntax(tests)
defpackage slm/tests/commands/remove:
import core
import collections

import semver

import slm/commands/remove
import slm/toml
import slm/dependency

import slm/tests/test-tools

deftest(rm-cmd) test-remove-basic:

val input = SlmToml(
"my-pkg",
"0.1.3",
One("jstanza")
to-hashtable<String, Dependency>([
"stanza-toml" => GitDependency("stanza-toml", "StanzaOrg/stanza-toml", SemanticVersion(0,3,1), "")
])
)

val uut = remove-dependency(input, ["stanza-toml"])

#EXPECT( name(uut) == "my-pkg" )
#EXPECT( version(uut) == "0.1.3" )
#EXPECT( compiler?(uut) == One("jstanza"))

val deps = dependencies(uut)
val names = to-tuple $ keys(deps)
#EXPECT( length(names) == 0 )


deftest(rm-cmd) test-remove-not-found:

val input = SlmToml(
"my-pkg",
"0.1.3",
None(),
to-hashtable<String, Dependency>([])
)

defn attempt-remove () :
remove-dependency(input, ["stanza-toml"])

val msg = expect-throw(attempt-remove)
#EXPECT(prefix?(value!(msg), "The following dependencies were not found"))


deftest(rm-cmd) test-remove-with-others:

val input = SlmToml(
"my-pkg",
"0.1.3",
One("jstanza")
to-hashtable<String, Dependency>([
"stanza-toml" => GitDependency("stanza-toml", "StanzaOrg/stanza-toml", SemanticVersion(0,3,1), "")
"semver" => GitDependency("semver", "StanzaOrg/semver", SemanticVersion(0,1,4), "")
"maybe-utils" => GitDependency("maybe-utils", "StanzaOrg/maybe-utils", SemanticVersion(0,1,5), "")
"scooby-doo" => PathDependency("scooby-doo", "/where/are/you")
])
)

val uut = remove-dependency(input, ["semver"])

#EXPECT( name(uut) == "my-pkg" )
#EXPECT( version(uut) == "0.1.3" )
#EXPECT( compiler?(uut) == One("jstanza"))

val deps = dependencies(uut)
val names = to-tuple $ keys(deps)
val expNames = ["stanza-toml", "maybe-utils", "scooby-doo"]
#EXPECT( length(names) == length(expNames) )

for name in names do:
#EXPECT(contains?(expNames, name))

deftest(rm-cmd) test-remove-multiple:

val input = SlmToml(
"my-pkg",
"0.1.3",
One("jstanza")
to-hashtable<String, Dependency>([
"stanza-toml" => GitDependency("stanza-toml", "StanzaOrg/stanza-toml", SemanticVersion(0,3,1), "")
"semver" => GitDependency("semver", "StanzaOrg/semver", SemanticVersion(0,1,4), "")
"maybe-utils" => GitDependency("maybe-utils", "StanzaOrg/maybe-utils", SemanticVersion(0,1,5), "")
"scooby-doo" => PathDependency("scooby-doo", "/where/are/you")
])
)

val uut = remove-dependency(input, ["semver", "scooby-doo"])

#EXPECT( name(uut) == "my-pkg" )
#EXPECT( version(uut) == "0.1.3" )
#EXPECT( compiler?(uut) == One("jstanza"))

val deps = dependencies(uut)
val names = to-tuple $ keys(deps)
val expNames = ["stanza-toml", "maybe-utils"]
#EXPECT( length(names) == length(expNames) )

for name in names do:
#EXPECT(contains?(expNames, name))


deftest(rm-cmd) test-remove-multiple-with-fail:

val input = SlmToml(
"my-pkg",
"0.1.3",
One("jstanza")
to-hashtable<String, Dependency>([
"stanza-toml" => GitDependency("stanza-toml", "StanzaOrg/stanza-toml", SemanticVersion(0,3,1), "")
"semver" => GitDependency("semver", "StanzaOrg/semver", SemanticVersion(0,1,4), "")
"maybe-utils" => GitDependency("maybe-utils", "StanzaOrg/maybe-utils", SemanticVersion(0,1,5), "")
"scooby-doo" => PathDependency("scooby-doo", "/where/are/you")
])
)

defn attempt-remove ():
remove-dependency(input, ["semver", "scooby-doo", "not-existing"])

val msg = expect-throw(attempt-remove)

#EXPECT(prefix?(value!(msg), "The following dependencies were not found"))

0 comments on commit 0f8329a

Please sign in to comment.