Skip to content

Commit d807600

Browse files
committed
added test for nu_plugin_example
1 parent b0f63a0 commit d807600

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ jobs:
5353
tests-dir: ./python/nu_plugin_python_example
5454
needs:
5555
- python
56+
- name: nu_plugin_example
57+
plugin: ./target/nu_plugin_example
58+
tests-dir: ./rust/nu_plugin_example
59+
needs:
60+
- rust
5661

5762
steps:
5863
- name: Checkout Repo
@@ -72,6 +77,14 @@ jobs:
7277
with:
7378
python-version-file: ".python-version"
7479

80+
- if: contains(matrix.plugin.needs, 'rust')
81+
name: Setup Rust toolchain and cache
82+
uses: actions-rust-lang/setup-rust-toolchain@v1
83+
84+
- if: contains(matrix.plugin.needs, 'rust')
85+
name: Build Rust-based Plugin
86+
run: cargo build --release ${{ matrix.plugin.name }}
87+
7588
- name: Download Nushell Binary
7689
uses: actions/download-artifact@v4
7790
with:
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
use std/testing *
2+
use std/assert
3+
4+
@test
5+
def "test example" [] {
6+
assert str contains (example) "Example commands for Nushell plugins"
7+
}
8+
9+
@test
10+
def "test example call-decl" [] {
11+
let expected = version | columns | length
12+
assert length (example call-decl version | columns) $expected
13+
}
14+
15+
@test
16+
def "test example collect-bytes" [] {
17+
let expected = "ab"
18+
assert equal ([a, b] | example collect-bytes) $expected
19+
}
20+
21+
@test
22+
def "test example config" [] {
23+
let config = {a: 1, b: "b"}
24+
$env.config.plugins.example = $config
25+
assert equal (example config) $config
26+
}
27+
28+
@test
29+
@ignore
30+
def "test example ctrlc" [] {
31+
# TODO: test this
32+
}
33+
34+
@test
35+
@ignore
36+
def "test example disable-gc" [] {
37+
# TODO: test this
38+
}
39+
40+
@test
41+
def "test example echo" [] {
42+
let expected = seq 1 5 | collect
43+
assert equal (seq 1 5 | example echo) $expected
44+
}
45+
46+
@test
47+
def "test example env" [] {
48+
let value = "🐘"
49+
$env.ELLY = $value
50+
assert equal (example env | get ELLY) $value
51+
}
52+
53+
@test
54+
@ignore
55+
def "test example for-each" [] {
56+
# TODO: test this
57+
}
58+
59+
@test
60+
def "test example generate" [] {
61+
let expected = [0, 2, 4, 6, 8, 10]
62+
let closure = {|i| if $i <= 10 {{out: $i, next: ($i + 2)}}}
63+
let actual = example generate 0 $closure
64+
assert equal $actual $expected
65+
}
66+
67+
@test
68+
def "test example one" [] {
69+
# TODO: test the actual behavior
70+
assert equal (example one 1 a) null
71+
}
72+
73+
@test
74+
def "test example seq" [] {
75+
assert equal (example seq 1 5) (seq 1 5)
76+
}
77+
78+
@test
79+
def "test example sum" [] {
80+
let input = [1, 2, 3]
81+
let expected = $input | math sum
82+
let actual = $input | example sum
83+
assert equal $expected $actual
84+
}
85+
86+
@test
87+
def "test example three" [] {
88+
assert error {|| example three 1 a}
89+
}
90+
91+
@test
92+
def "test example two" [] {
93+
let expected = (0..9 | generate {|i| {out: {one: $i, two: ($i * 2), three: ($i * 3)}, next: ($i + 1)}} 0)
94+
assert equal (example two 1 a) $expected
95+
}
96+
97+
@test
98+
def "test example view span" [] {
99+
let expected = "'hello ' ++ 'world'"
100+
let actual = ('hello ' ++ 'world') | example view span
101+
assert equal $expected $actual
102+
}

0 commit comments

Comments
 (0)