Fork me on GitHub
#clojure
<
2018-07-07
>
dpsutton00:07:27

can you sketch it out a bit? i bet there's a good clean solution without redefs and dynamic vars

didibus00:07:03

What I need for some of my tests is created through something that I'm also testing in the same test namespace

didibus00:07:22

Imagine: (def thing (make-thing))

didibus00:07:04

But if I just def this in my tests, so the tests that needs thing just use it from def. It means if (make-thing) doesn't work, the def could fail

didibus00:07:31

So I want to first run my tests for (make-thing)

didibus00:07:43

And when they pass, run my tests that use make-thing

didibus00:07:55

So I create the thing in the middle of my test-ns-hook

didibus00:07:12

After the (make-thing) tests, and before the tests that need a thing

dpsutton00:07:50

that sounds like break them into two tests. test creating the thing. and then test handling of the thing with a well-formed test version of the thing

dpsutton00:07:11

that way you can test the latter half with the bad conditions that can arise as well

didibus00:07:22

They are two tests

didibus00:07:43

But the order matters then. Like, I can't create the thing until I've run the test for it.

didibus00:07:52

But I need the thing for the other test

dpsutton00:07:18

and it has to be that thing that is created? you can't mock one or have generated input to the second test?

didibus00:07:13

Its an integ test

didibus00:07:28

And the thing is a remote client

didibus00:07:34

So I do need it

dpsutton00:07:16

ah i see now.

didibus00:07:25

I mean, I'm definitly being a bit pedantic. Because the edge case is that (make-thing) throws an exception, and then I'm not sure what happens to the test when running if a def in a test namespace throws

noisesmith17:07:18

one option I've used is a function that calls is, and calling that function inside a test

noisesmith17:07:35

this works because deftest/is interaction is via dynamic scope

didibus00:07:34

I assumed it breaks the tests from running. So by first testing that make-thing works, I'm hoping instead of say, the tests not running at all because it threw an exception in the def, instead I see tests failing for make-thing that show me directly where the error is

didibus00:07:27

Anyways, dynamic vars were not that ugly to put in. But I feel its too bad deftest can't take args. Would be nice just for say running a bunch of tests over a huge list of inputs or something.

didibus00:07:30

You could do: (defn test-ns-hook [] (doseq [x list-of-test-inputs] (the-test x)))

ag01:07:53

wat? (reduce + 0 [1 2 3 nil]) => java.lang.NullPointerException (reduce (fnil + 0) 0 [1 2 3 nil]) => java.lang.NullPointerException

dpsutton01:07:18

fnil is the first argument not the second, right?

dpsutton01:07:36

when you get to the 3 you're calling (+ 6 nil) and boom

dpsutton01:07:07

([a b] (f (if (nil? a) x a) b)) should be the branch here. a is 6 so you get a and the b without changing it

ag01:07:43

so it has to be like this (reduce #((fnil + 0) %2 %1) 0 [1 2 3 nil])

ag01:07:50

kinda ugly

noisesmith17:07:16

(fnil + 0 0)

noisesmith17:07:24

also hi, we are coworkers

ag19:07:30

oh hey Justin. I didn't recognize you

dpsutton01:07:46

if you have a swap function you could comp it in there maybe

dpsutton01:07:08

(reduce (comp (fnil + 0) swap) 0 [1 2 3 nil]))

dpsutton01:07:39

(reduce (partial swap (fnil + 0)) 0 [1 2 3 nil]) where (defn swap [f x y] (f y x))

dpsutton01:07:51

looks nicer in haskell i'm sure

oscar01:07:42

(reduce + (filter some? [1 2 3 nil]))

oscar01:07:33

Or (->> [1 2 4 nil] (filter some?) (reduce +))

mg01:07:16

You could do (fnil + 0 0) and not need swap

🎉 4
oscar01:07:32

If you want to use fnil: (reduce (fnil + 0 0) [1 2 3 nil])

mg01:07:11

fnil replaces nils positionally with however many default args you suplly

oscar01:07:21

Oh! Editing...

oscar01:07:04

... Which is what you said...

dpsutton01:07:27

i always forget about the other arities of fnil. despite having just looked at the source lol

mg01:07:08

It's one of my favorite little gems

joefromct04:07:49

hi, quick q, i have a lein project with a main entry point; Is there anyway to not run -main when just doing a lein repl ? I don't like having to constantly change my project.clj just to get to my repl.

joefromct04:07:17

especially since my program takes [& args]

leblowl05:07:01

Hey @joefromct, see here: https://github.com/technomancy/leiningen/blob/stable/sample.project.clj#L362-L364 -- there's a nested keyword option you can set in your project.clj: :repl-options > :init-ns. You set it to the namespace that you want to load for REPL sessions.

leblowl05:07:24

@joefromct I use a special user namespace that is specifically for my REPL sessions. It imports other libraries and defines functions that I use often in the REPL. I got the idea from here: http://www.luminusweb.net/docs#creating_a_new_application (The Luminus project template is focused on web apps, but it might still be helpful for you)

👍 4
joefromct05:07:27

thats exactly what i needed thank you

mx200012:07:36

I have a clojure nrepl server running on an ubutnu server , but I cannot remotly connect via nrepl. Probably the port is blocked. Is there a way I can use my ssh connection to connect via ssh?

mx200012:07:40

I dont want to expose this port also, it would be insecure

mx200012:07:30

So somehow I would like to forward the nrepl port through my ssh connection

valtteri13:07:51

@mx2000 you’re possibly looking for ssh port forwarding https://www.ssh.com/ssh/tunneling/example

noisesmith17:07:29

@mx2000 the connection is from the local host only intentionally since a repl is a huge security hole

noisesmith17:07:43

but yes, the right thing to do is port forward

philip20:07:05

Hello! Is there any sensible mobile app/mobile website that can teach daily bits of clojure or clojurescript on iOS? I am looking for little coding challenges, discussions on architecture, tips and tricks etc… Thanks 🙂

valerauko05:07:42

would purely functional work? https://purelyfunctional.tv/

💯 4
johnj20:07:57

there is an iOS repl somewhere out there

👍 4