Skip to content

Commit

Permalink
Add in metadata and format tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richardreeve committed Oct 23, 2024
1 parent 6f5f201 commit bd09a2d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/clean_JuliaFormatter.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-License-Identifier: BSD-2-Clause

module CleanJuliaFormatter
using Test
using TraitExtraction
using Git
using Logging
using Pkg
using JuliaFormatter

function is_repo_clean(repo_path; ignore_untracked = true)
# Get the status of the repository
statuses = readlines(`$(Git.git()) status -s $repo_path`)

if ignore_untracked
# Repo must be clean except for untracked files
statuses = filter((!) contains("??"), statuses)
end

is_clean = isempty(statuses)

# If not clean then report on dirty files
is_clean || @error "\n" * join(statuses, "\n")

return is_clean
end

# Metadata crosswalk testing only works on Julia v1.8 and after due to Project.toml changes
# Also does not currently work on Windows runners on GitHub due to file writing issues
if VERSION VersionNumber("1.8.0") &&
(!haskey(ENV, "RUNNER_OS") || ENV["RUNNER_OS"] "Windows")
@testset "JuliaFormatter" begin
git_dir = readchomp(`$(Git.git()) rev-parse --show-toplevel`)
@test_nowarn format(TraitExtraction)
@test is_repo_clean(git_dir)
end
else
@test_broken VERSION VersionNumber("1.8.0") &&
(!haskey(ENV, "RUNNER_OS") || ENV["RUNNER_OS"] "Windows")
end

end
44 changes: 44 additions & 0 deletions test/clean_ResearchSoftwareMetadata.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SPDX-License-Identifier: BSD-2-Clause

module CleanRSMD
using Test
using TraitExtraction
using Git
using Logging
using Pkg
using ResearchSoftwareMetadata

function is_repo_clean(repo_path; ignore_untracked = true)
# Get the status of the repository
statuses = readlines(`$(Git.git()) status -s $repo_path`)

if ignore_untracked
# Repo must be clean except for untracked files
statuses = filter((!) contains("??"), statuses)
end

is_clean = isempty(statuses)

# If not clean then report on dirty files
is_clean || @error "\n" * join(statuses, "\n")

return is_clean
end

# Metadata crosswalk testing only works on Julia v1.8 and after due to Project.toml changes
# Also does not currently work on Windows runners on GitHub due to file writing issues
if VERSION VersionNumber("1.8.0") &&
(!haskey(ENV, "RUNNER_OS") || ENV["RUNNER_OS"] "Windows")
@testset "RSMD" begin
git_dir = readchomp(`$(Git.git()) rev-parse --show-toplevel`)
@test isnothing(ResearchSoftwareMetadata.crosswalk())
global_logger(SimpleLogger(stderr, Logging.Warn))
@test_nowarn ResearchSoftwareMetadata.crosswalk()
@test is_repo_clean(git_dir)
end
else
@test_broken VERSION VersionNumber("1.8.0") &&
(!haskey(ENV, "RUNNER_OS") || ENV["RUNNER_OS"] "Windows")
end

end

0 comments on commit bd09a2d

Please sign in to comment.