sschwarzer
2021-8-7 16:39:47

I guess we have our (hopefully) monthly Racket meeting on Gather.town today?

The “location” and time of day would be the same as listed here: https://racket-news.com/2021/07/racket-news-issue-52.html#meetups


massung
2021-8-7 18:04:08

If I want to write a rackunit that tested for output, anyone here have a good best-practice for it?

Generally, what I’m thinking is something along the lines of using call-with-output-string, and comparing the output. But, my concern is with multi-line output and cross-platform. If the hard-coded string to compare against is filled with \n and anything written to the port is sent \r\n on Windows, then the unit test fails. Is there a way to get around this (even if it’s forcing a line ending mode just for the unit test)?


rokitna
2021-8-7 18:25:34

Hmm, I don’t know how well everyone else would like my unit test practices, but I might approach this by using a non-hardcoded string. Like, my unit test’s expected value might be a call to call-with-output-string with a bunch of displayln calls inside.


massung
2021-8-7 18:31:18

In this case, it’s kind akin to “pretty print list as xml” and ensure that the output is correct


massung
2021-8-7 18:31:55

WRT not hard-coding, my best thought was “write and then read the output back in” and ensure the final structure is identical as the input


soegaard2
2021-8-7 18:32:40

You could write a function clean that simply replaves \r with the empty string.


massung
2021-8-7 18:33:41

that may work



shu--hung
2021-8-7 19:31:41

Except that in this case the situation is the other way around. The Windows git checkout turned "\n" into "\r\n" in the expected output so this code has to turn it back to match the printed output.


shu--hung
2021-8-7 19:33:39

shu--hung
2021-8-7 19:45:03

The translation could happen at the lower file I/O level and not at the Racket level.


massung
2021-8-7 19:48:26

Good point. I’ll do some side tests and see


claiborn
2021-8-7 22:01:55

Okay, I am doing something dumb:

The following code works fine in the REPL and when invoked as racket lambda-run.rkt get-run.rkt

lambda-run.rkt: (define (run-from-file filename) (dynamic-require filename 'do-this)) ((run-from-file (vector-ref (current-command-line-arguments) 0)))

And get-run.rkt: (provide do-this) (define (do-this) (displayln "Doing this."))

But when I run it after having compiled via raco exe , it fails with:

resolver: collection not found for module path: racket/lang/reader collection: "racket/lang" in collection directories: context...: .../racket-run/lambda-run.rkt:8:0 body of '#%mzc:lambda-run

I have tried parameterizing current-library-collection-paths and adding my current directory, and that doesn’t work. What am I missing?

Thanks in advance for any help.


claiborn
2021-8-7 22:04:41

lang racket lines were skipped, but they are there in the actual code.


sorawee
2021-8-7 22:07:48

When using raco exe with dynamic-require, you need to either use ++lib or use define-runtime-path. See https://docs.racket-lang.org/raco/exe.html


claiborn
2021-8-7 22:09:03

Thank you; I think I skimmed over that because it looked like it was for embedding the file (I was trying to get it in at runtime). I’ll look. Appreciate the tip.


sorawee
2021-8-7 22:10:35

Though I don’t think it’s going to work well, since it’s a command-line argument parameter


sorawee
2021-8-7 22:10:59

In a sense, ++lib is a way to make that dynamic-require static.


sorawee
2021-8-7 22:11:22

But if you can specify anything, it’s not gonna work, I think


claiborn
2021-8-7 22:12:35

Yeah, that’s what I had initially thought. I’m basically trying to do some runtime code injection (I have honorable intentions, I promise) and I’d like to do it from a standalone executable to simplify my deployment.


massung
2021-8-7 22:58:27

okay… I have a raco package where I’ve set: (define compile-omit-paths '("examples")) I’ve done this because I’m created a few examples that include other packages I do not want as a dependency for my package.

However, it would appear http://pkg-build.racket-lang.org\|pkg-build.racket-lang.org still trolls the examples folder and tries to build/test it, so I’m getting dependency and test failures for my package.

Is there something I can do to work around this?


shu--hung
2021-8-7 23:01:37

Which package?



massung
2021-8-7 23:07:34

I’d like to not rewrite the sample, but I can as a last resort. I’m really just hoping I can do something to work around it. Ignoring it by the build system is ideal. I imagine next would be conditionally running the sample code if the package in question exists.


shu--hung
2021-8-7 23:08:27

The build isn’t real-time. It was the log from 8pm (UTC+0)


massung
2021-8-7 23:08:54

It’s got the latest from github. It’s up-to-date (and the docs are correct as well)


massung
2021-8-7 23:09:17

So, unless the test part is separate…?


shu--hung
2021-8-7 23:09:28

Yes, the catalog points to the latest commit but the build only runs a few times a day.


shu--hung
2021-8-7 23:09:43

The catalog is more like a index


massung
2021-8-7 23:09:45

ok. i’ll wait and see then


massung
2021-8-7 23:10:06

Is compile-omit-paths supposed to be the solution to this?


massung
2021-8-7 23:10:30

I basically just copy/pasted that from another package, so I don’t know if that’s correct, old and obsolete, or just wrong. :wink:


shu--hung
2021-8-7 23:10:42

I also use that to omit examples but I’m not sure :slightly_smiling_face:


ben.knoble
2021-8-8 01:30:11

There’s also a test omit paths (or compile test omit?), but I don’t think that excludes dependencies?


shu--hung
2021-8-8 02:05:00

@massung ^ I forgot about the tests!