jschobben / colorscad

Script to produce colorized OpenSCAD models
Other
43 stars 7 forks source link

Tests fail #5

Closed schorsch3000 closed 4 months ago

schorsch3000 commented 4 months ago

Hi, There are some issues in colorscad, mainly missing quotes around variables that make thing break with special chars (including space) in path names. I'm happy to fix at least everything that shellcheck complains about and make a PR for that.

It would be nice to have some tests to be sure everything i've done works, but the tests currently fail :-(

here is the full output of my testrun on a clean repo:

 ./run.sh 
Testing bad weather:
Bad weather tests all passed.
Testing: input=test_boolean.scad expected=expectations/test_boolean.3mf
  Get list of used colors
  3 unique colors were found.

  Create a separate .3mf file for each color
  1/3 [1, 0, 0, 1] Starting
  2/3 [0, 0.501961, 0, 1] Starting
  3/3 [0, 0, 1, 1] Starting
  1/3 [1, 0, 0, 1] Finished at ./tmp.tensgR/[1, 0, 0, 1].3mf
  2/3 [0, 0.501961, 0, 1] Finished at ./tmp.tensgR/[0, 0.501961, 0, 1].3mf
  3/3 [0, 0, 1, 1] Finished at ./tmp.tensgR/[0, 0, 1, 1].3mf

  Generate a merged .3mf file

  /home/heilig/bin/colorscad.git/test/tmp.hFr84F/output.3mf created successfully.
Testing: input=test_boolean.scad expected=expectations/test_boolean.amf
  Get list of used colors
  3 unique colors were found.

  Create a separate .amf file for each color
  1/3 [1, 0, 0, 1] Starting
  2/3 [0, 0.501961, 0, 1] Starting
  3/3 [0, 0, 1, 1] Starting
  3/3 [0, 0, 1, 1] Finished at ./tmp.8uFS9n/[0, 0, 1, 1].amf
  1/3 [1, 0, 0, 1] Finished at ./tmp.8uFS9n/[1, 0, 0, 1].amf
  2/3 [0, 0.501961, 0, 1] Finished at ./tmp.8uFS9n/[0, 0.501961, 0, 1].amf

  Generate a merged .amf file
  3/3 
  To create a compressed AMF, run:
    zip 'tmp.hFr84F/output.amf.zip' 'tmp.hFr84F/output.amf' && mv 'tmp.hFr84F/output.amf.zip' 'tmp.hFr84F/output.amf'
  But, be aware that some tools may not support compressed AMF files.

  /home/heilig/bin/colorscad.git/test/tmp.hFr84F/output.amf created successfully.
diff -wur /home/heilig/bin/colorscad.git/test/./tmp.hFr84F/exp/model.amf /home/heilig/bin/colorscad.git/test/./tmp.hFr84F/out/model.amf
--- /home/heilig/bin/colorscad.git/test/./tmp.hFr84F/exp/model.amf  2024-04-03 18:10:19.206300838 +0200
+++ /home/heilig/bin/colorscad.git/test/./tmp.hFr84F/out/model.amf  2024-04-03 18:10:19.234300798 +0200
@@ -1,4 +1,4 @@
-<?xmlversion="1.0"encoding="UTF-8"?><amfunit="millimeter"><metadatatype="producer">ColorSCAD</metadata><materialid="0"><color><r>1</r><g>0</g><b>0</b><a>1</a></color></material><materialid="1"><color><r>0</r><g>0.501961</g><b>0</b><a>1</a></color></material><materialid="2"><color><r>0</r><g>0</g><b>1</b><a>1</a></color></material>
+<?xmlversion="1.0"encoding="UTF-8"?><amfunit="millimeter"><metadatatype="producer">ColorSCAD</metadata><materialid="0"><color><r>1,0,0,1]</r><g></g><b></b><a></a></color></material><materialid="1"><color><r>0,0.501961,0,1]</r><g></g><b></b><a></a></color></material><materialid="2"><color><r>0,0,1,1]</r><g></g><b></b><a></a></color></material>
 <triangle><vertex><coordinates><x>-0.375</x><y>0.625</y><z>0.625</z></coordinates></vertex><vertex><coordinates><x>-0.375</x><y>-0.375</y><z>-0.375</z></coordinates></vertex><vertex><coordinates><x>0.625</x><y>-0.375</y><z>0.625</z></coordinates></vertex></triangle>
 <triangle><vertex><coordinates><x>0.625</x><y>-0.375</y><z>0.625</z></coordinates></vertex><vertex><coordinates><x>-0.375</x><y>-0.375</y><z>-0.375</z></coordinates></vertex><vertex><coordinates><x>0.625</x><y>0.625</y><z>-0.375</z></coordinates></vertex></triangle>
 <triangle><vertex><coordinates><x>0.625</x><y>0.625</y><z>-0.375</z></coordinates></vertex><vertex><coordinates><x>-0.375</x><y>-0.375</y><z>-0.375</z></coordinates></vertex><vertex><coordinates><x>-0.375</x><y>0.625</y><z>0.625</z></coordinates></vertex></triangle>
Failure at ./run.sh:149
jschobben commented 4 months ago

Hmm indeed, on Linux the tests fail with OpenSCAD's nightly builds since 26 jan 2024, fix for that is in PR #6. That looks unrelated to the above though, which is a failure to properly split the r/g/b/a colors in the AMF merging code (whether anyone still needs AMF is another topic :sweat_smile:)

I would like to try reproducing the above failure, it works OK still for me. Could you give some info on your versions/environment? E.g. versions of colorscad, openscad, bash, which OS, etc. Maybe locale info is also interesting.

schorsch3000 commented 4 months ago

So, yeah that seems to be a nightly-build-problem. Fun fact, i tend to run the a somewhat early nightly, since opening this issue i updated to2024.03.28.ai1895 i can't reproduce my error now running 2024.03.28.ai1895. I Updated to 22024.04.05.ai18986 right now and All tests passed as well.

So, according to me all is fine now, nothing to see here :-D

That said, are you Interested to reproduce anymore?

Anyway, Thanks!

jschobben commented 4 months ago

Do you still know with which nightly appimage it failed? If so I'd like to have a shot at fixing it. I'm also setting up some workflows to run the tests automatically, so maybe that's already sufficient.

Anyway if it works now then all is good! Feel free to submit a PR with shellcheck fixes.

schorsch3000 commented 4 months ago

unfortunately i don't know, it must have been from April, but i dint know :-(

PR is coming up, I've done the easy part, sprinkling some quotes in there, end the script if bad things gonna happen, change some things to acknowledge best practice. Tests run fine on my setup.

3 things are missing for now: the ambiguous until > "$NAME"; thing, yes, it works, yes, i understand what it does, but shellcheck minds, and i get it.

IFS=','; set -- $COLOR seems like it's just missing quotes around $COLOR, but that breaks things, seems i need to dig in and find out what actually is happening here :-D

<(echo "$COLORS" | sed "s/\$/\.${FORMAT}/") should be able be rewritten as a ${foo//search/replace}.

My current state is here, if you are interested. I'll do the PR if everything is done.

jschobben commented 4 months ago

Just a remark, CI will now run tests on all supported platforms so that should make it easier to verify your changes are OK. Might even consider adding a shellcheck step in the CI...

jschobben commented 4 months ago

IFS=','; set -- $COLOR

This (and the followup) should probably be simplified as something like: IFS=, read R G B A <<<"${COLOR//[\[\] ]/}"

There's probably more stuff like that, let's discuss it all on your PR.

schorsch3000 commented 4 months ago

adding shellcheck sounds like a great idea and should be quite easy i hope!

My first Task was to fix everything thatz is fixable without actually understanding the scope, just look at the few lines around shellcheck's finding and make improvements, that's easily done for missing quotes and alike, with the given tests im fairly confident everything is okay, for the next steps i actually need to check whats happening there :-D

But your hint will help.

To use the now added checks i will open a PR now, it's not done yet, but i like to utilize checks for osx and it's aged bash.