Skip to content

Commit

Permalink
Merge pull request #56 from daniel-thom/test-windows-fix
Browse files Browse the repository at this point in the history
Ignore line endings when comparing generated structs
  • Loading branch information
jd-lara authored Feb 6, 2020
2 parents 20ea289 + 993a389 commit 3dcc96f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
28 changes: 28 additions & 0 deletions src/utils/generate_structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,31 @@ function generate_structs(
data = read_json_data(input_file)
generate_structs(output_directory, data, print_results = print_results)
end

"""
test_generated_structs(descriptor_file, existing_dir)
Return true if the structs defined in existing_dir match structs freshly-generated
from descriptor_file.
"""
function test_generated_structs(descriptor_file, existing_dir)
output_dir = "tmp-test-generated-structs"
if isdir(output_dir)
rm(output_dir; recursive = true)
end
mkdir(output_dir)

generate_structs(descriptor_file, output_dir; print_results = false)

matched = true
try
run(`diff --strip-trailing-cr $output_dir $existing_dir`)
catch err
@error "Generated structs do not match the descriptor file." err
matched = false
finally
rm(output_dir; recursive = true)
end

return matched
end
21 changes: 1 addition & 20 deletions test/test_generate_structs.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
@testset "Test generated structs" begin
descriptor_file = joinpath(@__DIR__, "..", "src", "descriptors", "structs.json")
existing_dir = joinpath(@__DIR__, "..", "src", "generated")
output_dir = "tmp-test-generated-structs"
if isdir(output_dir)
rm(output_dir; recursive = true)
end
mkdir(output_dir)

IS.generate_structs(descriptor_file, output_dir; print_results = false)

matched = true
try
run(`diff $output_dir $existing_dir`)
catch
(err)
@error "Generated structs do not match the descriptor file."
matched = false
finally
rm(output_dir; recursive = true)
end

@test matched
@test IS.test_generated_structs(descriptor_file, existing_dir)
end

0 comments on commit 3dcc96f

Please sign in to comment.