Skip to content

Commit 2b6ee1a

Browse files
ontouchstartStefanKarpinski
authored andcommitted
Command-line-based basic editor/REPL workflow (#28725)
1 parent ea00782 commit 2b6ee1a

File tree

1 file changed

+45
-31
lines changed

1 file changed

+45
-31
lines changed

doc/src/manual/workflow-tips.md

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,59 @@ As already elaborated in [The Julia REPL](@ref), Julia's REPL provides rich func
88
that facilitates an efficient interactive workflow. Here are some tips that might further enhance
99
your experience at the command line.
1010

11-
### A basic editor/REPL workflow
11+
## Command-line-based basic editor/REPL workflow
1212

1313
The most basic Julia workflows involve using a text editor in conjunction with the `julia` command
1414
line. A common pattern includes the following elements:
1515

16-
* **Put code under development in a temporary module.** Create a file, say `Tmp.jl`, and include
17-
within it
16+
* **Generate a new project**
17+
18+
```
19+
$ julia -e 'using Pkg;Pkg.generate("Tmp")'
20+
Generating project Tmp:
21+
Tmp/Project.toml
22+
Tmp/src/Tmp.jl
23+
$ ls -R Tmp
24+
Tmp:
25+
Project.toml src
26+
27+
Tmp/src:
28+
Tmp.jl
29+
$ cat -n Tmp/src/Tmp.jl
30+
1 module Tmp
31+
2
32+
3 greet() = print("Hello World!")
33+
4
34+
5 end # module
35+
```
36+
37+
* **Create a test folder**
38+
```
39+
$ mkdir Tmp/test
40+
```
41+
* **Put your test code in `test/runtests.jl` file.**
1842

1943
```
20-
module Tmp
21-
22-
<your definitions here>
23-
24-
end
25-
```
26-
* **Put your test code in another file.** Create another file, say `tst.jl`, which begins with
27-
28-
```julia
29-
import Tmp
44+
$ cat -n Tmp/test/runtests.jl
45+
1 using Tmp
46+
2 Tmp.greet()
3047
```
3148
32-
and includes tests for the contents of `Tmp`.
33-
Alternatively, you can wrap the contents of your test file in a module, as
34-
35-
```
36-
module Tst
37-
using Tmp
38-
39-
<scratch work>
40-
41-
end
42-
```
43-
44-
The advantage is that you can now do `using Tmp` in your test code and can therefore avoid prepending
45-
`Tmp.` everywhere. The disadvantage is that code can no longer be selectively copied to the REPL
46-
without some tweaking.
47-
* **Lather. Rinse. Repeat.** Explore ideas at the `julia` command prompt. Save good ideas in `tst.jl`.
48-
49-
### Simplify initialization
49+
* **Run test**
50+
```
51+
$ julia -e 'using Pkg;Pkg.activate("Tmp");Pkg.test()'
52+
Updating registry at `~/.julia/registries/General`
53+
Updating git-repo `https://github.com/JuliaRegistries/General.git`
54+
Resolving package versions...
55+
Updating `~/Tmp/Project.toml`
56+
[no changes]
57+
Testing Tmp
58+
Resolving package versions...
59+
Hello World! Testing Tmp tests passed
60+
```
61+
* **Lather. Rinse. Repeat.** Explore ideas at the `julia` command prompt. Save good ideas in `Tmp.jl` and test with `runtests.jl`.
62+
63+
## Simplify initialization
5064
5165
To simplify restarting the REPL, put project-specific initialization code in a file, say `_init.jl`,
5266
which you can run on startup by issuing the command:

0 commit comments

Comments
 (0)