From 2df76e3d54f3663ed3dbc3cb217d8d5283bd8859 Mon Sep 17 00:00:00 2001 From: William Johnson Date: Fri, 15 Mar 2024 14:59:47 -0700 Subject: [PATCH] Fix failing Reference Line test. Adding user-defined reference lines broke this test, as user writable data directory isnt defined when running tests. --- src/ReferenceLineInfo.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/ReferenceLineInfo.cpp b/src/ReferenceLineInfo.cpp index dc9811a1..5206188d 100644 --- a/src/ReferenceLineInfo.cpp +++ b/src/ReferenceLineInfo.cpp @@ -348,12 +348,26 @@ namespace load_ref_line_file( add_lines_path, *nuc_mixes, *custom_lines ); #if( BUILD_AS_ELECTRON_APP || IOS || ANDROID || BUILD_AS_OSX_APP || BUILD_AS_LOCAL_SERVER || BUILD_AS_WX_WIDGETS_APP || BUILD_AS_UNIT_TEST_SUITE ) - const string user_data_dir = InterSpec::writableDataDirectory(); - const string custom_lines_path = SpecUtils::append_path( user_data_dir, "add_ref_line.xml" ); - // Any duplicate names, will overwrite what comes with InterSpec - if( SpecUtils::is_file( custom_lines_path ) ) - load_ref_line_file( custom_lines_path, *nuc_mixes, *custom_lines ); + string user_data_dir; + + // `InterSpec::writableDataDirectory()` will throw if it hasnt been set. + // - e.g., in testing or batch mode + try + { + user_data_dir = InterSpec::writableDataDirectory(); + }catch( std::exception & ) + { + }//try / catch + + if( !user_data_dir.empty() ) + { + const string custom_lines_path = SpecUtils::append_path( user_data_dir, "add_ref_line.xml" ); + + // Any duplicate names, will overwrite what comes with InterSpec + if( SpecUtils::is_file( custom_lines_path ) ) + load_ref_line_file( custom_lines_path, *nuc_mixes, *custom_lines ); + }//if( !user_data_dir.empty() ) #endif sm_nuc_mixes = nuc_mixes;