
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

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)?

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.

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

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

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

that may work


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.

The translation from "\n"
to "\r\n"
seems to happen for file ports but I am not sure https://docs.racket-lang.org/reference/file-ports.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._open-output-file%29%29

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

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

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.

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

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

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.

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

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

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

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.

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?

Which package?


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.

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

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

So, unless the test part is separate…?

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

The catalog is more like a index

ok. i’ll wait and see then

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

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:

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

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

@massung ^ I forgot about the tests!