Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #11

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI

on:
push:
branches:
- main
paths-ignore:
- 'LICENSE.md'
- 'README.md'
- 'docs/**'
pull_request:
paths-ignore:
- 'LICENSE.md'
- 'README.md'
- 'docs/**'
workflow_dispatch:
inputs:
debug_enabled:
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: "false"

jobs:
test:
name: ${{ matrix.os }} - Julia ${{ matrix.julia_version }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
arch:
- x64
julia_version:
- '1.10'
- '1.11'

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Enable Julia cache
uses: julia-actions/cache@v2

- name: Install Julia
uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.julia_version }}
arch: ${{ matrix.arch }}
show-versioninfo: true

- name: Run Julia tests
uses: julia-actions/julia-runtest@v1
with:
coverage: false
env:
CATALYST_DEBUG: 1

# Enable tmate debugging of manually-triggered workflows if the input option was provided
- name: Setup tmate session for debugging
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled && always() }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 15
31 changes: 31 additions & 0 deletions src/conduit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ struct ConduitNode
nptr = API.conduit_node_create()
return new(nptr)
end

function ConduitNode(ptr::Ptr{API.conduit_node})
return new(ptr)
end
end
Base.unsafe_convert(::Type{Ptr{API.conduit_node}}, node::ConduitNode) = node.ptr

Expand All @@ -23,11 +27,24 @@ function ConduitNode(f::Function)
end

Base.setindex!(node::ConduitNode, val, path::String) = node_set!(node, path, val)
Base.getindex(node::ConduitNode, path::String) = node_get(node, path)

function node_get(node::ConduitNode, path::String)
if !node_has_path(node, path)
throw(KeyError(path))
end
node_at_path = API.conduit_node_fetch(node, path)
dtype = API.conduit_node_dtype(node_at_path)
dtypename = Symbol(unsafe_string(API.conduit_datatype_name(dtype)))
return node_get(node_at_path, Val(dtypename))
end

for numtype in (:UInt8, :Int8, :UInt16, :Int16, :UInt32, :Int32, :UInt64, :Int64, :Float32, :Float64)
cnumtype = Symbol(lowercase("$(numtype)"))
node_set_path = Symbol("conduit_node_set_path_$(cnumtype)")
node_set_path_ptr = Symbol("conduit_node_set_path_$(cnumtype)_ptr")
node_as = Symbol("conduit_node_as_$(cnumtype)")
node_as_ptr = Symbol("conduit_node_as_$(cnumtype)_ptr")
@eval begin
function node_set!(node::ConduitNode, path::String, val::$numtype)
API.$node_set_path(node, path, val)
Expand All @@ -37,6 +54,12 @@ for numtype in (:UInt8, :Int8, :UInt16, :Int16, :UInt32, :Int32, :UInt64, :Int64
API.$node_set_path_ptr(node, path, pointer(val), length(val))
return node
end
function node_get(nodeptr::Ptr{API.conduit_node}, ::$(Val{cnumtype}))
return API.$node_as(nodeptr)
end
function node_get(nodeptr::Ptr{API.conduit_node}, ::$(Val{Array{cnumtype}}))
return API.$node_as_ptr(nodeptr)
end
end
end

Expand All @@ -50,6 +73,14 @@ function node_set!(node::ConduitNode, path::String, val::ConduitNode)
return node
end

function node_get(nodeptr::Ptr{API.conduit_node}, ::Val{:object})
return ConduitNode(nodeptr)
end

function node_get(nodeptr::Ptr{API.conduit_node}, ::Val{:char8_str})
return unsafe_string(API.conduit_node_as_char8_str(nodeptr))
end

function node_has_path(node::ConduitNode, path::String)
return Bool(API.conduit_node_has_path(node, path))
end
Expand Down
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Test

@time @testset verbose=true showtiming=true "ParaViewCatalyst.jl tests" begin
include("test_catalyst_jll.jl")
end
24 changes: 24 additions & 0 deletions test/test_catalyst_jll.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module TestCatalyst_jll

using Test
using ParaViewCatalyst
using ParaViewCatalyst.API

# Manually override the usual initialization and
# - do not provide search paths
# - request the stub implementation
# This test should then pick up the catalyst library shipped with Catalyst_jll
@testset verbose=true showtiming=true "Check stub" begin
ConduitNode() do node
node["catalyst_load/implementation"] = "stub"
catalyst_initialize(node)
end
ConduitNode() do node
status = API.catalyst_about(node)
@test status === API.catalyst_status_ok
@test node["catalyst/implementation"] == "stub"
Conduit.node_print(node, detailed=false)
end
catalyst_finalize()
end
end
Loading