Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pseuco-ide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
10
Issues
10
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pseuco
pseuco-ide
Commits
fd353f40
Verified
Commit
fd353f40
authored
Jun 10, 2019
by
Konstantin Kopper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added compiler tests
parent
b24e9394
Pipeline
#7543
passed with stages
in 6 minutes and 6 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
0 deletions
+122
-0
.gitmodules
.gitmodules
+4
-0
src/test/kotlin/pseuco/javaCompiler/CompilerTests.kt
src/test/kotlin/pseuco/javaCompiler/CompilerTests.kt
+117
-0
src/test/resources/pseuco-tests
src/test/resources/pseuco-tests
+1
-0
No files found.
.gitmodules
View file @
fd353f40
[submodule "lib/pseuco-java-compiler"]
path = lib/pseuco-java-compiler
url = ../pseuco-java-compiler.git
[submodule "src/test/resources/pseuco-tests"]
path = src/test/resources/pseuco-tests
url = ../pseuco-tests.git
src/test/kotlin/pseuco/javaCompiler/CompilerTests.kt
0 → 100644
View file @
fd353f40
package
pseuco.javaCompiler
import
kotlinx.io.ByteArrayOutputStream
import
kotlinx.serialization.CompositeDecoder
import
kotlinx.serialization.Decoder
import
kotlinx.serialization.KSerializer
import
kotlinx.serialization.SerialDescriptor
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.SerializationException
import
kotlinx.serialization.Serializer
import
kotlinx.serialization.UnstableDefault
import
kotlinx.serialization.internal.SerialClassDescImpl
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.list
import
kotlinx.serialization.serializer
import
org.junit.jupiter.api.Assertions.assertEquals
import
org.junit.jupiter.api.Assertions.assertIterableEquals
import
org.junit.jupiter.api.Assertions.assertTimeoutPreemptively
import
org.junit.jupiter.api.Assumptions.assumeTrue
import
org.junit.jupiter.api.DynamicTest.dynamicTest
import
org.junit.jupiter.api.TestFactory
import
org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable
import
org.junit.jupiter.api.fail
import
pseuco.javaCompiler.runner.PseuCoRunner
import
java.io.File
import
java.time.Duration
import
kotlin.reflect.full.functions
import
kotlin.reflect.jvm.isAccessible
@UnstableDefault
@DisabledIfEnvironmentVariable
(
named
=
"CI"
,
matches
=
"true"
)
class
CompilerTests
{
private
val
tests
=
File
(
this
::
class
.
java
.
getResource
(
"/pseuco-tests/tests"
).
toURI
())
.
listFiles
{
f
->
f
.
extension
==
"json"
}
.
map
{
f
->
Json
.
parse
(
CompilerTestConfig
.
serializer
(),
f
.
readText
()).
let
{
CompilerTest
(
File
(
f
.
absolutePath
.
replace
(
Regex
(
"json$"
),
"pseuco"
)),
"${it.description} (${f.nameWithoutExtension})"
,
it
.
correctnessProperties
)
}
}
@TestFactory
fun
compilerTests
()
=
tests
.
map
{
test
->
test
.
correctnessProperties
.
map
{
cp
->
dynamicTest
(
test
.
description
)
{
assumeTrue
(
cp
is
CorrectnessProperty
.
DeterministicOutput
)
{
"Correctness property '${cp.type}' is currently unsupported."
}
val
outStream
=
ByteArrayOutputStream
()
val
errStream
=
ByteArrayOutputStream
()
val
joinFunction
=
PseuCoCompilerTask
::
class
.
functions
.
find
{
it
.
name
==
"joinAgents"
}
!!
.
apply
{
isAccessible
=
true
}
PseuCoRunner
(
test
.
file
,
outStream
,
errStream
).
apply
{
onError
{
fail
(
it
)
}
assertTimeoutPreemptively
(
Duration
.
ofSeconds
(
2
))
{
run
()
}
}.
also
{
joinFunction
.
call
(
it
)
}
val
output
=
outStream
.
toString
().
lines
().
filter
{
it
.
isNotEmpty
()
}
when
(
cp
)
{
is
CorrectnessProperty
.
DeterministicOutput
->
{
assertEquals
(
cp
.
output
.
size
,
output
.
size
)
assertIterableEquals
(
cp
.
output
,
output
)
}
else
->
fail
{
"Unsupported correctness property: '${cp.type}'"
}
}
}
}
}.
flatten
()
private
data class
CompilerTest
(
val
file
:
File
,
val
description
:
String
,
val
correctnessProperties
:
List
<
CorrectnessProperty
>)
@Serializable
private
data class
CompilerTestConfig
(
val
description
:
String
,
val
correctnessProperties
:
List
<
CorrectnessProperty
>)
@Serializable
(
with
=
CorrectnessProperty
.
Companion
::
class
)
private
sealed
class
CorrectnessProperty
(
val
type
:
String
)
{
data class
DeterministicOutput
(
val
output
:
List
<
String
>)
:
CorrectnessProperty
(
"deterministicOutput"
)
data class
PossibleOutputs
(
val
possibilities
:
List
<
String
>)
:
CorrectnessProperty
(
"possibleOutputs"
)
@Serializer
(
forClass
=
CorrectnessProperty
::
class
)
companion
object
:
KSerializer
<
CorrectnessProperty
>
{
override
val
descriptor
:
SerialDescriptor
=
object
:
SerialClassDescImpl
(
"CorrectnessProperty"
)
{
init
{
addElement
(
"type"
)
addElement
(
"output"
,
isOptional
=
true
)
addElement
(
"possibilities"
,
isOptional
=
true
)
}
}
override
fun
deserialize
(
decoder
:
Decoder
):
CorrectnessProperty
{
val
structure
=
decoder
.
beginStructure
(
descriptor
)
lateinit
var
type
:
String
lateinit
var
list
:
List
<
String
>
tailrec
fun
decodeAttributes
():
CorrectnessProperty
{
when
(
val
i
=
structure
.
decodeElementIndex
(
descriptor
))
{
CompositeDecoder
.
READ_DONE
->
{
structure
.
endStructure
(
descriptor
)
return
when
(
type
)
{
"deterministicOutput"
->
DeterministicOutput
(
list
)
"possibleOutputs"
->
PossibleOutputs
(
list
)
else
->
throw
SerializationException
(
"Cannot deserialize unknown correctness property '$type'."
)
}
}
0
->
type
=
structure
.
decodeStringElement
(
descriptor
,
i
)
1
,
2
->
list
=
structure
.
decodeSerializableElement
(
descriptor
,
i
,
String
.
serializer
().
list
)
}
return
decodeAttributes
()
}
return
decodeAttributes
()
}
}
}
}
pseuco-tests
@
49428dd6
Subproject commit 49428dd6e424559c3d12fe6fc4fe7853d43385f7
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment