-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for text context, reading environment variables in browser te…
…sts, and gradle root dir for accessing test dirs for non-browser tests
- Loading branch information
Showing
12 changed files
with
340 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2024 Kazimierz Pogoda / Xemantic | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.xemantic.kotlin.test | ||
|
||
/** | ||
* Returns the value of the specified environment variable. | ||
* | ||
* Note: on platforms which does not support access to system environment variables, | ||
* they can be still set with gradle test configuration. | ||
* See [README.md](https://github.com/xemantic/xemantic-kotlin-test) for details. | ||
* | ||
* @param name the name of the environment variable to read. | ||
*/ | ||
public expect fun getEnv(name: String): String? | ||
|
||
/** | ||
* Returns true, if we are on the browser platform. | ||
* | ||
* This flag might be used to skip certain tests, e.g. file based tests | ||
* on platforms which does not offer access to the filesystem. | ||
*/ | ||
public expect val isBrowserPlatform: Boolean | ||
|
||
/** | ||
* The root dir of the gradle project. | ||
* | ||
* It is provided as an absolute file path. The specificity of emulators | ||
* is taken into account. | ||
* | ||
* Note: the gradle root dir can be only resolved with additional gradle | ||
* settings. | ||
* See [README.md](https://github.com/xemantic/xemantic-kotlin-test) for details. | ||
*/ | ||
public val gradleRootDir: String get() = getEnv("GRADLE_ROOT_DIR")!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2024 Kazimierz Pogoda / Xemantic | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.xemantic.kotlin.test | ||
|
||
import kotlin.test.Test | ||
|
||
class TestContextTest { | ||
|
||
@Test | ||
fun `Should read gradleRootDir`() { | ||
if (isBrowserPlatform) return // we don't have access to Gradle root dir | ||
assert(gradleRootDir.isNotEmpty()) | ||
} | ||
|
||
@Test | ||
fun `Should read predefined environment variable`() { | ||
assert(getEnv("FOO") == "bar") | ||
} | ||
|
||
@Test | ||
fun `Should not read undefined environment variable`() { | ||
assert(getEnv("BAR") == null) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2024 Kazimierz Pogoda / Xemantic | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.xemantic.kotlin.test | ||
|
||
public actual fun getEnv( | ||
name: String | ||
): String? { | ||
val variable = process.env[name] | ||
return if (variable) return variable else null | ||
} | ||
|
||
public actual val isBrowserPlatform: Boolean = js( | ||
"typeof window !== 'undefined'" | ||
) | ||
|
||
private external val process: dynamic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2024 Kazimierz Pogoda / Xemantic | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.xemantic.kotlin.test | ||
|
||
public actual fun getEnv( | ||
name: String | ||
): String? = System.getenv(name) | ||
|
||
public actual val isBrowserPlatform: Boolean = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2024 Kazimierz Pogoda / Xemantic | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.xemantic.kotlin.test | ||
|
||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.toKString | ||
import platform.posix.getenv | ||
|
||
@OptIn(ExperimentalForeignApi::class) | ||
public actual fun getEnv( | ||
name: String | ||
): String? = getenv(name)?.toKString() | ||
|
||
public actual val isBrowserPlatform: Boolean = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2024 Kazimierz Pogoda / Xemantic | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.xemantic.kotlin.test | ||
|
||
public actual fun getEnv( | ||
name: String | ||
): String? = js("process.env[name]") | ||
|
||
public actual val isBrowserPlatform: Boolean = js( | ||
"typeof window !== 'undefined'" | ||
) |
Oops, something went wrong.