Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set start of 'ok' and improve check of empty 'file' string #4405

Closed
wants to merge 2 commits into from

Conversation

tobolar
Copy link
Contributor

@tobolar tobolar commented May 10, 2024

No description provided.

@tobolar tobolar added the L: ModelicaTest Issue addresses ModelicaTest, ModelicaTestConversion4 or ModelicaTestOverdetermined label May 10, 2024
Copy link
Contributor

@HansOlsson HansOlsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this, and those testing functions in general.

To me it indicates a mixup of two different testing variants:

Basically the functions internally assert if there is a failure, and always set ok to true at the end. Some (as this proposed one) set ok to false in the beginning, but I don't see the benefit - either the assert triggers and then it stops and the return value isn't relevant, or the assert doesn't trigger and it returns true.
I would either remove the asserts (probably not) or the return value.

The file part likely didn't work before, and the change doesn't help.
The correct solution would be:

if Modelica.Utilities.Strings.isEmpty(logFile) then
  file:="";
else
  file:=Modelica.Utilities.Files.fullPathName(logFile);
  print("... testAllFunctions(..) is logged in " + file);
  Modelica.Utilities.Files.removeFile(file);
end if;

So, that you send in an empty logfile if you don't want log-files, whereas fullPathName of "" may return the local directory!

@HansOlsson
Copy link
Contributor

Alternatively just don't change 'ok'.

@HansOlsson
Copy link
Contributor

BTW: Why is fullPathName needed at all?

I thought the other commands also handled relative paths as well, and only ModelicaTest.Utilities.Internal changes directory and it should restore it - if that fails the asserts will trigger before anything is logged to the file.

So, just:

if Modelica.Utilities.Strings.isEmpty(logFile) then
  file:="";
else
  file:=logFile;
  print("... testAllFunctions(..) is logged in " + file);
  Modelica.Utilities.Files.removeFile(file);
end if;

or back to:

if logFile<>"" then
  print("... testAllFunctions(..) is logged in " + logFile);
  Modelica.Utilities.Files.removeFile(logFile);
end if;

and replace file by logFile.

@tobolar
Copy link
Contributor Author

tobolar commented Jun 26, 2024

@HansOlsson Well, I didn't digger deeply in this function. The PR is only about to handle empty string of file properly i.e. using given MSL function.
Regarding ok - if the default value of ok is false, then there is no need to change it. You are right. I will revert this.

@HansOlsson
Copy link
Contributor

@HansOlsson Well, I didn't digger deeply in this function. The PR is only about to handle empty string of file properly i.e. using given MSL function.

But there are some problems:

  • isEmpty() returns true for both "" and " " (with space), whereas print will only print to the screen if "", so for consistency with print I would keep it as is
  • the test isn't for the input String (would be useful if you don't want the file output), but for the result of Modelica.Utilities.Files.fullPathName() - which is very unlikely to be an empty string.
  • And as noted I don't know why fullPathName is used at all

So the PR isn't that bad in itself - it just made me realize how messy the function really is.

@tobolar
Copy link
Contributor Author

tobolar commented Jul 1, 2024

@HansOlsson I fully agree to all your three concerns.

So the PR isn't that bad in itself - it just made me realize how messy the function really is.

So I prefer retrieve this PR. Changing the function as you suggest is all fine but shall be done in a new PR.

@tobolar tobolar closed this Jul 1, 2024
@tobolar tobolar deleted the minor_testAllFunctions branch July 12, 2024 07:47
@beutlich beutlich added the wontfix Issue that will not be fixed label Jul 19, 2024
@beutlich beutlich added this to the never milestone Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: ModelicaTest Issue addresses ModelicaTest, ModelicaTestConversion4 or ModelicaTestOverdetermined wontfix Issue that will not be fixed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants