Skip to content

Commit 7fab703

Browse files
authored
fix: stabilize Kotlin, Scala, and Rust runtime tests (#2415)
1 parent e7d1dee commit 7fab703

File tree

15 files changed

+47
-35
lines changed

15 files changed

+47
-35
lines changed

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ ENV PATH="${PATH}:/usr/local/go/bin"
1717

1818
# Install dotnet SDK
1919
RUN apt install apt-transport-https dirmngr gnupg ca-certificates -yq \
20-
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
21-
&& echo "deb https://download.mono-project.com/repo/ubuntu stable-jammy main"| tee /etc/apt/sources.list.d/mono-official-stable.list \
2220
&& apt update -yq \
2321
&& apt install mono-devel -yq
2422

src/generators/rust/RustRenderer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { FormatHelpers } from '../../helpers/FormatHelpers';
55
import {
66
deriveCopy,
77
deriveHash,
8-
derivePartialEq,
98
deriveEq,
109
derivePartialOrd,
1110
deriveOrd
@@ -37,16 +36,20 @@ export abstract class RustRenderer<
3736
}
3837

3938
renderMacro(model: ConstrainedMetaModel): string {
40-
const derive: string[] = ['Serialize', 'Deserialize', 'Clone', 'Debug'];
39+
const derive: string[] = [
40+
'Serialize',
41+
'Deserialize',
42+
'Clone',
43+
'Debug',
44+
'PartialEq'
45+
];
46+
4147
if (deriveHash(model)) {
4248
derive.push('Hash');
4349
}
4450
if (deriveCopy(model)) {
4551
derive.push('Copy');
4652
}
47-
if (derivePartialEq(model)) {
48-
derive.push('PartialEq');
49-
}
5053
if (deriveEq(model)) {
5154
derive.push('Eq');
5255
}
@@ -56,6 +59,7 @@ export abstract class RustRenderer<
5659
if (deriveOrd(model)) {
5760
derive.push('Ord');
5861
}
62+
5963
derive.sort();
6064
return `#[derive(${derive.join(', ')})]`;
6165
}

src/generators/scala/ScalaConstrainer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Constraints } from '../../helpers';
2-
import { ConstrainedEnumValueModel } from '../../models';
2+
import { ConstrainedEnumValueModel, ConstrainedEnumModel } from '../../models';
33
import {
44
defaultEnumKeyConstraints,
55
defaultEnumValueConstraints
@@ -78,6 +78,9 @@ export const ScalaDefaultTypeMapping: ScalaTypeMapping = {
7878
return constrainedModel.name;
7979
},
8080
Reference({ constrainedModel }): string {
81+
if (constrainedModel.ref instanceof ConstrainedEnumModel) {
82+
return `${constrainedModel.name}.Value`;
83+
}
8184
return constrainedModel.name;
8285
},
8386
Any(): string {

test/generators/rust/RustRenderer.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,13 @@ describe('RustRenderer', () => {
550550
);
551551

552552
expect(renderer.renderMacro(arrayModel)).toEqual(
553-
'#[derive(Clone, Debug, Deserialize, Serialize)]'
553+
'#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]'
554554
);
555555
expect(renderer.renderMacro(enumModel)).toEqual(
556-
'#[derive(Clone, Debug, Deserialize, Serialize)]'
556+
'#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]'
557557
);
558558
expect(renderer.renderMacro(objectModel)).toEqual(
559-
'#[derive(Clone, Debug, Deserialize, Serialize)]'
559+
'#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]'
560560
);
561561
});
562562
});

test/generators/rust/presets/__snapshots__/CommonPreset.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl Default for CustomEnum {
194194

195195
exports[`RUST_COMMON_PRESET Enum should render reserved union for dict array 1`] = `
196196
"// Class represents a Class model.
197-
#[derive(Clone, Debug, Deserialize, Serialize)]
197+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
198198
pub struct Class {
199199
#[serde(rename=\\"students\\")]
200200
pub students: Vec<crate::Student>,
@@ -215,7 +215,7 @@ impl Class {
215215

216216
exports[`RUST_COMMON_PRESET Enum should render reserved union for dict array 2`] = `
217217
"// Student represents a Student model.
218-
#[derive(Clone, Debug, Deserialize, Serialize)]
218+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
219219
pub struct Student {
220220
#[serde(rename=\\"name\\")]
221221
pub name: String,
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { execCommand } from '../TestUtils/GeneralUtils';
22
import path from 'path';
33

4-
jest.setTimeout(50000);
4+
jest.setTimeout(500000);
55

66
test('Kotlin runtime testing', async () => {
7+
const generateCommand = 'npm run generate:runtime:kotlin';
8+
await execCommand(generateCommand, true);
79
//The 'build' command here
810
const buildCommand = `cd ${path.resolve(
911
__dirname,
1012
'./runtime-kotlin'
1113
)} && ./gradlew build`;
12-
await execCommand(buildCommand);
14+
await execCommand(buildCommand, true);
1315
//The 'test' command here
1416
const testCommand = `cd ${path.resolve(
1517
__dirname,
1618
'./runtime-kotlin'
1719
)} && ./gradlew test`;
18-
await execCommand(testCommand);
20+
await execCommand(testCommand, true);
1921
});

test/runtime/runtime-kotlin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { KOTLIN_DEFAULT_PRESET, KotlinFileGenerator } from '../../';
1+
import { KOTLIN_DEFAULT_PRESET, KotlinFileGenerator } from '../../src';
22
import path from 'path';
33
import input from './generic-input.json';
44

test/runtime/runtime-kotlin/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ dependencies {
1010
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
1111
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.1")
1212
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
13+
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.14.2'
14+
testImplementation 'org.hamcrest:hamcrest:2.2'
1315
}

test/runtime/runtime-kotlin/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
1+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStorePath=wrapper/dists

test/runtime/runtime-kotlin/src/test/kotlin/com/mycompany/app/generic/AddressTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
44
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
55
import org.hamcrest.CoreMatchers.containsString
66
import org.hamcrest.CoreMatchers.not
7+
import org.hamcrest.MatcherAssert.assertThat
78
import org.junit.jupiter.api.Assertions.assertTrue
89
import org.junit.jupiter.api.Test
910
import org.junit.jupiter.api.BeforeEach
@@ -18,11 +19,11 @@ class AddressTest {
1819
fun setup() {
1920
address = Address(
2021
streetName = "Test address 2",
21-
houseNumber = 2,
22+
houseNumber = 2.0,
2223
marriage = true,
2324
members = 2,
2425
arrayType = listOf(2, "test"),
25-
nestedObject = Address.NestedObject(test = "test")
26+
nestedObject = NestedObject(test = "test")
2627
)
2728
}
2829

0 commit comments

Comments
 (0)