Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
cache: gradle

- uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm
cache-dependency-path: test/typecheck/package-lock.json

- name: Build the generator
working-directory: dts-generator
run: ./gradlew jar

- name: Compare with the expected output
run: make test

- name: Type-check the expected output
run: make test-typecheck
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
testparams.txt
/jars
bin/
/test/kotlin-fixture/build
/test/typecheck/node_modules
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,23 @@ androidx-35:
mv out/android.d.ts out/androidx-35.d.ts

test-compare-output:
rm -f out/android.d.ts out/android-declarations.d.ts
java -jar dts-generator/build/libs/dts-generator.jar \
--input libs
cmp out/android.d.ts test/expected-output/android.d.ts
cmp out/android-declarations.d.ts test/expected-output/android-declarations.d.ts

test-kotlin-fixture:
dts-generator/gradlew -q -p test/kotlin-fixture jar
rm -rf out/kotlin-fixture
java -jar dts-generator/build/libs/dts-generator.jar \
--input test/kotlin-fixture/build/libs/kotlin-fixture.jar --output out/kotlin-fixture
cmp out/kotlin-fixture/android.d.ts test/expected-output/kotlin-fixture/android.d.ts
cmp out/kotlin-fixture/android-declarations.d.ts test/expected-output/kotlin-fixture/android-declarations.d.ts

test: test-compare-output test-kotlin-fixture

test-typecheck:
cd test/typecheck && npm ci --no-audit --no-fund && node check.mjs

androidx-all: androidx-17 androidx-23 androidx-26 androidx-28 androidx-29 androidx-30 androidx-31 androidx-32 androidx-33 androidx-34 androidx-35
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ java -jar build/libs/dts-generator.jar --input <jarFolder>

## Test

In order to test the tool there are some predefined AndroidX packages. We are running the tool and comparing the output with the expected output committed in the repo.
To run the test:
The tests run the tool and compare its output with the expected output committed in the repo. There are two inputs: the predefined AndroidX packages in `libs`, and a small Kotlin and Java library in `test/kotlin-fixture`, built from source, where each declaration exercises one case the generator has to handle.
To run the tests:

```shell
make test-compare-output
make test
```

Then check whether the make command returns an error when comparing the files.
Then check whether the make command returns an error when comparing the files. `make test-compare-output` and `make test-kotlin-fixture` run them one at a time.

> Note: If the contents of the libs folder are changed, the expected output should also be changed
`make test-typecheck` (Node.js required) type-checks the expected output against the published `@nativescript/types-android` platform typings: the Kotlin fixture must have no errors, and the AndroidX output no syntax errors.

> Note: If the contents of the libs folder or the fixture sources are changed, the expected output should also be changed

## Generate definitions for .aar
Pass the aar as input as you would normally do
Expand Down
2 changes: 1 addition & 1 deletion _helpers.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module androidNative {
declare namespace androidNative {
export class Array<T> {
public constructor();
}
Expand Down
18 changes: 11 additions & 7 deletions dts-generator/src/main/java/com/telerik/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,17 @@ public static void main(String[] args) {
}

try {
InputParameters inputParameters = parseCommand(args);
InputParameters inputParameters;
try {
inputParameters = parseCommand(args);
} catch (IllegalArgumentException ex) {
// A malformed command line is the user's mistake, not a crash: say what is wrong and
// how to look up the right spelling, without burying it under a stack trace.
System.err.println("dts-generator: " + ex.getMessage());
System.err.println("Run with " + HELP + " to see the available options.");
System.exit(2);
return;
}

long startTime = System.currentTimeMillis();

Expand All @@ -75,12 +85,6 @@ public static void main(String[] args) {

long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Generation of definitions took " + elapsedTime + "ms.");
} catch (IllegalArgumentException ex) {
// A malformed command line is the user's mistake, not a crash: say what is wrong and
// how to look up the right spelling, without burying it under a stack trace.
System.err.println("dts-generator: " + ex.getMessage());
System.err.println("Run with " + HELP + " to see the available options.");
System.exit(2);
} catch (Throwable ex) {
System.err.println(String.format("Error executing Typescript Definitions Generator: %s", ex.getMessage()));
ex.printStackTrace(System.out);
Expand Down
Loading
Loading