diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ee574d6..82492d3 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -24,6 +24,12 @@ jobs: - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v5 + with: + files: lcov.info + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: false docs: name: Documentation runs-on: ubuntu-latest diff --git a/README.md b/README.md index 0275e15..a99403e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # JSONSchema2Types -[![Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://rmsrosa.github.io/JSONSchema2Types.jl/dev/) [![CI](https://github.com/rmsrosa/JSONSchema2Types.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/rmsrosa/JSONSchema2Types.jl/actions/workflows/CI.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![GitHub repo size](https://img.shields.io/github/repo-size/rmsrosa/JSONSchema2Types.jl) +[![Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://rmsrosa.github.io/JSONSchema2Types.jl/dev/) [![CI](https://github.com/rmsrosa/JSONSchema2Types.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/rmsrosa/JSONSchema2Types.jl/actions/workflows/CI.yml) [![codecov](https://codecov.io/gh/rmsrosa/JSONSchema2Types.jl/graph/badge.svg)](https://codecov.io/gh/rmsrosa/JSONSchema2Types.jl) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![GitHub repo size](https://img.shields.io/github/repo-size/rmsrosa/JSONSchema2Types.jl) Generate Julia types from a [JSON Schema](https://json-schema.org), together with functions to read and write JSON documents that conform to the schema. diff --git a/test/runtests.jl b/test/runtests.jl index 92de188..e98b1d9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,10 +13,27 @@ module. Returns the generated module. function load_generated(schema; split = false, kwargs...) output = joinpath(mktempdir(), split ? "generated" : "generated.jl") file = generate_module(schema, output; split, kwargs...) + split || include_runtime_sources!(file) # the file contains a single `module ... end`, which evaluates to the module itself return Base.include(Module(), file) end +# A generated file contains a copy of the runtime code of the package (`src/runtime*.jl`). +# Replace each copy by an `include` of its source file, the same code, so that the code +# coverage of the tests is recorded for the source files. +const RUNTIME_SOURCES = [JSONSchema2Types.RUNTIME_CODE => "runtime.jl", + JSONSchema2Types.VALIDATION_CODE => "runtime_validation.jl", + JSONSchema2Types.FORMATS_CODE => "runtime_formats.jl"] +function include_runtime_sources!(file) + code = read(file, String) + for (source, name) in RUNTIME_SOURCES + path = joinpath(pkgdir(JSONSchema2Types), "src", name) + code = replace(code, source => "include(" * repr(path) * ")\n"; count = 1) + end + write(file, code) + return file +end + # Compare JSON values regardless of the order of keys and of `1` vs `1.0`. canon(x::AbstractDict) = Dict(String(k) => canon(v) for (k, v) in x) canon(x::AbstractVector) = Any[canon(v) for v in x]