From 658df50e97ac4bc6e65b228d32942375402e15b8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Oct 2022 09:37:05 -0400 Subject: [PATCH] make getenv style variable test fully portable --- unittest/fortran/test_fortran_extract_variable.f90 | 3 +-- unittest/fortran/wrap_extract_variable.cpp | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/unittest/fortran/test_fortran_extract_variable.f90 b/unittest/fortran/test_fortran_extract_variable.f90 index 0b16e61894..da7b2d5835 100644 --- a/unittest/fortran/test_fortran_extract_variable.f90 +++ b/unittest/fortran/test_fortran_extract_variable.f90 @@ -118,8 +118,7 @@ SUBROUTINE f_lammps_setup_extract_variable () BIND(C) CALL lmp%command('variable ex equal exp(v_lp)') CALL lmp%command('variable fmt format ex %.6G') CALL lmp%command('variable fmt_pad format ex %08.6g') - ! USERNAME should exist on all platforms (incl. Windows) - CALL lmp%command('variable username getenv USERNAME') + CALL lmp%command('variable username getenv FORTRAN_USER') CALL lmp%command('variable greeting file ' // absolute_path('greetings.txt')) CALL lmp%command('variable atfile atomfile ' & // absolute_path('atomdata.txt')) diff --git a/unittest/fortran/wrap_extract_variable.cpp b/unittest/fortran/wrap_extract_variable.cpp index ba439fbda4..47ca0c205d 100644 --- a/unittest/fortran/wrap_extract_variable.cpp +++ b/unittest/fortran/wrap_extract_variable.cpp @@ -3,6 +3,8 @@ #include "lammps.h" #include "library.h" +#include "platform.h" + #include #include #include @@ -175,8 +177,9 @@ TEST_F(LAMMPS_extract_variable, format_pad) TEST_F(LAMMPS_extract_variable, getenv) { + LAMMPS_NS::platform::putenv("FORTRAN_USER=myuser"); f_lammps_setup_extract_variable(); - char *env = std::getenv("USERNAME"); + char *env = std::getenv("FORTRAN_USER"); char *fenv = f_lammps_extract_variable_getenv(); EXPECT_STREQ(fenv, env); std::free(fenv);