The V Programming Language

Simple, fast, safe language created for developing Volt, soon available for everyone.

Open source release in June 2019. Early access since April 15.
Install V from source in 0.5 seconds
wget vlang.io/v.c && gcc -o v v.c
1.9k

Testing, access to structs

Alex
Apr 15 · 3 min read
kcorey Jun 25 18:16
Hiya,

Just thinking about playing with the language a bit.

Writing one-file scripts is cute, but it's not reasonable to build larger, interesting apps.

So, I figured I'd do TDD using V.

Let's pick the bowling kata from Uncle Bob. Good enough place to start.

I create a file 'bowling.v' as well as 'bowling_test.v'. v run bowling_test.v runs.

In bowling_test.v, I want to create a test that forces me to write a Game struct:
fn test_game() {
game := Game{

}
}

This fails with "undefined: 'Game'". I get it, there's no way for the compiler to understand 'struct Game{}' in bowling.v.

I thought about making 'bowling' a module.

So, in bowling_test.v:
import bowling

The error that gets is: V panic: /Users/<username>//code/v//bowling doesn't exist

Ah, okay, so
import examples/bowling

pass=1 fn=``
panic: hello_world.v:5
unexpected token `println`

Seems that it's going through the 'example' directory.

Okay, move 'bowling' up to 'v'.

Now, 'v run bowling_test.v' gets stuck in a loop (I suspect because bowling_test.v is inside the bowling module).

So I'm perplexed. How does one use the 'v test filename' command to do TDD with V after all?

I want to import one file into another. I want to be able to call the functions in the source file.

Thoughts? (RTFM would be great if you tell me where, code would be better).

-Ken
medvednikov Jun 25 21:39
Yes, this is broken right now.
medvednikov Jun 25 21:39
Thanks for reporting, will be fixed asap.
medvednikov Jun 25 21:39
Its a relatively simple fix. Ive added it to the 0.2 roadmap
medvednikov Jun 25 21:39
https://github.com/vlang/v/projects/2
medvednikov Jun 25 21:39
And I need to fix the forum, I couldn't post this as one message :)
kcorey Jun 25 22:00
No worries, keep up the good work!
Log in via GitHub to comment



Powered by vtalk, open-source blogging/forum software written in V