Skip to content

Commit

Permalink
Prepare for multilanguage monorepo development (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Jan 29, 2024
2 parents de80a0c + 6c92156 commit 8f2f847
Show file tree
Hide file tree
Showing 213 changed files with 80 additions and 51 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ name: "Validate Gradle Wrapper"
on:
push:
paths:
- 'gradlew'
- 'gradlew.bat'
- 'gradle/wrapper/'
- 'jvm/gradlew'
- 'jvm/gradlew.bat'
- 'jvm/gradle/wrapper/'
pull_request:
paths:
- 'gradlew'
- 'gradlew.bat'
- 'gradle/wrapper/'

- 'jvm/gradlew'
- 'jvm/gradlew.bat'
- 'jvm/gradle/wrapper/'
permissions:
contents: read

defaults:
run:
working-directory: jvm
jobs:
validation:
name: "Validation"
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml → .github/workflows/jvm-ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
on:
pull_request:
push:
branches: [main]
pull_request:
paths:
- 'jvm/*'
defaults:
run:
working-directory: jvm
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# GRADLE_KEY
# GRADLE_SECRET

name: deploy
on:
workflow_dispatch:
inputs:
Expand All @@ -21,7 +20,9 @@ on:
type: choice
options:
- all

defaults:
run:
working-directory: jvm
jobs:
build:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
on:
push:
branches: [release]
paths:
- 'jvm/*'
defaults:
run:
working-directory: jvm
jobs:
publish:
runs-on: ubuntu-latest
Expand Down
17 changes: 5 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
# Contributing to Selfie

- If you want to improve our webpage, [selfie.dev](https://selfie.dev), go to [`docs/README.md`](docs/README.md)
- If you want to remove the webpage of our published kdoc, [kdoc.selfie.dev](https://kdoc.selfie.dev), go to [`gradle/dokka/README.md`](gradle/dokka/README.md)
- If you want to contribute to the Kotlin Multiplatform implementation of selfie (jvm, js, wasm) use the gradle instructions below
- If you want to contribute for a different platform (python, go, etc.) we'd love to help, but it should probably live in a different repo. Discuss in [selfie#85](https://github.com/diffplug/selfie/issues/85), but also feel free to open a PR with any ideas you have.

- To improve our webpage go to [`selfie.dev/README.md`](selfie.dev/README.md)
- To improve our JVM, Javascript, or WASM implementations, go to [`jvm/README.md`](jvm/README.md)
- To improve the webpage of our published kdoc, [kdoc.selfie.dev](https://kdoc.selfie.dev), go to [`jvm/gradle/dokka/README.md`](jvm/gradle/dokka/README.md)
- To contribute for a different platform (python, go, etc.) we're happy to help! It should probably live in a different repo until it's close to `1.0`, but once it's near completion we're happy to maintain it here if you would like. Discuss in [selfie#85](https://github.com/diffplug/selfie/issues/85), but also feel free to open a PR with any ideas you have.

Pull requests are very welcome, preferably against `main`.

## Build instructions

It's a standard Gradle build, `./gradlew build` to assemble and test everything.

One tricky thing is that inline snapshots requires changing the code being tested. To make this work, we have `undertest` projects. Their `test` task is disabled, and they have an `underTest` task instead. You'll note that every test in these projects is named `UT_SomethingTest`. That's because there is a corresponding `SomethingTest` in `selfie-runner-junit5` , and `SomethingTest` works by changing the source code in `UT_SomethingTest`, running builds, and making assertions about the state of snapshots and source code after the build.

## License

By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/diffplug/atplug/blob/master/LICENSE
By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/diffplug/selfie/blob/master/LICENSE

All files are released with the Apache 2.0 license as such:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <img align="left" src="docs/selfie_logo_only.png"> Selfie
# <img align="left" src="selfie.dev/selfie_logo_only.png"> Selfie

Snapshot testing for the JVM.

Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md → jvm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.
Changelog for the selfie JVM libraries.

- [`com.diffplug.selfie:selfie-lib:VERSION`](https://central.sonatype.com/artifact/com.diffplug.selfie/selfie-lib)
- [`com.diffplug.selfie:selfie-runner-junit5:VERSION`](https://central.sonatype.com/artifact/com.diffplug.selfie/selfie-runner-junit5)
- can be used with JUnit4 via [junit-vintage](https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4)

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
Expand Down
11 changes: 11 additions & 0 deletions jvm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Selfie snapshot testing for Java, Kotlin, and the JVM

- [Quickstart](https://selfie.dev/jvm/get-started)
- [Advanced](https://selfie.dev/jvm/advanced)
- [Why selfie](https://selfie.dev/jvm)

## Contributing

PR's welcome! It's a standard Gradle build, `./gradlew build` to assemble and test everything.

One tricky thing is that testing inline snapshots requires changing the code being tested. To make this work, we have `undertest` projects. Their `test` task is disabled, and they have an `underTest` task instead. You'll note that every test in these projects is named `UT_SomethingTest`. That's because there is a corresponding `SomethingTest` in `selfie-runner-junit5` , and `SomethingTest` works by changing the source code in `UT_SomethingTest`, running builds, and making assertions about the state of snapshots and source code after the build.
4 changes: 4 additions & 0 deletions build.gradle → jvm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ plugins {
repositories {
mavenCentral()
}
spotlessChangelog {
tagPrefix 'jvm/'
commitMessage 'Published jvm/{{version}}'
}
group =.proj('maven_group', 'the maven group, recommend com.diffplug')
apply from: rootProject.file('gradle/spotless.gradle')
apply from: 干.file('base/changelog.gradle')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class SnapshotValueReader(val lineReader: LineReader) {
private const val FLAG_BASE64 = " ═╗ base64"

/**
* https://github.com/diffplug/selfie/blob/main/selfie-lib/src/commonTest/resources/com/diffplug/selfie/scenarios_and_lenses.ss
* https://github.com/diffplug/selfie/blob/main/jvm/selfie-lib/src/commonTest/resources/com/diffplug/selfie/scenarios_and_lenses.ss
*/
internal val nameEsc = PerCharacterEscaper.specifiedEscape("\\\\[(])\nn\tt╔┌╗┐═─")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016-2023 DiffPlug
* Copyright (C) 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 DiffPlug
* Copyright (C) 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
5 changes: 0 additions & 5 deletions settings.gradle → jvm/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ plugins {
blowdryerSetup {
github 'diffplug/blowdryer-diffplug', 'tag', '7.2.0'
//devLocal '../blowdryer-diffplug'
setPluginsBlockTo {
it.file 'plugin.versions'
it.file 'plugin-kotlin.versions'
it.replace('\t', ' ')
}
}

include 'selfie-lib'
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 11 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
],
"packageRules": [
{
"paths": ["selfie.dev/"],
"labels": ["selfie.dev"]
},
{
"paths": ["jvm/"],
"labels": ["jvm"]
}
]
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Assuming you have [installed selfie](/jvm/get-started#installation) and glanced

## Our toy project

We'll be using the [`example-junit5`](https://github.com/diffplug/selfie/tree/main/example-junit5) project from the selfie GitHub repo. You can clone the code and follow along, but there's no need to. If you did clone the project, you could run `gradlew exampleAppJvm` and you'd have a little [jooby](https://jooby.io/) webapp running at `localhost:8080`.
We'll be using the [`example-junit5`](https://github.com/diffplug/selfie/tree/main/jvm/example-junit5) project from the selfie GitHub repo. You can clone the code and follow along, but there's no need to. If you did clone the project, you could run `gradlew exampleAppJvm` and you'd have a little [jooby](https://jooby.io/) webapp running at `localhost:8080`.

It has a homepage where we can login. We can go to `/email` to see the emails the server has sent and click our login link, and boom we've got some auth cookies.

Expand Down Expand Up @@ -196,7 +196,7 @@ private static final Lens HTML = new CompoundLens()
Snapshot testing has been badly underused for three reasons:

- controlling read vs write used to be cumbersome (fixed by [control comments](https://selfie.dev/jvm/get-started#quickstart))
- stale snapshots used to pile up (fixed by [garbage collection](https://github.com/diffplug/selfie/blob/main/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/SelfieGC.kt))
- stale snapshots used to pile up (fixed by [garbage collection](https://github.com/diffplug/selfie/blob/main/jvm/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/SelfieGC.kt))
- a great test should tell a story, and disk snapshots can't do that

Inline snapshots are a partial fix for storytelling within a test, but the harnessing can become verbose. This is where we combine it all:
Expand Down Expand Up @@ -237,7 +237,7 @@ status code: 401""");
}
```

We just wrote a high-level specification of a realistic login flow, and it only took 25 lines of java code — most of which were generated for us, and could be regenerated on a whim if we want to change our copywriting. The [corresponding disk snapshot](https://github.com/diffplug/selfie/blob/main/example-junit5/src/test/java/com/example/LoginFlowTest.ss) gives us an exhaustive specification and description of the server's behavior.
We just wrote a high-level specification of a realistic login flow, and it only took 25 lines of java code — most of which were generated for us, and could be regenerated on a whim if we want to change our copywriting. The [corresponding disk snapshot](https://github.com/diffplug/selfie/blob/main/jvm/example-junit5/src/test/java/com/example/LoginFlowTest.ss) gives us an exhaustive specification and description of the server's behavior.

Didn't think that adopting a bugfixed version of your internationalization lib would cause any changes to your website whatsever? Oops. Don't wade through failed assertions, get a diff in every failure. If you want, regenerate all the snapshots to get a full view of the problem across the whole codebase in your git client.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Disk snapshots can be used with any JVM language, but inline literal snapshots o
- groovy
- scala

Adding support for other languages is [straightforward](https://github.com/diffplug/selfie/blob/main/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/guts/Literals.kt), PRs are welcome!
Adding support for other languages is [straightforward](https://github.com/diffplug/selfie/blob/main/jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/guts/Literals.kt), PRs are welcome!

### Maven

Expand All @@ -40,7 +40,7 @@ If you're using Maven, add the following dependency to your `pom.xml` file:
</dependency>
```

Replace `LATEST_VERSION` with the [latest available version of selfie](https://github.com/diffplug/selfie/blob/main/CHANGELOG.md).
Replace `LATEST_VERSION` with the [latest available version of selfie](https://github.com/diffplug/selfie/blob/main/jvm/CHANGELOG.md).

### Gradle

Expand All @@ -50,7 +50,7 @@ For Gradle users, add this to your `build.gradle` file:
testImplementation 'com.diffplug.selfie:selfie-runner-junit5:LATEST_VERSION'
```

Again, replace `LATEST_VERSION` with the [latest available version of selfie](https://github.com/diffplug/selfie/blob/main/CHANGELOG.md).
Again, replace `LATEST_VERSION` with the [latest available version of selfie](https://github.com/diffplug/selfie/blob/main/jvm/CHANGELOG.md).

## Quickstart

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8f2f847

Please sign in to comment.