Skip to content

Commit 1ad2e93

Browse files
raganhanalmann
authored andcommitted
Migrate to new spec (#106)
Migrated tests from old spec to PTS spec Also fixes a multiple PTS bugs and integrates it with the ref implementation * set_default_environment can be a file path or a struct with the environment * equality for struct elements were using Ion equality instead of PTS equality * Interpolation now accepts both $variable or ${variable} when interpolating strings * using absolute path for test files in errors for better error reporting * JUnitRunner generated name now includes the test location location along with the test id
1 parent b89f1d8 commit 1ad2e93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+403469
-242
lines changed

pts/test/org/partiql/lang/pts/PartiQlPtsEvaluator.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ class PartiQlPtsEvaluator(equality: PtsEquality) : Evaluator(equality) {
3333
}
3434

3535
private fun runTest(test: TestExpression): TestResult = try {
36-
val ionStruct = test.environment
36+
// recreate the environment struct using the evaluator ion system
37+
val ionStruct = ion.newValue(ion.newReader(test.environment).apply { next() }) as IonStruct
3738

38-
val reader = ion.newReader(ionStruct)
39-
reader.next()
4039

41-
val globals = compilerPipeline.valueFactory.newFromIonValue(ion.newValue(reader) as IonStruct).bindings
40+
val globals = compilerPipeline.valueFactory.newFromIonValue(ionStruct).bindings
4241
val session = EvaluationSession.build { globals(globals) }
4342
val expression = compilerPipeline.compile(test.statement)
4443
val actualResult = expression.eval(session).toPtsIon()
@@ -75,7 +74,7 @@ class PartiQlPtsEvaluator(equality: PtsEquality) : Evaluator(equality) {
7574
LIST -> this.foldToIonSequence(ion.newEmptyList())
7675
SEXP -> this.foldToIonSequence(ion.newEmptySexp())
7776
STRUCT -> this.fold(ion.newEmptyStruct()) { struct, el ->
78-
struct.apply { put(el.asNamed().name.stringValue(), el.toPtsIon()) }
77+
struct.apply { add(el.name!!.stringValue(), el.toPtsIon()) }
7978
}
8079
BAG -> {
8180
val bag = ion.newEmptySexp().apply { add(ion.newSymbol("bag")) }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.partiql.lang.pts
2+
3+
import org.partiql.testscript.evaluator.Evaluator
4+
import org.partiql.testscript.evaluator.PtsEquality
5+
import org.partiql.testscript.junitRunner.Junit4PtsTest
6+
7+
// TODO move this back into lang when testscript is its own pkg
8+
9+
/**
10+
* Runs all tests from PTS as Junit tests
11+
*/
12+
class PtsTest : Junit4PtsTest() {
13+
14+
override fun getEvaluator(): Evaluator = PartiQlPtsEvaluator(PtsEquality.getDefault())
15+
16+
override fun getPtsFilePaths() = listOf("../testscript/pts/test-scripts")
17+
18+
}

testscript/Readme.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,22 @@ successfully or produce an error:
3737
Changes the default environment for the current file. The initial default environment is the empty environment.
3838

3939
```ion
40-
set_default_environment::<struct, required - new default environment>
40+
set_default_environment::<struct|string, required - new default environment>
4141
```
4242

43+
When `set_default_environment` is a `string` it denotes the relative file path to an ion file that contains
44+
the environment.
45+
4346
### for
4447

45-
A `for` function contains a `template` and `variableSet`. Each `test` in the template is performed once for
46-
each `variableSet` by substituting a `variableSet`'s name/value pairs into corresponding placeholders in a `test`.
48+
A `for` function contains a `template` and `variable_set`. Each `test` in the template is performed once for
49+
each `variable_set` by substituting a `variable_set`'s name/value pairs into corresponding placeholders in
50+
the template.
4751

4852
```ion
4953
for::{
50-
template: <list of tests, required - list of templated PTS functions to be interpolated>,
51-
variableSets: <list of structs, required - list of variables used to interpolate the template>,
54+
template: <list of tests, required - list of templated PTS tests to be interpolated>,
55+
variable_sets: <list of structs, required - list of variables used to interpolate the template>,
5256
}
5357
```
5458

@@ -64,7 +68,7 @@ for::{
6468
expected: (success $expected)
6569
}
6670
],
67-
variableSets: [
71+
variable_sets: [
6872
{ value: 1, expected: 2 },
6973
{ value: 10, expected: 11 },
7074
]

testscript/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ dependencies {
1414
// test dependencies
1515
testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.1"
1616
testImplementation "org.junit.jupiter:junit-jupiter-params:5.3.1"
17+
18+
testImplementation 'com.amazon.ion:ion-kotlin-builder:1.0.1'
19+
1720
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.3.1"
1821
}
1922

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tests inside this directory are not run as part of the `integration-test` target. They may be failing or too slow

0 commit comments

Comments
 (0)