moved to kotest assertions in compilerAst module tests

This commit is contained in:
Irmen de Jong 2021-11-07 21:18:18 +01:00
parent 1fbbed7e23
commit 7e8db16e18
10 changed files with 194 additions and 174 deletions

View File

@ -23,6 +23,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.3' implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.3'
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12" implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12"
testImplementation 'io.kotest:kotest-runner-junit5-jvm:4.6.3'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5" testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testImplementation 'org.hamcrest:hamcrest:2.2' testImplementation 'org.hamcrest:hamcrest:2.2'

View File

@ -25,5 +25,8 @@
<orderEntry type="module" module-name="codeOptimizers" /> <orderEntry type="module" module-name="codeOptimizers" />
<orderEntry type="module" module-name="compilerInterfaces" /> <orderEntry type="module" module-name="compilerInterfaces" />
<orderEntry type="module" module-name="codeGeneration" /> <orderEntry type="module" module-name="codeGeneration" />
<orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" />
<orderEntry type="library" name="io.kotest.property.jvm" level="project" />
<orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" />
</component> </component>
</module> </module>

View File

@ -16,8 +16,6 @@ dependencies {
implementation project(':parser') implementation project(':parser')
testImplementation 'io.kotest:kotest-runner-junit5-jvm:4.6.3' testImplementation 'io.kotest:kotest-runner-junit5-jvm:4.6.3'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
} }
configurations.all { configurations.all {

View File

@ -14,7 +14,8 @@
<orderEntry type="module" module-name="parser" /> <orderEntry type="module" module-name="parser" />
<orderEntry type="library" name="antlr.antlr4" level="project" /> <orderEntry type="library" name="antlr.antlr4" level="project" />
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" /> <orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
<orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" />
<orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" /> <orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" />
<orderEntry type="library" name="io.kotest.property.jvm" level="project" />
<orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" />
</component> </component>
</module> </module>

View File

@ -1,6 +1,13 @@
package prog8tests.ast package prog8tests.ast
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldStartWith
import io.kotest.matchers.types.instanceOf
import prog8.ast.IFunctionCall import prog8.ast.IFunctionCall
import prog8.ast.Module import prog8.ast.Module
import prog8.ast.Node import prog8.ast.Node
@ -22,7 +29,6 @@ import kotlin.io.path.Path
import kotlin.io.path.isRegularFile import kotlin.io.path.isRegularFile
import kotlin.io.path.name import kotlin.io.path.name
import kotlin.io.path.nameWithoutExtension import kotlin.io.path.nameWithoutExtension
import kotlin.test.*
class TestProg8Parser: FunSpec( { class TestProg8Parser: FunSpec( {
@ -34,14 +40,14 @@ class TestProg8Parser: FunSpec( {
// #40: Prog8ANTLRParser would report (throw) "missing <EOL> at '<EOF>'" // #40: Prog8ANTLRParser would report (throw) "missing <EOL> at '<EOF>'"
val module = parseModule(src) val module = parseModule(src)
assertEquals(1, module.statements.size) module.statements.size shouldBe 1
} }
test("is still accepted - #40, fixed by #45") { test("is still accepted - #40, fixed by #45") {
val nl = "\n" // say, Unix-style (different flavours tested elsewhere) val nl = "\n" // say, Unix-style (different flavours tested elsewhere)
val srcText = "foo {" + nl + "}" + nl // source does end with a newline (issue #40) val srcText = "foo {" + nl + "}" + nl // source does end with a newline (issue #40)
val module = parseModule(SourceCode.Text(srcText)) val module = parseModule(SourceCode.Text(srcText))
assertEquals(1, module.statements.size) module.statements.size shouldBe 1
} }
} }
@ -55,21 +61,21 @@ class TestProg8Parser: FunSpec( {
// GOOD: 2nd block `bar` does start on a new line; however, a nl at the very end ain't needed // GOOD: 2nd block `bar` does start on a new line; however, a nl at the very end ain't needed
val srcGood = "foo {" + nl + "}" + nl + "bar {" + nl + "}" val srcGood = "foo {" + nl + "}" + nl + "bar {" + nl + "}"
assertFailsWith<ParseError> { parseModule(SourceCode.Text(srcBad)) } shouldThrow<ParseError> { parseModule(SourceCode.Text(srcBad)) }
val module = parseModule(SourceCode.Text(srcGood)) val module = parseModule(SourceCode.Text(srcGood))
assertEquals(2, module.statements.size) module.statements.size shouldBe 2
} }
test("is required between two Blocks or Directives - #47") { test("is required between two Blocks or Directives - #47") {
// block and block // block and block
assertFailsWith<ParseError>{ parseModule(SourceCode.Text(""" shouldThrow<ParseError>{ parseModule(SourceCode.Text("""
blockA { blockA {
} blockB { } blockB {
} }
""")) } """)) }
// block and directive // block and directive
assertFailsWith<ParseError>{ parseModule(SourceCode.Text(""" shouldThrow<ParseError>{ parseModule(SourceCode.Text("""
blockB { blockB {
} %import textio } %import textio
""")) } """)) }
@ -78,12 +84,12 @@ class TestProg8Parser: FunSpec( {
// Leaving them in anyways. // Leaving them in anyways.
// dir and block // dir and block
assertFailsWith<ParseError>{ parseModule(SourceCode.Text(""" shouldThrow<ParseError>{ parseModule(SourceCode.Text("""
%import textio blockB { %import textio blockB {
} }
""")) } """)) }
assertFailsWith<ParseError>{ parseModule(SourceCode.Text(""" shouldThrow<ParseError>{ parseModule(SourceCode.Text("""
%import textio %import syslib %import textio %import syslib
""")) } """)) }
} }
@ -112,7 +118,7 @@ class TestProg8Parser: FunSpec( {
nlUnix // end with newline (see testModuleSourceNeedNotEndWithNewline) nlUnix // end with newline (see testModuleSourceNeedNotEndWithNewline)
val module = parseModule(SourceCode.Text(srcText)) val module = parseModule(SourceCode.Text(srcText))
assertEquals(2, module.statements.size) module.statements.size shouldBe 2
} }
} }
@ -129,7 +135,7 @@ class TestProg8Parser: FunSpec( {
} }
""" """
val module = parseModule(SourceCode.Text(srcText)) val module = parseModule(SourceCode.Text(srcText))
assertEquals(1, module.statements.size) module.statements.size shouldBe 1
} }
test("are ok between blocks - #47") { test("are ok between blocks - #47") {
@ -145,7 +151,7 @@ class TestProg8Parser: FunSpec( {
} }
""" """
val module = parseModule(SourceCode.Text(srcText)) val module = parseModule(SourceCode.Text(srcText))
assertEquals(2, module.statements.size) module.statements.size shouldBe 2
} }
test("are ok after last block - #47") { test("are ok after last block - #47") {
@ -159,7 +165,7 @@ class TestProg8Parser: FunSpec( {
""" """
val module = parseModule(SourceCode.Text(srcText)) val module = parseModule(SourceCode.Text(srcText))
assertEquals(1, module.statements.size) module.statements.size shouldBe 1
} }
} }
@ -170,20 +176,20 @@ class TestProg8Parser: FunSpec( {
val text = "%import ${importedNoExt.name}" val text = "%import ${importedNoExt.name}"
val module = parseModule(SourceCode.Text(text)) val module = parseModule(SourceCode.Text(text))
assertEquals(1, module.statements.size) module.statements.size shouldBe 1
} }
} }
context("EmptySourcecode") { context("EmptySourcecode") {
test("from an empty string should result in empty Module") { test("from an empty string should result in empty Module") {
val module = parseModule(SourceCode.Text("")) val module = parseModule(SourceCode.Text(""))
assertEquals(0, module.statements.size) module.statements.size shouldBe 0
} }
test("from an empty file should result in empty Module") { test("from an empty file should result in empty Module") {
val path = assumeReadableFile(fixturesDir, "empty.p8") val path = assumeReadableFile(fixturesDir, "empty.p8")
val module = parseModule(SourceCode.File(path)) val module = parseModule(SourceCode.File(path))
assertEquals(0, module.statements.size) module.statements.size shouldBe 0
} }
} }
@ -196,13 +202,13 @@ class TestProg8Parser: FunSpec( {
val module = parseModule(SourceCode.Text(srcText)) val module = parseModule(SourceCode.Text(srcText))
// Note: assertContains has *actual* as first param // Note: assertContains has *actual* as first param
assertContains(module.name, Regex("^<String@[0-9a-f\\-]+>$")) module.name shouldContain Regex("^<String@[0-9a-f\\-]+>$")
} }
test("parsed from a file") { test("parsed from a file") {
val path = assumeReadableFile(fixturesDir, "simple_main.p8") val path = assumeReadableFile(fixturesDir, "simple_main.p8")
val module = parseModule(SourceCode.File(path)) val module = parseModule(SourceCode.File(path))
assertEquals(path.nameWithoutExtension, module.name) module.name shouldBe path.nameWithoutExtension
} }
} }
@ -216,10 +222,10 @@ class TestProg8Parser: FunSpec( {
expEndCol: Int? = null expEndCol: Int? = null
) { ) {
require(!listOf(expLine, expStartCol, expEndCol).all { it == null }) require(!listOf(expLine, expStartCol, expEndCol).all { it == null })
if (expLine != null) assertEquals(expLine, actual.line, ".position.line (1-based)") if (expLine != null) actual.line shouldBe expLine
if (expStartCol != null) assertEquals(expStartCol, actual.startCol, ".position.startCol (0-based)") if (expStartCol != null) actual.startCol shouldBe expStartCol
if (expEndCol != null) assertEquals(expEndCol, actual.endCol, ".position.endCol (0-based)") if (expEndCol != null) actual.endCol shouldBe expEndCol
if (expFile != null) assertEquals(expFile, actual.file, ".position.file") if (expFile != null) actual.file shouldBe expFile
} }
fun assertPosition( fun assertPosition(
@ -230,11 +236,10 @@ class TestProg8Parser: FunSpec( {
expEndCol: Int? = null expEndCol: Int? = null
) { ) {
require(!listOf(expLine, expStartCol, expEndCol).all { it == null }) require(!listOf(expLine, expStartCol, expEndCol).all { it == null })
if (expLine != null) assertEquals(expLine, actual.line, ".position.line (1-based)") if (expLine != null) actual.line shouldBe expLine
if (expStartCol != null) assertEquals(expStartCol, actual.startCol, ".position.startCol (0-based)") if (expStartCol != null) actual.startCol shouldBe expStartCol
if (expEndCol != null) assertEquals(expEndCol, actual.endCol, ".position.endCol (0-based)") if (expEndCol != null) actual.endCol shouldBe expEndCol
// Note: assertContains expects *actual* value first if (expFile != null) actual.file shouldContain expFile
if (expFile != null) assertContains(actual.file, expFile, ".position.file")
} }
fun assertPositionOf( fun assertPositionOf(
@ -259,14 +264,14 @@ class TestProg8Parser: FunSpec( {
test("in ParseError from bad string source code") { test("in ParseError from bad string source code") {
val srcText = "bad * { }\n" val srcText = "bad * { }\n"
val e = assertFailsWith<ParseError> { parseModule(SourceCode.Text(srcText)) } val e = shouldThrow<ParseError> { parseModule(SourceCode.Text(srcText)) }
assertPosition(e.position, Regex("^<String@[0-9a-f\\-]+>$"), 1, 4, 4) assertPosition(e.position, Regex("^<String@[0-9a-f\\-]+>$"), 1, 4, 4)
} }
test("in ParseError from bad file source code") { test("in ParseError from bad file source code") {
val path = assumeReadableFile(fixturesDir, "file_with_syntax_error.p8") val path = assumeReadableFile(fixturesDir, "file_with_syntax_error.p8")
val e = assertFailsWith<ParseError> { parseModule(SourceCode.File(path)) } val e = shouldThrow<ParseError> { parseModule(SourceCode.File(path)) }
assertPosition(e.position, SourceCode.relative(path).toString(), 2, 6) assertPosition(e.position, SourceCode.relative(path).toString(), 2, 6)
} }
@ -353,8 +358,8 @@ class TestProg8Parser: FunSpec( {
val path = assumeReadableFile(fixturesDir, "simple_main.p8") val path = assumeReadableFile(fixturesDir, "simple_main.p8")
val module = parseModule(SourceCode.File(path)) val module = parseModule(SourceCode.File(path))
assertSomethingForAllNodes(module) { assertSomethingForAllNodes(module) {
assertFalse(Path(it.position.file).isAbsolute) Path(it.position.file).isAbsolute shouldBe false
assertTrue(Path(it.position.file).isRegularFile()) Path(it.position.file).isRegularFile() shouldBe true
} }
} }
@ -371,7 +376,7 @@ class TestProg8Parser: FunSpec( {
""".trimIndent() """.trimIndent()
val module = parseModule(SourceCode.Text(srcText)) val module = parseModule(SourceCode.Text(srcText))
assertSomethingForAllNodes(module) { assertSomethingForAllNodes(module) {
assertTrue(it.position.file.startsWith(SourceCode.stringSourcePrefix)) it.position.file shouldStartWith SourceCode.stringSourcePrefix
} }
} }
@ -380,7 +385,7 @@ class TestProg8Parser: FunSpec( {
val resource = SourceCode.Resource("prog8lib/math.p8") val resource = SourceCode.Resource("prog8lib/math.p8")
val module = parseModule(resource) val module = parseModule(resource)
assertSomethingForAllNodes(module) { assertSomethingForAllNodes(module) {
assertTrue(it.position.file.startsWith(SourceCode.libraryFilePrefix)) it.position.file shouldStartWith SourceCode.libraryFilePrefix
} }
} }
} }
@ -402,9 +407,9 @@ class TestProg8Parser: FunSpec( {
.statements.filterIsInstance<Subroutine>()[0] .statements.filterIsInstance<Subroutine>()[0]
val funCall = startSub.statements.filterIsInstance<IFunctionCall>().first() val funCall = startSub.statements.filterIsInstance<IFunctionCall>().first()
assertIs<CharLiteral>(funCall.args[0]) funCall.args[0] shouldBe(instanceOf<CharLiteral>())
val char = funCall.args[0] as CharLiteral val char = funCall.args[0] as CharLiteral
assertEquals('\n', char.value) char.value shouldBe '\n'
} }
test("on rhs of block-level var decl, no AltEnc") { test("on rhs of block-level var decl, no AltEnc") {
@ -419,8 +424,8 @@ class TestProg8Parser: FunSpec( {
.statements.filterIsInstance<VarDecl>()[0] .statements.filterIsInstance<VarDecl>()[0]
val rhs = decl.value as CharLiteral val rhs = decl.value as CharLiteral
assertEquals('x', rhs.value, "char literal's .value") rhs.value shouldBe 'x'
assertEquals(false, rhs.altEncoding, "char literal's .altEncoding") rhs.altEncoding shouldBe false
} }
test("on rhs of block-level const decl, with AltEnc") { test("on rhs of block-level const decl, with AltEnc") {
@ -435,8 +440,8 @@ class TestProg8Parser: FunSpec( {
.statements.filterIsInstance<VarDecl>()[0] .statements.filterIsInstance<VarDecl>()[0]
val rhs = decl.value as CharLiteral val rhs = decl.value as CharLiteral
assertEquals('x', rhs.value, "char literal's .value") rhs.value shouldBe 'x'
assertEquals(true, rhs.altEncoding, "char literal's .altEncoding") rhs.altEncoding shouldBe true
} }
test("on rhs of subroutine-level var decl, no AltEnc") { test("on rhs of subroutine-level var decl, no AltEnc") {
@ -454,8 +459,8 @@ class TestProg8Parser: FunSpec( {
.statements.filterIsInstance<VarDecl>()[0] .statements.filterIsInstance<VarDecl>()[0]
val rhs = decl.value as CharLiteral val rhs = decl.value as CharLiteral
assertEquals('x', rhs.value, "char literal's .value") rhs.value shouldBe 'x'
assertEquals(false, rhs.altEncoding, "char literal's .altEncoding") rhs.altEncoding shouldBe false
} }
test("on rhs of subroutine-level const decl, with AltEnc") { test("on rhs of subroutine-level const decl, with AltEnc") {
@ -473,8 +478,8 @@ class TestProg8Parser: FunSpec( {
.statements.filterIsInstance<VarDecl>()[0] .statements.filterIsInstance<VarDecl>()[0]
val rhs = decl.value as CharLiteral val rhs = decl.value as CharLiteral
assertEquals('x', rhs.value, "char literal's .value") rhs.value shouldBe 'x'
assertEquals(true, rhs.altEncoding, "char literal's .altEncoding") rhs.altEncoding shouldBe true
} }
} }
@ -504,26 +509,26 @@ class TestProg8Parser: FunSpec( {
.statements.filterIsInstance<ForLoop>() .statements.filterIsInstance<ForLoop>()
.map { it.iterable } .map { it.iterable }
assertEquals(5, iterables.size) iterables.size shouldBe 5
val it0 = iterables[0] as RangeExpr val it0 = iterables[0] as RangeExpr
assertIs<StringLiteralValue>(it0.from, "parser should leave it as is") it0.from shouldBe instanceOf<StringLiteralValue>()
assertIs<StringLiteralValue>(it0.to, "parser should leave it as is") it0.to shouldBe instanceOf<StringLiteralValue>()
val it1 = iterables[1] as StringLiteralValue val it1 = iterables[1] as StringLiteralValue
assertEquals("something", it1.value, "parser should leave it as is") it1.value shouldBe "something"
val it2 = iterables[2] as RangeExpr val it2 = iterables[2] as RangeExpr
assertIs<CharLiteral>(it2.from, "parser should leave it as is") it2.from shouldBe instanceOf<CharLiteral>()
assertIs<CharLiteral>(it2.to, "parser should leave it as is") it2.to shouldBe instanceOf<CharLiteral>()
val it3 = iterables[3] as RangeExpr val it3 = iterables[3] as RangeExpr
assertIs<NumericLiteralValue>(it3.from, "parser should leave it as is") it3.from shouldBe instanceOf<NumericLiteralValue>()
assertIs<NumericLiteralValue>(it3.to, "parser should leave it as is") it3.to shouldBe instanceOf<NumericLiteralValue>()
val it4 = iterables[4] as RangeExpr val it4 = iterables[4] as RangeExpr
assertIs<NumericLiteralValue>(it4.from, "parser should leave it as is") it4.from shouldBe instanceOf<NumericLiteralValue>()
assertIs<NumericLiteralValue>(it4.to, "parser should leave it as is") it4.to shouldBe instanceOf<NumericLiteralValue>()
} }
} }
@ -532,33 +537,33 @@ class TestProg8Parser: FunSpec( {
val char2 = CharLiteral('z', true, Position.DUMMY) val char2 = CharLiteral('z', true, Position.DUMMY)
val program = Program("test", DummyFunctions, DummyMemsizer, AsciiStringEncoder) val program = Program("test", DummyFunctions, DummyMemsizer, AsciiStringEncoder)
assertEquals(65, char1.constValue(program).number.toInt()) char1.constValue(program).number.toInt() shouldBe 65
assertEquals(122, char2.constValue(program).number.toInt()) char2.constValue(program).number.toInt() shouldBe 122
} }
test("testLiteralValueComparisons") { test("testLiteralValueComparisons") {
val ten = NumericLiteralValue(DataType.UWORD, 10, Position.DUMMY) val ten = NumericLiteralValue(DataType.UWORD, 10, Position.DUMMY)
val nine = NumericLiteralValue(DataType.UBYTE, 9, Position.DUMMY) val nine = NumericLiteralValue(DataType.UBYTE, 9, Position.DUMMY)
assertEquals(ten, ten) ten shouldBe ten
assertNotEquals(ten, nine) nine shouldNotBe ten
assertFalse(ten != ten) (ten != ten) shouldBe false
assertTrue(ten != nine) (ten != nine) shouldBe true
assertTrue(ten > nine) (ten > nine) shouldBe true
assertTrue(ten >= nine) (ten >= nine) shouldBe true
assertTrue(ten >= ten) (ten >= ten) shouldBe true
assertFalse(ten > ten) (ten > ten) shouldBe false
assertFalse(ten < nine) (ten < nine) shouldBe false
assertFalse(ten <= nine) (ten <= nine) shouldBe false
assertTrue(ten <= ten) (ten <= ten) shouldBe true
assertFalse(ten < ten) (ten < ten) shouldBe false
val abc = StringLiteralValue("abc", false, Position.DUMMY) val abc = StringLiteralValue("abc", false, Position.DUMMY)
val abd = StringLiteralValue("abd", false, Position.DUMMY) val abd = StringLiteralValue("abd", false, Position.DUMMY)
assertEquals(abc, abc) abc shouldBe abc
assertTrue(abc!=abd) (abc!=abd) shouldBe true
assertFalse(abc!=abc) (abc!=abc) shouldBe false
} }
test("testAnonScopeStillContainsVarsDirectlyAfterParse") { test("testAnonScopeStillContainsVarsDirectlyAfterParse") {
@ -576,12 +581,18 @@ class TestProg8Parser: FunSpec( {
val mainBlock = module.statements.single() as Block val mainBlock = module.statements.single() as Block
val start = mainBlock.statements.single() as Subroutine val start = mainBlock.statements.single() as Subroutine
val repeatbody = (start.statements.single() as RepeatLoop).body val repeatbody = (start.statements.single() as RepeatLoop).body
assertFalse(mainBlock.statements.any { it is VarDecl }, "no vars moved to main block") withClue("no vars moved to main block") {
assertFalse(start.statements.any { it is VarDecl }, "no vars moved to start sub") mainBlock.statements.any { it is VarDecl } shouldBe false
assertTrue(repeatbody.statements[0] is VarDecl, "var is still in repeat block (anonymousscope)") }
withClue("no vars moved to start sub") {
start.statements.any { it is VarDecl } shouldBe false
}
withClue("\"var is still in repeat block (anonymousscope") {
repeatbody.statements[0] shouldBe instanceOf<VarDecl>()
}
val initvalue = (repeatbody.statements[0] as VarDecl).value as? NumericLiteralValue val initvalue = (repeatbody.statements[0] as VarDecl).value as? NumericLiteralValue
assertEquals(99, initvalue?.number?.toInt()) initvalue?.number?.toInt() shouldBe 99
assertTrue(repeatbody.statements[1] is PostIncrDecr) repeatbody.statements[1] shouldBe instanceOf<PostIncrDecr>()
// the ast processing steps used in the compiler, will eventually move the var up to the containing scope (subroutine). // the ast processing steps used in the compiler, will eventually move the var up to the containing scope (subroutine).
} }
@ -612,6 +623,6 @@ class TestProg8Parser: FunSpec( {
val mainBlock = module.statements.single() as Block val mainBlock = module.statements.single() as Block
val start = mainBlock.statements.single() as Subroutine val start = mainBlock.statements.single() as Subroutine
val labels = start.statements.filterIsInstance<Label>() val labels = start.statements.filterIsInstance<Label>()
assertEquals(1, labels.size, "only one label in subroutine scope") labels.size shouldBe 1
} }
}) })

View File

@ -1,6 +1,9 @@
package prog8tests.ast package prog8tests.ast
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.AnnotationSpec import io.kotest.core.spec.style.AnnotationSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import prog8.parser.SourceCode import prog8.parser.SourceCode
import prog8.parser.SourceCode.Companion.libraryFilePrefix import prog8.parser.SourceCode.Companion.libraryFilePrefix
import prog8tests.ast.helpers.assumeNotExists import prog8tests.ast.helpers.assumeNotExists
@ -8,7 +11,6 @@ import prog8tests.ast.helpers.assumeReadableFile
import prog8tests.ast.helpers.fixturesDir import prog8tests.ast.helpers.fixturesDir
import prog8tests.ast.helpers.resourcesDir import prog8tests.ast.helpers.resourcesDir
import kotlin.io.path.Path import kotlin.io.path.Path
import kotlin.test.*
class TestSourceCode: AnnotationSpec() { class TestSourceCode: AnnotationSpec() {
@ -21,30 +23,30 @@ class TestSourceCode: AnnotationSpec() {
val src = SourceCode.Text(text) val src = SourceCode.Text(text)
val actualText = src.getCharStream().toString() val actualText = src.getCharStream().toString()
assertContains(src.origin, Regex("^<String@[0-9a-f\\-]+>$")) src.origin shouldContain Regex("^<String@[0-9a-f\\-]+>$")
assertEquals(text, actualText) actualText shouldBe text
assertFalse(src.isFromResources) src.isFromResources shouldBe false
assertFalse(src.isFromFilesystem) src.isFromFilesystem shouldBe false
assertTrue(src.toString().startsWith("prog8.parser.SourceCode")) src.toString().startsWith("prog8.parser.SourceCode") shouldBe true
} }
@Test @Test
fun testFromPathWithNonExistingPath() { fun testFromPathWithNonExistingPath() {
val filename = "i_do_not_exist.p8" val filename = "i_do_not_exist.p8"
val path = assumeNotExists(fixturesDir, filename) val path = assumeNotExists(fixturesDir, filename)
assertFailsWith<NoSuchFileException> { SourceCode.File(path) } shouldThrow<NoSuchFileException> { SourceCode.File(path) }
} }
@Test @Test
fun testFromPathWithMissingExtension_p8() { fun testFromPathWithMissingExtension_p8() {
val pathWithoutExt = assumeNotExists(fixturesDir,"simple_main") val pathWithoutExt = assumeNotExists(fixturesDir,"simple_main")
assumeReadableFile(fixturesDir,"simple_main.p8") assumeReadableFile(fixturesDir,"simple_main.p8")
assertFailsWith<NoSuchFileException> { SourceCode.File(pathWithoutExt) } shouldThrow<NoSuchFileException> { SourceCode.File(pathWithoutExt) }
} }
@Test @Test
fun testFromPathWithDirectory() { fun testFromPathWithDirectory() {
assertFailsWith<AccessDeniedException> { SourceCode.File(fixturesDir) } shouldThrow<AccessDeniedException> { SourceCode.File(fixturesDir) }
} }
@Test @Test
@ -53,10 +55,10 @@ class TestSourceCode: AnnotationSpec() {
val path = assumeReadableFile(fixturesDir, filename) val path = assumeReadableFile(fixturesDir, filename)
val src = SourceCode.File(path) val src = SourceCode.File(path)
val expectedOrigin = SourceCode.relative(path).toString() val expectedOrigin = SourceCode.relative(path).toString()
assertEquals(expectedOrigin, src.origin) src.origin shouldBe expectedOrigin
assertEquals(path.toFile().readText(), src.readText()) src.readText() shouldBe path.toFile().readText()
assertFalse(src.isFromResources) src.isFromResources shouldBe false
assertTrue(src.isFromFilesystem) src.isFromFilesystem shouldBe true
} }
@Test @Test
@ -66,8 +68,8 @@ class TestSourceCode: AnnotationSpec() {
val srcFile = assumeReadableFile(path).toFile() val srcFile = assumeReadableFile(path).toFile()
val src = SourceCode.File(path) val src = SourceCode.File(path)
val expectedOrigin = SourceCode.relative(path).toString() val expectedOrigin = SourceCode.relative(path).toString()
assertEquals(expectedOrigin, src.origin) src.origin shouldBe expectedOrigin
assertEquals(srcFile.readText(), src.readText()) src.readText() shouldBe srcFile.readText()
} }
@Test @Test
@ -76,10 +78,10 @@ class TestSourceCode: AnnotationSpec() {
val srcFile = assumeReadableFile(resourcesDir, pathString).toFile() val srcFile = assumeReadableFile(resourcesDir, pathString).toFile()
val src = SourceCode.Resource(pathString) val src = SourceCode.Resource(pathString)
assertEquals("$libraryFilePrefix/$pathString", src.origin) src.origin shouldBe "$libraryFilePrefix/$pathString"
assertEquals(srcFile.readText(), src.readText()) src.readText() shouldBe srcFile.readText()
assertTrue(src.isFromResources) src.isFromResources shouldBe true
assertFalse(src.isFromFilesystem) src.isFromFilesystem shouldBe false
} }
@Test @Test
@ -88,8 +90,8 @@ class TestSourceCode: AnnotationSpec() {
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile() val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
val src = SourceCode.Resource(pathString) val src = SourceCode.Resource(pathString)
assertEquals("$libraryFilePrefix$pathString", src.origin) src.origin shouldBe "$libraryFilePrefix$pathString"
assertEquals(srcFile.readText(), src.readText()) src.readText() shouldBe srcFile.readText()
} }
@Test @Test
@ -98,9 +100,9 @@ class TestSourceCode: AnnotationSpec() {
val srcFile = assumeReadableFile(resourcesDir, pathString).toFile() val srcFile = assumeReadableFile(resourcesDir, pathString).toFile()
val src = SourceCode.Resource(pathString) val src = SourceCode.Resource(pathString)
assertEquals("$libraryFilePrefix/$pathString", src.origin) src.origin shouldBe "$libraryFilePrefix/$pathString"
assertEquals(srcFile.readText(), src.readText()) src.readText() shouldBe srcFile.readText()
assertTrue(src.isFromResources, ".isFromResources") src.isFromResources shouldBe true
} }
@Test @Test
@ -109,8 +111,8 @@ class TestSourceCode: AnnotationSpec() {
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile() val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
val src = SourceCode.Resource(pathString) val src = SourceCode.Resource(pathString)
assertEquals("$libraryFilePrefix$pathString", src.origin) src.origin shouldBe "$libraryFilePrefix$pathString"
assertEquals(srcFile.readText(), src.readText()) src.readText() shouldBe srcFile.readText()
} }
@Test @Test
@ -119,9 +121,9 @@ class TestSourceCode: AnnotationSpec() {
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile() val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
val src = SourceCode.Resource(pathString) val src = SourceCode.Resource(pathString)
assertEquals("$libraryFilePrefix/prog8lib/math.p8", src.origin) src.origin shouldBe "$libraryFilePrefix/prog8lib/math.p8"
assertEquals(srcFile.readText(), src.readText()) src.readText() shouldBe srcFile.readText()
assertTrue(src.isFromResources, ".isFromResources") src.isFromResources shouldBe true
} }
@ -130,13 +132,13 @@ class TestSourceCode: AnnotationSpec() {
val pathString = "/prog8lib/i_do_not_exist" val pathString = "/prog8lib/i_do_not_exist"
assumeNotExists(resourcesDir, pathString.substring(1)) assumeNotExists(resourcesDir, pathString.substring(1))
assertFailsWith<NoSuchFileException> { SourceCode.Resource(pathString) } shouldThrow<NoSuchFileException> { SourceCode.Resource(pathString) }
} }
@Test @Test
fun testFromResourcesWithNonExistingFile_withoutLeadingSlash() { fun testFromResourcesWithNonExistingFile_withoutLeadingSlash() {
val pathString = "prog8lib/i_do_not_exist" val pathString = "prog8lib/i_do_not_exist"
assumeNotExists(resourcesDir, pathString) assumeNotExists(resourcesDir, pathString)
assertFailsWith<NoSuchFileException> { SourceCode.Resource(pathString) } shouldThrow<NoSuchFileException> { SourceCode.Resource(pathString) }
} }
} }

View File

@ -1,14 +1,12 @@
package prog8tests.ast package prog8tests.ast
import io.kotest.core.spec.style.AnnotationSpec import io.kotest.core.spec.style.AnnotationSpec
import io.kotest.matchers.shouldBe
import prog8.ast.base.DataType import prog8.ast.base.DataType
import prog8.ast.statements.Block import prog8.ast.statements.Block
import prog8.ast.statements.Subroutine import prog8.ast.statements.Subroutine
import prog8.parser.Prog8Parser.parseModule import prog8.parser.Prog8Parser.parseModule
import prog8.parser.SourceCode import prog8.parser.SourceCode
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class TestSubroutines: AnnotationSpec() { class TestSubroutines: AnnotationSpec() {
@ -31,12 +29,12 @@ class TestSubroutines: AnnotationSpec() {
val mainBlock = module.statements.single() as Block val mainBlock = module.statements.single() as Block
val asmfunc = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="asmfunc"} val asmfunc = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="asmfunc"}
val func = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="func"} val func = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="func"}
assertTrue(asmfunc.isAsmSubroutine) asmfunc.isAsmSubroutine shouldBe true
assertEquals(DataType.STR, asmfunc.parameters.single().type) asmfunc.parameters.single().type shouldBe DataType.STR
assertTrue(asmfunc.statements.isEmpty()) asmfunc.statements.isEmpty() shouldBe true
assertFalse(func.isAsmSubroutine) func.isAsmSubroutine shouldBe false
assertEquals(DataType.STR, func.parameters.single().type) func.parameters.single().type shouldBe DataType.STR
assertTrue(func.statements.isEmpty()) func.statements.isEmpty() shouldBe true
} }
@Test @Test
@ -57,11 +55,11 @@ class TestSubroutines: AnnotationSpec() {
val mainBlock = module.statements.single() as Block val mainBlock = module.statements.single() as Block
val asmfunc = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="asmfunc"} val asmfunc = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="asmfunc"}
val func = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="func"} val func = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="func"}
assertTrue(asmfunc.isAsmSubroutine) asmfunc.isAsmSubroutine shouldBe true
assertEquals(DataType.ARRAY_UB, asmfunc.parameters.single().type) asmfunc.parameters.single().type shouldBe DataType.ARRAY_UB
assertTrue(asmfunc.statements.isEmpty()) asmfunc.statements.isEmpty() shouldBe true
assertFalse(func.isAsmSubroutine) func.isAsmSubroutine shouldBe false
assertEquals(DataType.ARRAY_UB, func.parameters.single().type) func.parameters.single().type shouldBe DataType.ARRAY_UB
assertTrue(func.statements.isEmpty()) func.statements.isEmpty() shouldBe true
} }
} }

View File

@ -1,10 +1,10 @@
package prog8tests.ast.helpers package prog8tests.ast.helpers
import io.kotest.assertions.withClue
import io.kotest.matchers.shouldBe
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import kotlin.io.path.* import kotlin.io.path.*
import kotlin.test.assertFalse
import kotlin.test.assertTrue
val workingDir = assumeDirectory("").absolute() // Note: "." does NOT work..! val workingDir = assumeDirectory("").absolute() // Note: "." does NOT work..!
@ -20,7 +20,9 @@ fun createIfNotExists(workingDir: Path, path: String): Path {
} }
fun assumeNotExists(path: Path): Path { fun assumeNotExists(path: Path): Path {
assertFalse(path.exists(), "sanity check: should not exist: ${path.absolute()}") withClue("sanity check: should not exist: ${path.absolute()}") {
path.exists() shouldBe false
}
return path return path
} }
@ -28,12 +30,16 @@ fun assumeNotExists(pathStr: String): Path = assumeNotExists(Path(pathStr))
fun assumeNotExists(path: Path, other: String): Path = assumeNotExists(path / other) fun assumeNotExists(path: Path, other: String): Path = assumeNotExists(path / other)
fun assumeReadable(path: Path): Path { fun assumeReadable(path: Path): Path {
assertTrue(path.isReadable(), "sanity check: should be readable: ${path.absolute()}") withClue("sanity check: should be readable: ${path.absolute()}") {
path.isReadable() shouldBe true
}
return path return path
} }
fun assumeReadableFile(path: Path): Path { fun assumeReadableFile(path: Path): Path {
assertTrue(path.isRegularFile(), "sanity check: should be normal file: ${path.absolute()}") withClue("sanity check: should be normal file: ${path.absolute()}") {
path.isRegularFile() shouldBe true
}
return assumeReadable(path) return assumeReadable(path)
} }
@ -44,7 +50,9 @@ fun assumeReadableFile(path: Path, other: String): Path = assumeReadableFile(pat
fun assumeReadableFile(path: Path, other: Path): Path = assumeReadableFile(path / other) fun assumeReadableFile(path: Path, other: Path): Path = assumeReadableFile(path / other)
fun assumeDirectory(path: Path): Path { fun assumeDirectory(path: Path): Path {
assertTrue(path.isDirectory(), "sanity check; should be directory: $path") withClue("sanity check; should be directory: $path") {
path.isDirectory() shouldBe true
}
return path return path
} }

View File

@ -1,12 +1,12 @@
package prog8tests.ast package prog8tests.ast
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.assertions.withClue import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import prog8tests.ast.helpers.* import prog8tests.ast.helpers.*
import kotlin.io.path.Path import kotlin.io.path.Path
import kotlin.io.path.div import kotlin.io.path.div
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
// Do not move into folder helpers/! // Do not move into folder helpers/!
@ -22,18 +22,18 @@ class PathsHelpersTests: FunSpec({
test("on non-existing path") { test("on non-existing path") {
val path = fixturesDir / "i_do_not_exist" val path = fixturesDir / "i_do_not_exist"
withClue("should return the path") { withClue("should return the path") {
assertEquals(path, assumeNotExists(path)) assumeNotExists(path) shouldBe path
} }
} }
test("on existing file") { test("on existing file") {
assertFailsWith<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeNotExists(fixturesDir / "simple_main.p8") assumeNotExists(fixturesDir / "simple_main.p8")
} }
} }
test("on existing directory") { test("on existing directory") {
assertFailsWith<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeNotExists(fixturesDir) assumeNotExists(fixturesDir)
} }
} }
@ -44,19 +44,19 @@ class PathsHelpersTests: FunSpec({
test("on non-existing path") { test("on non-existing path") {
val path = fixturesDir / "i_do_not_exist" val path = fixturesDir / "i_do_not_exist"
withClue("should return the path") { withClue("should return the path") {
assertEquals(path, assumeNotExists("$path")) assumeNotExists("$path") shouldBe path
} }
} }
test("on existing file") { test("on existing file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "simple_main.p8"
assertFailsWith<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeNotExists("$path") assumeNotExists("$path")
} }
} }
test("on existing directory") { test("on existing directory") {
assertFailsWith<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeNotExists("$fixturesDir") assumeNotExists("$fixturesDir")
} }
} }
@ -67,18 +67,18 @@ class PathsHelpersTests: FunSpec({
test("on non-existing path") { test("on non-existing path") {
val path = fixturesDir / "i_do_not_exist" val path = fixturesDir / "i_do_not_exist"
withClue("should return the path") { withClue("should return the path") {
assertEquals(path, assumeNotExists(fixturesDir, "i_do_not_exist")) assumeNotExists(fixturesDir / "i_do_not_exist") shouldBe path
} }
} }
test("on existing file") { test("on existing file") {
assertFailsWith<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeNotExists(fixturesDir, "simple_main.p8") assumeNotExists(fixturesDir, "simple_main.p8")
} }
} }
test("on existing directory") { test("on existing directory") {
assertFailsWith<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeNotExists(fixturesDir, "..") assumeNotExists(fixturesDir, "..")
} }
} }
@ -90,14 +90,14 @@ class PathsHelpersTests: FunSpec({
context("WithOnePathArg") { context("WithOnePathArg") {
test("on non-existing path") { test("on non-existing path") {
val path = fixturesDir / "i_do_not_exist" val path = fixturesDir / "i_do_not_exist"
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory(path) assumeDirectory(path)
} }
} }
test("on existing file") { test("on existing file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "simple_main.p8"
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory(path) assumeDirectory(path)
} }
} }
@ -105,7 +105,7 @@ class PathsHelpersTests: FunSpec({
test("on existing directory") { test("on existing directory") {
val path = workingDir val path = workingDir
withClue("should return the path") { withClue("should return the path") {
assertEquals(path, assumeDirectory(path)) assumeDirectory(path) shouldBe path
} }
} }
} }
@ -113,14 +113,14 @@ class PathsHelpersTests: FunSpec({
context("WithOneStringArg") { context("WithOneStringArg") {
test("on non-existing path") { test("on non-existing path") {
val path = fixturesDir / "i_do_not_exist" val path = fixturesDir / "i_do_not_exist"
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory("$path") assumeDirectory("$path")
} }
} }
test("on existing file") { test("on existing file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "simple_main.p8"
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory("$path") assumeDirectory("$path")
} }
} }
@ -128,20 +128,20 @@ class PathsHelpersTests: FunSpec({
test("on existing directory") { test("on existing directory") {
val path = workingDir val path = workingDir
withClue("should return the path") { withClue("should return the path") {
assertEquals(path, assumeDirectory("$path")) assumeDirectory("$path") shouldBe path
} }
} }
} }
context("WithPathAndStringArgs") { context("WithPathAndStringArgs") {
test("on non-existing path") { test("on non-existing path") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory(fixturesDir, "i_do_not_exist") assumeDirectory(fixturesDir, "i_do_not_exist")
} }
} }
test("on existing file") { test("on existing file") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory(fixturesDir, "simple_main.p8") assumeDirectory(fixturesDir, "simple_main.p8")
} }
} }
@ -149,20 +149,20 @@ class PathsHelpersTests: FunSpec({
test("on existing directory") { test("on existing directory") {
val path = workingDir / ".." val path = workingDir / ".."
withClue("should return resulting path") { withClue("should return resulting path") {
assertEquals(path, assumeDirectory(workingDir, "..")) assumeDirectory(workingDir / "..") shouldBe path
} }
} }
} }
context("WithStringAndStringArgs") { context("WithStringAndStringArgs") {
test("on non-existing path") { test("on non-existing path") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory("$fixturesDir", "i_do_not_exist") assumeDirectory("$fixturesDir", "i_do_not_exist")
} }
} }
test("on existing file") { test("on existing file") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory("$fixturesDir", "simple_main.p8") assumeDirectory("$fixturesDir", "simple_main.p8")
} }
} }
@ -170,20 +170,20 @@ class PathsHelpersTests: FunSpec({
test("on existing directory") { test("on existing directory") {
val path = workingDir / ".." val path = workingDir / ".."
withClue("should return resulting path") { withClue("should return resulting path") {
assertEquals(path, assumeDirectory("$workingDir", "..")) assumeDirectory(workingDir / "..") shouldBe path
} }
} }
} }
context("WithStringAndPathArgs") { context("WithStringAndPathArgs") {
test("on non-existing path") { test("on non-existing path") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory("$fixturesDir", Path("i_do_not_exist")) assumeDirectory("$fixturesDir", Path("i_do_not_exist"))
} }
} }
test("on existing file") { test("on existing file") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory("$fixturesDir", Path("simple_main.p8")) assumeDirectory("$fixturesDir", Path("simple_main.p8"))
} }
} }
@ -191,7 +191,7 @@ class PathsHelpersTests: FunSpec({
test("on existing directory") { test("on existing directory") {
val path = workingDir / ".." val path = workingDir / ".."
withClue("should return resulting path") { withClue("should return resulting path") {
assertEquals(path, assumeDirectory("$workingDir", Path(".."))) assumeDirectory(workingDir / Path("..")) shouldBe path
} }
} }
} }
@ -203,7 +203,7 @@ class PathsHelpersTests: FunSpec({
test("on non-existing path") { test("on non-existing path") {
val path = fixturesDir / "i_do_not_exist" val path = fixturesDir / "i_do_not_exist"
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeReadableFile(path) assumeReadableFile(path)
} }
} }
@ -211,12 +211,12 @@ class PathsHelpersTests: FunSpec({
test("on readable file") { test("on readable file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "simple_main.p8"
withClue("should return the path") { withClue("should return the path") {
assertEquals(path, assumeReadableFile(path)) assumeReadableFile(path) shouldBe path
} }
} }
test("on directory") { test("on directory") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeReadableFile(fixturesDir) assumeReadableFile(fixturesDir)
} }
} }
@ -226,7 +226,7 @@ class PathsHelpersTests: FunSpec({
test("on non-existing path") { test("on non-existing path") {
val path = fixturesDir / "i_do_not_exist" val path = fixturesDir / "i_do_not_exist"
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeReadableFile("$path") assumeReadableFile("$path")
} }
} }
@ -234,12 +234,12 @@ class PathsHelpersTests: FunSpec({
test("on readable file") { test("on readable file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "simple_main.p8"
withClue("should return the resulting path") { withClue("should return the resulting path") {
assertEquals(path, assumeReadableFile("$path")) assumeReadableFile("$path") shouldBe path
} }
} }
test("on directory") { test("on directory") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeReadableFile("$fixturesDir") assumeReadableFile("$fixturesDir")
} }
} }
@ -247,7 +247,7 @@ class PathsHelpersTests: FunSpec({
context("WithPathAndStringArgs") { context("WithPathAndStringArgs") {
test("on non-existing path") { test("on non-existing path") {
assertFailsWith<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeReadableFile(fixturesDir, "i_do_not_exist") assumeReadableFile(fixturesDir, "i_do_not_exist")
} }
} }
@ -255,12 +255,12 @@ class PathsHelpersTests: FunSpec({
test("on readable file") { test("on readable file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "simple_main.p8"
withClue("should return the resulting path") { withClue("should return the resulting path") {
assertEquals(path, assumeReadableFile(fixturesDir, "simple_main.p8")) assumeReadableFile(fixturesDir / "simple_main.p8") shouldBe path
} }
} }
test("on directory") { test("on directory") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeReadableFile(fixturesDir, "..") assumeReadableFile(fixturesDir, "..")
} }
} }
@ -268,19 +268,19 @@ class PathsHelpersTests: FunSpec({
context("WithPathAndPathArgs") { context("WithPathAndPathArgs") {
test("on non-existing path") { test("on non-existing path") {
assertFailsWith<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeReadableFile(fixturesDir, Path("i_do_not_exist")) assumeReadableFile(fixturesDir, Path("i_do_not_exist"))
} }
} }
test("on readable file") { test("on readable file") {
withClue("should return the resulting path") { withClue("should return the resulting path") {
assertEquals(fixturesDir / "simple_main.p8", assumeReadableFile(fixturesDir, Path("simple_main.p8"))) assumeReadableFile(fixturesDir / Path("simple_main.p8")) shouldBe fixturesDir / "simple_main.p8"
} }
} }
test("on directory") { test("on directory") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeReadableFile(fixturesDir, Path("..")) assumeReadableFile(fixturesDir, Path(".."))
} }
} }
@ -288,19 +288,19 @@ class PathsHelpersTests: FunSpec({
context("WithStringAndStringArgs") { context("WithStringAndStringArgs") {
test("on non-existing path") { test("on non-existing path") {
assertFailsWith<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeReadableFile("$fixturesDir", "i_do_not_exist") assumeReadableFile("$fixturesDir", "i_do_not_exist")
} }
} }
test("on readable file") { test("on readable file") {
withClue("should return the resulting path") { withClue("should return the resulting path") {
assertEquals( fixturesDir / "simple_main.p8", assumeReadableFile(fixturesDir.toString(), "simple_main.p8")) assumeReadableFile(fixturesDir / "simple_main.p8") shouldBe fixturesDir / "simple_main.p8"
} }
} }
test("on directory") { test("on directory") {
assertFailsWith<AssertionError> { shouldThrow<AssertionError> {
assumeReadableFile("$fixturesDir", "..") assumeReadableFile("$fixturesDir", "..")
} }
} }

View File

@ -3,8 +3,6 @@ TODO
For next compiler release (7.3) For next compiler release (7.3)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- replace all old asserts in compilerAst tests by kotest equivalents
- remove kotlin.test and junit dependencies in compilerAst module
- migrate Compiler tests to KoTest library (this will close github issue #70) - migrate Compiler tests to KoTest library (this will close github issue #70)
... ...