Skip to content

Commit 3594daf

Browse files
committed
yanglint UPDATE add command for sid file
1 parent f8f1d85 commit 3594daf

14 files changed

Lines changed: 945 additions & 3 deletions

File tree

tests/yanglint/data/test.sid

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"ietf-sid-file:sid-file": {
3+
"module-name": "test-sid",
4+
"module-revision": "2026-08-11",
5+
"sid-file-status": "unpublished",
6+
"description": "Generated by libyang 5.6.12, at 2026-08-17 08:37:22",
7+
"assignment-range": [
8+
{
9+
"entry-point": "1000",
10+
"size": "20"
11+
}
12+
],
13+
"item": [
14+
{
15+
"namespace": "module",
16+
"identifier": "test-sid",
17+
"status": "unstable",
18+
"sid": "1000"
19+
},
20+
{
21+
"namespace": "data",
22+
"identifier": "/test-sid:test-container",
23+
"status": "unstable",
24+
"sid": "1001"
25+
},
26+
{
27+
"namespace": "data",
28+
"identifier": "/test-sid:test-container/test-leaf1",
29+
"status": "unstable",
30+
"sid": "1002"
31+
},
32+
{
33+
"namespace": "data",
34+
"identifier": "/test-sid:test-container/test-leaf2",
35+
"status": "unstable",
36+
"sid": "1003"
37+
}
38+
]
39+
}
40+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}]
2+
3+
set mdir $::env(YANG_MODULES_DIR)
4+
set ddir $::env(TESTS_DIR)/data
5+
6+
test sid_generate {} {
7+
-setup $ly_setup -cleanup $ly_cleanup -body {
8+
set pattern "(?s)^"
9+
append pattern {.*"module-name": "test-sid",}
10+
append pattern {.*"module-revision": "2026-08-11",}
11+
append pattern {.*"sid-file-status": "unpublished",}
12+
append pattern {.*"description": "Generated by libyang }
13+
append pattern {.*"entry-point": "1000",}
14+
append pattern {.*"size": "20"}
15+
append pattern {.*"identifier": "test-sid",}
16+
append pattern {.*"status": "unstable",}
17+
append pattern {.*"sid": "1000"}
18+
append pattern {.*"identifier": "/test-sid:test-container",}
19+
append pattern {.*"status": "unstable",}
20+
append pattern {.*"sid": "1001"}
21+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf1",}
22+
append pattern {.*"status": "unstable",}
23+
append pattern {.*"sid": "1002"}
24+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf2",}
25+
append pattern {.*"status": "unstable",}
26+
append pattern {.*"sid": "1003"}
27+
28+
ly_cmd "verb error"
29+
ly_cmd "add $mdir/test-sid-v1.yang"
30+
ly_cmd "sid generate 1000:20 test-sid" $pattern
31+
}}
32+
33+
test sid_generate_published {} {
34+
-setup $ly_setup -cleanup $ly_cleanup -body {
35+
set pattern "(?s)^"
36+
append pattern {(?=.*"module-name": "test-sid",)}
37+
append pattern {(?=.*"module-revision": "2026-08-11",)}
38+
append pattern {(?=.*"entry-point": "1000",)}
39+
append pattern {(?=.*"size": "20")}
40+
append pattern {(?=.*"identifier": "test-sid",)}
41+
append pattern {(?=.*"sid": "1000")}
42+
append pattern {(?=.*"identifier": "/test-sid:test-container",)}
43+
append pattern {(?=.*"sid": "1001")}
44+
append pattern {(?=.*"identifier": "/test-sid:test-container/test-leaf1",)}
45+
append pattern {(?=.*"sid": "1002")}
46+
append pattern {(?=.*"identifier": "/test-sid:test-container/test-leaf2",)}
47+
append pattern {(?=.*"sid": "1003")}
48+
append pattern {(?!.*sid-file-status)}
49+
append pattern {(?!.*"status")}
50+
51+
ly_cmd "verb error"
52+
ly_cmd "add $mdir/test-sid-v1.yang"
53+
ly_cmd "sid generate 1000:20 published test-sid" $pattern
54+
}}
55+
56+
test sid_update {} {
57+
-setup $ly_setup -cleanup $ly_cleanup -body {
58+
set pattern "(?s)^"
59+
append pattern {.*"module-name": "test-sid",}
60+
append pattern {.*"module-revision": "2026-08-11",}
61+
append pattern {.*"sid-file-version": 1,}
62+
append pattern {.*"sid-file-status": "unpublished",}
63+
append pattern {.*"entry-point": "1000",}
64+
append pattern {.*"size": "20"}
65+
append pattern {.*"identifier": "test-sid",}
66+
append pattern {.*"status": "unstable",}
67+
append pattern {.*"sid": "1000"}
68+
append pattern {.*"identifier": "/test-sid:test-container",}
69+
append pattern {.*"status": "unstable",}
70+
append pattern {.*"sid": "1001"}
71+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf1",}
72+
append pattern {.*"status": "unstable",}
73+
append pattern {.*"sid": "1002"}
74+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf2",}
75+
append pattern {.*"status": "obsolete",}
76+
append pattern {.*"sid": "1003"}
77+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf3",}
78+
append pattern {.*"status": "unstable",}
79+
append pattern {.*"sid": "1004"}
80+
81+
ly_cmd "verb error"
82+
ly_cmd "add $mdir/test-sid-v2.yang"
83+
ly_cmd "sid update $ddir/test.sid test-sid" $pattern
84+
}}
85+
86+
test sid_update_published {} {
87+
-setup $ly_setup -cleanup $ly_cleanup -body {
88+
set pattern "(?s)^"
89+
append pattern {(?=.*"module-name": "test-sid",)}
90+
append pattern {(?=.*"module-revision": "2026-08-11",)}
91+
append pattern {(?=.*"sid-file-version": 1,)}
92+
append pattern {(?=.*"entry-point": "1000",)}
93+
append pattern {(?=.*"size": "20")}
94+
append pattern {(?=.*"identifier": "test-sid",)}
95+
append pattern {(?=.*"sid": "1000")}
96+
append pattern {(?=.*"identifier": "/test-sid:test-container",)}
97+
append pattern {(?=.*"sid": "1001")}
98+
append pattern {(?=.*"identifier": "/test-sid:test-container/test-leaf1",)}
99+
append pattern {(?=.*"sid": "1002")}
100+
append pattern {(?=.*"identifier": "/test-sid:test-container/test-leaf2",)}
101+
append pattern {(?=.*"status": "obsolete",)}
102+
append pattern {(?=.*"sid": "1003")}
103+
append pattern {(?=.*"identifier": "/test-sid:test-container/test-leaf3",)}
104+
append pattern {(?=.*"sid": "1004")}
105+
append pattern {(?!.*sid-file-status)}
106+
append pattern {(?!.*"unstable")}
107+
108+
ly_cmd "verb error"
109+
ly_cmd "add $mdir/test-sid-v2.yang"
110+
ly_cmd "sid update $ddir/test.sid published test-sid" $pattern
111+
}}
112+
113+
test sid_range_add {} {
114+
-setup $ly_setup -cleanup $ly_cleanup -body {
115+
set pattern "^(?!.*sid-file-version)"
116+
append pattern {.*"module-name": "test-sid",}
117+
append pattern {.*"module-revision": "2026-08-11",}
118+
append pattern {.*"description": "Generated by libyang }
119+
append pattern {.*"entry-point": "1000",}
120+
append pattern {.*"size": "20"}
121+
append pattern {.*"entry-point": "2000",}
122+
append pattern {.*"size": "10"}
123+
append pattern {.*"identifier": "test-sid",}
124+
append pattern {.*"status": "unstable",}
125+
append pattern {.*"sid": "1000"}
126+
append pattern {.*"identifier": "/test-sid:test-container",}
127+
append pattern {.*"status": "unstable",}
128+
append pattern {.*"sid": "1001"}
129+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf1",}
130+
append pattern {.*"status": "unstable",}
131+
append pattern {.*"sid": "1002"}
132+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf2",}
133+
append pattern {.*"status": "unstable",}
134+
append pattern {.*"sid": "1003"}
135+
136+
ly_cmd "sid range-add 2000:10 $ddir/test.sid" $pattern
137+
}}
138+
139+
test sid_generate_output_file {Test generating .sid file into a file} {
140+
-setup $ly_setup -cleanup $ly_cleanup -body {
141+
set pattern "(?s)^"
142+
append pattern {.*"module-name": "test-sid",}
143+
append pattern {.*"module-revision": "2026-08-11",}
144+
append pattern {.*"sid-file-status": "unpublished",}
145+
append pattern {.*"entry-point": "1000",}
146+
append pattern {.*"size": "20"}
147+
append pattern {.*"identifier": "test-sid",}
148+
append pattern {.*"sid": "1000"}
149+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf2",}
150+
append pattern {.*"sid": "1003"}
151+
152+
ly_cmd "verb error"
153+
ly_cmd "add $mdir/test-sid-v1.yang"
154+
ly_cmd "sid -o test_output.sid generate 1000:20 test-sid"
155+
156+
if {![file exists "test_output.sid"]} {
157+
error "Test failed: yanglint did not create 'test_output.sid'!"
158+
}
159+
160+
set fp [open "test_output.sid" r]
161+
set file_data [read $fp]
162+
close $fp
163+
164+
if {![regexp $pattern $file_data]} {
165+
error "Test failed: The file content did not match!\nFile contained:\n$file_data"
166+
}
167+
168+
file delete "test_output.sid"
169+
}}
170+
171+
cleanupTests
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module test-sid {
2+
namespace "test:module:test-sid";
3+
prefix test-sid;
4+
5+
description
6+
"Test module for testing sid generation, update and range-add.";
7+
8+
revision 2026-08-11;
9+
10+
container test-container {
11+
leaf test-leaf1 {
12+
type string;
13+
}
14+
leaf test-leaf2 {
15+
type string;
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module test-sid {
2+
namespace "test:module:test-sid";
3+
prefix test-sid;
4+
5+
description
6+
"Test module for testing sid generation, update and range-add.";
7+
8+
revision 2026-08-11;
9+
10+
container test-container {
11+
leaf test-leaf1 {
12+
type string;
13+
}
14+
leaf test-leaf3 {
15+
type string;
16+
}
17+
}
18+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}]
2+
3+
set mdir $::env(YANG_MODULES_DIR)
4+
set ddir $::env(TESTS_DIR)/data
5+
6+
test sid_generate {} {
7+
set pattern "(?s)^"
8+
append pattern {.*"module-name": "test-sid",}
9+
append pattern {.*"module-revision": "2026-08-11",}
10+
append pattern {.*"sid-file-status": "unpublished",}
11+
append pattern {.*"description": "Generated by libyang }
12+
append pattern {.*"entry-point": "1000",}
13+
append pattern {.*"size": "20"}
14+
append pattern {.*"namespace": "module",}
15+
append pattern {.*"identifier": "test-sid",}
16+
append pattern {.*"status": "unstable",}
17+
append pattern {.*"sid": "1000"}
18+
append pattern {.*"namespace": "data",}
19+
append pattern {.*"identifier": "/test-sid:test-container",}
20+
append pattern {.*"status": "unstable",}
21+
append pattern {.*"sid": "1001"}
22+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf1",}
23+
append pattern {.*"status": "unstable",}
24+
append pattern {.*"sid": "1002"}
25+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf2",}
26+
append pattern {.*"status": "unstable",}
27+
append pattern {.*"sid": "1003"}
28+
append pattern ".*"
29+
30+
ly_cmd "-Q -g 1000:20 $mdir/test-sid-v1.yang" $pattern
31+
} {}
32+
33+
test sid_generate_published {} {
34+
set pattern "(?s)^"
35+
append pattern {(?=.*"module-name": "test-sid")}
36+
append pattern {(?=.*"module-revision": "2026-08-11")}
37+
append pattern {(?=.*"entry-point": "1000")}
38+
append pattern {(?=.*"size": "20")}
39+
append pattern {(?=.*"identifier": "/test-sid:test-container/test-leaf2")}
40+
append pattern {(?=.*"sid": "1003")}
41+
append pattern {(?!.*sid-file-status)}
42+
append pattern {(?!.*"status")}
43+
append pattern ".*"
44+
45+
ly_cmd "-Q -g 1000:20 -U $mdir/test-sid-v1.yang" $pattern
46+
} {}
47+
48+
test sid_update {} {
49+
set pattern "(?s)^"
50+
append pattern {.*"module-name": "test-sid",}
51+
append pattern {.*"module-revision": "2026-08-11",}
52+
append pattern {.*"sid-file-version": 1,}
53+
append pattern {.*"sid-file-status": "unpublished",}
54+
append pattern {.*"description": "Generated by libyang }
55+
append pattern {.*"entry-point": "1000",}
56+
append pattern {.*"size": "20"}
57+
append pattern {.*"namespace": "module",}
58+
append pattern {.*"identifier": "test-sid",}
59+
append pattern {.*"status": "unstable",}
60+
append pattern {.*"sid": "1000"}
61+
append pattern {.*"identifier": "/test-sid:test-container",}
62+
append pattern {.*"status": "unstable",}
63+
append pattern {.*"sid": "1001"}
64+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf1",}
65+
append pattern {.*"status": "unstable",}
66+
append pattern {.*"sid": "1002"}
67+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf2",}
68+
append pattern {.*"status": "obsolete",}
69+
append pattern {.*"sid": "1003"}
70+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf3",}
71+
append pattern {.*"status": "unstable",}
72+
append pattern {.*"sid": "1004"}
73+
append pattern ".*"
74+
75+
ly_cmd "-Q -u $ddir/test.sid $mdir/test-sid-v2.yang" $pattern
76+
} {}
77+
78+
test sid_update_published {} {
79+
set pattern "(?s)^"
80+
append pattern {(?=.*"module-name": "test-sid")}
81+
append pattern {(?=.*"sid-file-version": 1,)}
82+
append pattern {(?=.*"identifier": "/test-sid:test-container/test-leaf2")}
83+
append pattern {(?=.*"status": "obsolete")}
84+
append pattern {(?=.*"sid": "1003")}
85+
append pattern {(?=.*"identifier": "/test-sid:test-container/test-leaf3")}
86+
append pattern {(?=.*"sid": "1004")}
87+
append pattern {(?!.*sid-file-status)}
88+
append pattern {(?!.*"unstable")}
89+
append pattern ".*"
90+
91+
ly_cmd "-Q -u $ddir/test.sid -U $mdir/test-sid-v2.yang" $pattern
92+
} {}
93+
94+
test sid_update_range_add {} {
95+
set pattern "(?s)^"
96+
append pattern {.*"module-name": "test-sid",}
97+
append pattern {.*"module-revision": "2026-08-11",}
98+
append pattern {.*"sid-file-version": 1,}
99+
append pattern {.*"sid-file-status": "unpublished",}
100+
append pattern {.*"description": "Generated by libyang }
101+
append pattern {.*"entry-point": "1000",}
102+
append pattern {.*"size": "20"}
103+
append pattern {.*"entry-point": "2000",}
104+
append pattern {.*"size": "10"}
105+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf2",}
106+
append pattern {.*"status": "obsolete",}
107+
append pattern {.*"sid": "1003"}
108+
append pattern {.*"identifier": "/test-sid:test-container/test-leaf3",}
109+
append pattern {.*"status": "unstable",}
110+
append pattern {.*"sid": "1004"}
111+
append pattern ".*"
112+
113+
ly_cmd "-Q -u $ddir/test.sid -r 2000:10 $mdir/test-sid-v2.yang" $pattern
114+
} {}
115+
116+
test sid_duplicate_range {} {
117+
set pattern "can be specified only once"
118+
119+
ly_cmd_err "-g 1000:20 -r 2000:10 $mdir/test-sid-v1.yang" $pattern
120+
} {}
121+
122+
test sid_range_add_without_update {} {
123+
set pattern "can be used only in combination with"
124+
125+
ly_cmd_err "-r 2000:10 $mdir/test-sid-v1.yang" $pattern
126+
} {}
127+
128+
test sid_generate_with_update {} {
129+
set pattern "cannot be combined with"
130+
131+
ly_cmd_err "-g 1000:20 -u $ddir/test.sid $mdir/test-sid-v2.yang" $pattern
132+
} {}
133+
134+
cleanupTests

tools/lint/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ set(lintsrc
1515
cmd_verb.c
1616
cmd_debug.c
1717
cmd_sample.c
18+
cmd_sid.c
1819
ietf.c
1920
yl_opt.c
2021
yl_schema_features.c

0 commit comments

Comments
 (0)