From 5ce2280e762f7db930e7e9abfc21af77d74bca01 Mon Sep 17 00:00:00 2001 From: Daniel Thom Date: Wed, 5 Feb 2020 18:32:43 -0700 Subject: [PATCH 1/2] Ignore line endings when comparing generated structs --- test/test_generate_structs.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/test_generate_structs.jl b/test/test_generate_structs.jl index 7a452b21f..1d2e3e874 100644 --- a/test/test_generate_structs.jl +++ b/test/test_generate_structs.jl @@ -11,10 +11,9 @@ matched = true try - run(`diff $output_dir $existing_dir`) - catch - (err) - @error "Generated structs do not match the descriptor file." + 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) From 993a389c6ebec32428edd3085e34255c0a1fc377 Mon Sep 17 00:00:00 2001 From: Daniel Thom Date: Wed, 5 Feb 2020 20:10:41 -0700 Subject: [PATCH 2/2] Move test_generate_structs to package This will allow other packages to use this functionality without duplicating it. --- src/utils/generate_structs.jl | 28 ++++++++++++++++++++++++++++ test/test_generate_structs.jl | 20 +------------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/utils/generate_structs.jl b/src/utils/generate_structs.jl index 9bbec68a9..5570b8ea1 100644 --- a/src/utils/generate_structs.jl +++ b/src/utils/generate_structs.jl @@ -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 diff --git a/test/test_generate_structs.jl b/test/test_generate_structs.jl index 1d2e3e874..47cc84530 100644 --- a/test/test_generate_structs.jl +++ b/test/test_generate_structs.jl @@ -1,23 +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 --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 - - @test matched + @test IS.test_generated_structs(descriptor_file, existing_dir) end