Skip to content

Commit

Permalink
fun
Browse files Browse the repository at this point in the history
  • Loading branch information
mareklangiewicz committed Apr 11, 2024
1 parent 6e2f5b3 commit fee242f
Show file tree
Hide file tree
Showing 49 changed files with 1,069 additions and 949 deletions.
61 changes: 61 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
root = true

# Let's keep it short/minimal, with comments, so it's clear what is enforced in .editorconfig and why.


[*]

charset = utf-8
end_of_line = lf

# file size; diffs on small devices
indent_size = 2

indent_style = space

# simpler adhoc regular expressions search/replace
insert_final_newline = true

max_line_length = 120
tab_width = 2
trim_trailing_whitespace = true
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true

ij_any_keep_blank_lines_in_code = 3
ij_properties_keep_blank_lines = true


[{*.kt,*.kts}]

# new most official defaults on top so can be overridden below
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL

# No aligns at all - too fancy/problematic
ij_kotlin_align_in_columns_case_branch = false
ij_kotlin_align_multiline_binary_operation = false
ij_kotlin_align_multiline_extends_list = false
ij_kotlin_align_multiline_method_parentheses = false
ij_kotlin_align_multiline_parameters = true
ij_kotlin_align_multiline_parameters_in_calls = false
ij_kotlin_line_break_after_multiline_when_entry = false

# Trailing commas great for diffs; rearranging lines
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true

ij_kotlin_imports_layout = *

# Let's try to avoid conflicts with files generated by github-workflows-kt
# https://github.com/typesafegithub/github-workflows-kt
[{*.yaml,*.yml}]
ij_yaml_indent_sequence_value = false
ij_yaml_spaces_within_braces = false
ij_yaml_spaces_within_brackets = false

# Let's try to avoid conflicts with files generated by IntelliJ Run Configurations.
# (Edit Configurations... -> Store as project file)
[{*.ant,*.fxml,*.jhm,*.jnlp,*.jrxml,*.pom,*.rng,*.tld,*.wadl,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul}]
ij_xml_space_inside_empty_tag = true
insert_final_newline = false
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# μSpek

Micro tool for testing with syntax similar to Spek, but shorter.
Test different nested scenarios without **any** boilerplate code.

### Example

```kotlin

@Test
fun uspekTest() {

uspek {

"create some mutable list" o {
Expand Down Expand Up @@ -60,11 +62,12 @@ USpekX also contains less essential stuff like fun for test factories for JUnit5
Use USpekX when in doubt. Both flavors are multiplatform.

### Building with Gradle

```gradle
repositories {
mavenCentral()
}
dependencies {
// either:
testImplementation 'pl.mareklangiewicz:uspekx:A.B.C'
Expand Down
38 changes: 19 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import pl.mareklangiewicz.deps.*
import pl.mareklangiewicz.utils.*

plugins {
plug(plugs.NexusPublish)
plug(plugs.KotlinMulti) apply false
plug(plugs.KotlinJvm) apply false
plug(plugs.NexusPublish)
plug(plugs.KotlinMulti) apply false
plug(plugs.KotlinJvm) apply false
}

val enableJs = true
Expand All @@ -14,23 +14,23 @@ val enableNative = true
// https://youtrack.jetbrains.com/issue/KT-52666/Kotlin-Multiplatform-libraries-without-platform-specific-code-a.k.a.-Pure-Kotlin-libraries-Universal-libraries

defaultBuildTemplateForRootProject(
langaraLibDetails(
name = "USpek",
description = "Micro tool for testing with syntax similar to Spek, but shorter.",
githubUrl = "https://github.com/mareklangiewicz/USpek",
version = Ver(0, 0, 33),
// https://s01.oss.sonatype.org/content/repositories/releases/pl/mareklangiewicz/uspek/
// https://github.com/mareklangiewicz/USpek/releases
settings = LibSettings(
withJs = enableJs,
withNativeLinux64 = enableNative,
compose = null,
withTestJUnit4 = false,
withTestJUnit5 = false,
withTestUSpekX = false, // Let's NOT try to test uspek with other packaged uspek to avoid confusion.
withSonatypeOssPublishing = true,
),
langaraLibDetails(
name = "USpek",
description = "Micro tool for testing with syntax similar to Spek, but shorter.",
githubUrl = "https://github.com/mareklangiewicz/USpek",
version = Ver(0, 0, 33),
// https://s01.oss.sonatype.org/content/repositories/releases/pl/mareklangiewicz/uspek/
// https://github.com/mareklangiewicz/USpek/releases
settings = LibSettings(
withJs = enableJs,
withNativeLinux64 = enableNative,
compose = null,
withTestJUnit4 = false,
withTestJUnit5 = false,
withTestUSpekX = false, // Let's NOT try to test uspek with other packaged uspek to avoid confusion.
withSonatypeOssPublishing = true,
),
),
)

// region [Root Build Template]
Expand Down
38 changes: 19 additions & 19 deletions ktandrosample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ import pl.mareklangiewicz.deps.*
import pl.mareklangiewicz.utils.*

plugins {
plugAll(plugs.AndroLibEdge, plugs.KotlinAndro)
plugAll(plugs.AndroLibEdge, plugs.KotlinAndro)
}

val details = langaraLibDetails(
// name = "USpek Andro Sample",
name = "ktsample",
githubUrl = "https://github.com/mareklangiewicz/USpek",
settings = LibSettings(
withTestJUnit4 = true,
withTestJUnit5 = false,
withTestUSpekX = true,
compose = LibComposeSettings(
// withComposeCompiler = ComposeCompilerJb, // can't use Jb because andro plugin doesn't support it.
withComposeCompiler = ComposeCompilerAx,
// withComposeCompilerAllowWrongKotlinVer = Ver("2.0.0-Beta4"),
withComposeTestUiJUnit4 = true,
withComposeTestUiJUnit5 = false,
),
andro = LibAndroSettings()
)
// name = "USpek Andro Sample",
name = "ktsample",
githubUrl = "https://github.com/mareklangiewicz/USpek",
settings = LibSettings(
withTestJUnit4 = true,
withTestJUnit5 = false,
withTestUSpekX = true,
compose = LibComposeSettings(
// withComposeCompiler = ComposeCompilerJb, // can't use Jb because andro plugin doesn't support it.
withComposeCompiler = ComposeCompilerAx,
// withComposeCompilerAllowWrongKotlinVer = Ver("2.0.0-Beta4"),
withComposeTestUiJUnit4 = true,
withComposeTestUiJUnit5 = false,
),
andro = LibAndroSettings(),
),
)

defaultBuildTemplateForAndroLib(details)

dependencies {
defaultAndroTestDeps(details.settings, configuration = "androidTestImplementation")
// TODO_someday: investigate why "androidTestImplementation" doesn't inherit from "testImplementation"
defaultAndroTestDeps(details.settings, configuration = "androidTestImplementation")
// TODO_someday: investigate why "androidTestImplementation" doesn't inherit from "testImplementation"
}

// region [Kotlin Module Build Template]
Expand Down
5 changes: 0 additions & 5 deletions ktandrosample/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

android.useAndroidX=true
132 changes: 66 additions & 66 deletions ktandrosample/src/androidTest/kotlin/SomeComposeUSpek.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import androidx.compose.ui.graphics.*
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.*
import androidx.compose.ui.unit.*
import java.lang.Thread.*
import kotlin.test.*
import org.junit.*
import org.junit.runner.*
import pl.mareklangiewicz.uspek.*
import java.lang.Thread.*
import kotlin.test.*

// I use custom runner here and it seems to work, but consider changing default runner as experimental/dangerous.
// See more info in comments in andro tests in DepsKt/template-andro
Expand All @@ -23,91 +23,91 @@ import kotlin.test.*
@Suppress("DEPRECATION")
@RunWith(USpekJUnit4Runner::class)
class SomeComposeUSpek {
init {
uspekLog = {
if (it.failed) Log.e("uspek", it.status)
else Log.w("uspek", it.status)
}
init {
uspekLog = {
if (it.failed) Log.e("uspek", it.status)
else Log.w("uspek", it.status)
}
}

@get:Rule
val rule = createComposeRule()
@get:Rule
val rule = createComposeRule()

// @Test
// fun simpleTest() = assertEquals(2, 2)
//
// @Test
// fun simpleFailingTest() = assertEquals(3, 4)
// @Test
// fun simpleTest() = assertEquals(2, 2)
//
// @Test
// fun simpleFailingTest() = assertEquals(3, 4)

@USpekTestTree(13)
fun layoutUSpek() = with(rule) {
@USpekTestTree(13)
fun layoutUSpek() = with(rule) {

"On simple box content" o {
setContent {
Box {
Text("First simple box")
}
}
"On simple box content" o {
setContent {
Box {
Text("First simple box")
}
}
}

"On second nothing test" o {
setContent {
Box(Modifier.background(Color.Blue)) {
Text("Second simple box")
}
}
assertEquals(4, 4)
"On second nothing test" o {
setContent {
Box(Modifier.background(Color.Blue)) {
Text("Second simple box")
}
}
assertEquals(4, 4)
}

"On third nothing test" o {
assertEquals(5, 5)
"On inner UI test" o {
setContent {
Box(Modifier.background(Color.Cyan)) {
Text("Third inner box")
}
}
"wait a bit with content and fail" ox {
sleep(1000)
fail()
}
"wait a bit again with content and finish" ox {
sleep(1000)
}
}
"On third nothing test" o {
assertEquals(5, 5)
"On inner UI test" o {
setContent {
Box(Modifier.background(Color.Cyan)) {
Text("Third inner box")
}
}
"wait a bit with content and fail" ox {
sleep(1000)
fail()
}
"wait a bit again with content and finish" ox {
sleep(1000)
}
}
}

"On some animated stuff" o {
rule.mainClock.autoAdvance = false
"On some animated stuff" o {
rule.mainClock.autoAdvance = false

var numberTarget by mutableStateOf(100)
var numberTarget by mutableStateOf(100)

"On content with animated number" o {
setContent {
AnimatedStuff(numberTarget)
}
"On content with animated number" o {
setContent {
AnimatedStuff(numberTarget)
}

"box width is 200 dp" o { onNodeWithTag("mybox").assertWidthIsEqualTo(200.dp) }
"box width is 200 dp" o { onNodeWithTag("mybox").assertWidthIsEqualTo(200.dp) }


"On setting numberTarget to 200" o {
numberTarget = 200
"On setting numberTarget to 200" o {
numberTarget = 200

"box width is still 200 dp" o { onNodeWithTag("mybox").assertWidthIsEqualTo(200.dp) }
"box width is still 200 dp" o { onNodeWithTag("mybox").assertWidthIsEqualTo(200.dp) }

"On 40ms in" o {
mainClock.advanceTimeBy(40)
"On 40ms in" o {
mainClock.advanceTimeBy(40)

"box width has increased a bit" o { onNodeWithTag("mybox").assertWidthIsAtLeast(205.dp) }
"box width has increased a bit" o { onNodeWithTag("mybox").assertWidthIsAtLeast(205.dp) }

"On more than full second in" o {
mainClock.advanceTimeBy(1000)
"On more than full second in" o {
mainClock.advanceTimeBy(1000)

"box width is 300" o { onNodeWithTag("mybox").assertWidthIsEqualTo(300.dp) }
}
}
}
"box width is 300" o { onNodeWithTag("mybox").assertWidthIsEqualTo(300.dp) }
}
}
}
}
}
}
}
}
Loading

0 comments on commit fee242f

Please sign in to comment.