Skip to content

Commit

Permalink
Added tests for diffModelicaFileListings API
Browse files Browse the repository at this point in the history
Added two tests:
1. Checking a set of files with before and after files. Compares to
   the key "merged" files (diff and final without markup).
2. Checking that addComponent introduces a component in the expected
   location.

Also removed DiffAlgorithmModelica test since it has been superseded.
  • Loading branch information
sjoelund committed Jun 30, 2015
1 parent 8a3220b commit c52d337
Show file tree
Hide file tree
Showing 29 changed files with 254 additions and 170 deletions.
6 changes: 5 additions & 1 deletion Makefile
Expand Up @@ -148,7 +148,8 @@ fmi_cs_st.log \
uncertainties.log \
scodeinst.log \
xml.log \
xogeny.log
xogeny.log \
openmodelicadiff.log

.PHONY : all omc-diff ReferenceFiles failingtest test fast fast.logs $(FASTLOGS) $(SLOWLOGS) $(SIMULATIONLOGS) slow.logs threaded

Expand Down Expand Up @@ -532,6 +533,9 @@ modelica3d.log: omc-diff
hummod.log: omc-diff
$(MAKE) -C simulation/libraries/3rdParty/HumMod -f Makefile test > $@
@echo $@ done
openmodelicadiff.log: omc-diff
$(MAKE) -C openmodelica/diff -f Makefile test > $@
@echo $@ done

failingtest: omc-diff
cd mofiles; $(MAKE) -f Makefile failingtest; \
Expand Down
143 changes: 0 additions & 143 deletions openmodelica/bootstrapping/DiffAlgorithmModelica.mos

This file was deleted.

1 change: 0 additions & 1 deletion openmodelica/bootstrapping/Makefile
Expand Up @@ -3,7 +3,6 @@ TEST = ../../rtest

TESTFILES = \
DiffAlgorithm.mos \
DiffAlgorithmModelica.mos \
DumpTest.mos \
ExpressionTest.mos \
GraphTest.mos \
Expand Down
25 changes: 0 additions & 25 deletions openmodelica/bootstrapping/TestDiffAlgorithmModelica.mo

This file was deleted.

14 changes: 14 additions & 0 deletions openmodelica/diff/AddComponent.loop.mos
@@ -0,0 +1,14 @@
loadString(s1, "X.mo");
print(getErrorString());
addComponent(r1, Real, X);
print(getErrorString());
s2:=listFile(X);
if answer<>diffModelicaFileListings(s1, s2, OpenModelica.Scripting.DiffFormat.plain) then
print("\nFailed " + String(i) + "\n");
print("\nStart model:\n\n" + s1 + "\n");
print("\nAdded component+listFile:\n\n" + s2 + "\n");
print("\nDiff:\n\n" + diffModelicaFileListings(s1, s2) + "\n");
print(getErrorString());
exit(1);
end if;
print("OK " + String(i) + "\n");
44 changes: 44 additions & 0 deletions openmodelica/diff/AddComponent.mos
@@ -0,0 +1,44 @@
// status: correct

/*
The first one looks a bit odd since it does not have newlines from the
beginning, but it seems such an uncommon case that it is OK to just insert
the element on the same line as "model X".
*/

echo(false);
qs := {
"model X end X;",
"model X\nend X;",
"model X\n Real x;\n Real y;\nend X;",
"model X\n Real x;\n Real y;\nend X;"
};
as := {
"model X Real r1;
end X;",
"model X
Real r1;
end X;",
"model X
Real x;
Real y;
Real r1;
end X;",
"model X
Real x;
Real y;
Real r1;
end X;"
};
for i in 1:4 loop
s1:=qs[i];
answer:=as[i];
print(runScript("AddComponent.loop.mos"));
end for;

// Result:
// OK 1
// OK 2
// OK 3
// OK 4
// endResult
55 changes: 55 additions & 0 deletions openmodelica/diff/Makefile
@@ -0,0 +1,55 @@
# BuiltinReal.mos fails when using Cevalfunc.mo! the values are OK, the display is different!
TEST = ../../rtest

TESTFILES = \
AddComponent.mos \
TestDiffListAPI.mos

# test that currently fail. Move up when fixed.
# Run make testfailing
FAILINGTESTFILES= \


# Dependency files that are not .mo .mos or Makefile
# Add them here or they will be cleaned.
DEPENDENCIES = \
*.mo \
*.mos \
Makefile

# Remove executables on Linux (no extension)
# CLEAN = $(TESTFILES:.mos=) $(TESTFILES:.mos=_*) $(TESTFILES:.mos=.cpp) $(TESTFILES:.mos=.makefile) $(TESTFILES:.mos=.libs) $(TESTFILES:.mos=.log) output.log *.dll *.exe *.so

CLEAN = `ls | grep -w -v -f deps.tmp`

.PHONY : test

test:
@echo
@echo Running tests...
@echo
@echo OPENMODELICAHOME=" $(OPENMODELICAHOME) "
@$(TEST) $(TESTFILES)

# Cleans all files that are not listed as dependencies
clean :
@echo $(DEPENDENCIES) | sed 's/ /\\|/g' > deps.tmp
@rm -f $(CLEAN)

# Run this if you want to list out the files (dependencies).
# do it after cleaning and updating the folder
# then you can get a list of file names (which must be dependencies
# since you got them from repository + your own new files)
# then add them to the DEPENDENCIES. You can find the
# list in deps.txt
getdeps:
@echo $(DEPENDENCIES) | sed 's/ /\\|/g' > deps.tmp
@echo $(CLEAN) | sed -r 's/deps.txt|deps.tmp//g' | sed 's/ / \\\n/g' > deps.txt
@echo Dependency list saved in deps.txt.
@echo Copy the list from deps.txt and add it to the Makefile @DEPENDENCIES

failingtest :
@echo
@echo Running failing tests...
@echo
@$(TEST) $(FAILINGTESTFILES)
61 changes: 61 additions & 0 deletions openmodelica/diff/TestDiffListAPI.mos
@@ -0,0 +1,61 @@
// status: correct
// depends: manual

n:=5;
min(writeFile(
"manual/"+String(i)+".merged.color.rtest",
diffModelicaFileListings(
readFile("manual/"+String(i)+".before"),
readFile("manual/"+String(i)+".after"),
OpenModelica.Scripting.DiffFormat.color
))
and
writeFile(
"manual/"+String(i)+".merged.plain.rtest",
diffModelicaFileListings(
readFile("manual/"+String(i)+".before"),
readFile("manual/"+String(i)+".after"),
OpenModelica.Scripting.DiffFormat.plain
))
and
writeFile(
"manual/"+String(i)+".merged.xml.rtest",
diffModelicaFileListings(
readFile("manual/"+String(i)+".before"),
readFile("manual/"+String(i)+".after"),
OpenModelica.Scripting.DiffFormat.xml
))
for i in 1:n);
getErrorString();

sum(
if readFile("manual/"+String(i)+".merged.color")<>readFile("manual/"+String(i)+".merged.color.rtest")
then (String(i) + " failed. Got:\n" +
readFile("manual/"+String(i)+".merged.color.rtest") + "\nExpected:\n" +
readFile("manual/"+String(i)+".merged.color") + "\n"
)
else ""
for i in 1:n
);
getErrorString();

sum(
if readFile("manual/"+String(i)+".merged.plain")<>readFile("manual/"+String(i)+".merged.plain.rtest")
then (String(i) + " failed. Got:\n" +
readFile("manual/"+String(i)+".merged.plain.rtest") + "\nExpected:\n" +
readFile("manual/"+String(i)+".merged.plain") + "\n"
)
else ""
for i in 1:n
);
getErrorString();

// Result:
// 5
// true
// ""
// ""
// ""
// ""
// ""
// endResult
1 change: 1 addition & 0 deletions openmodelica/diff/manual/.gitignore
@@ -0,0 +1 @@
*.rtest
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions openmodelica/diff/manual/1.merged.color
@@ -0,0 +1,3 @@
model M
 Real r;
end M;
3 changes: 3 additions & 0 deletions openmodelica/diff/manual/1.merged.plain
@@ -0,0 +1,3 @@
model M
Real r;
end M;
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions openmodelica/diff/manual/2.merged.color
@@ -0,0 +1,4 @@
model M
Real x;
Real y;
end M;
4 changes: 4 additions & 0 deletions openmodelica/diff/manual/2.merged.plain
@@ -0,0 +1,4 @@
model M
Real x;
Real y;
end M;
File renamed without changes.
File renamed without changes.

0 comments on commit c52d337

Please sign in to comment.