Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions tests/yanglint/interactive/sample-skeleton.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}]

test print_yang {} {
-setup $ly_setup -cleanup $ly_cleanup -body {
ly_cmd "load modleaf"
ly_cmd "print -f yang modleaf" "leaf lfl"
}}

test skeleton_generate_xml {Test generating xml skeleton to stdout and to file} {
-setup $ly_setup -cleanup $ly_cleanup -body {
set pattern "(?s)^"
append pattern {.*<main-box xmlns="urn:ietf:params:xml:ns:yang:skeleton-complex">}
append pattern {.*<empty-leaf/>}
append pattern {.*<bool-leaf>true</bool-leaf>}
append pattern {.*<num32-leaf>-100</num32-leaf>}
append pattern {.*<num64-leaf>9999999999</num64-leaf>}
append pattern {.*<str-leaf>hello</str-leaf>}
append pattern {.*<ll-empty></ll-empty>}
append pattern {.*<ll-numbers>10</ll-numbers>}
append pattern {.*<ll-numbers>20</ll-numbers>}
append pattern {.*<a-leaf/>}
append pattern {.*<c2-leaf>default-choice-val</c2-leaf>}
append pattern {.*<server-list>}
append pattern {.*<id/>}
append pattern {.*<config>}
append pattern {.*<ip/>}
append pattern {.*</config>}
append pattern {.*</server-list>}
append pattern {.*<custom-data/>}
append pattern {.*<custom-xml/>}
append pattern {.*<aug-leaf xmlns="urn:ietf:params:xml:ns:yang:skeleton-augment">augmented-value</aug-leaf>}
append pattern {.*<aug-ll xmlns="urn:ietf:params:xml:ns:yang:skeleton-augment">1</aug-ll>}
append pattern {.*<aug-ll xmlns="urn:ietf:params:xml:ns:yang:skeleton-augment">2</aug-ll>}
append pattern {.*</main-box>}
append pattern ".*"

ly_cmd "load skeleton"
ly_cmd "load skeleton-augment"
ly_cmd "sample -f xml skeleton" $pattern

ly_cmd "sample -f xml -o test_output.xml skeleton"

if {![file exists "test_output.xml"]} {
error "Test failed: yanglint did not create 'test_output.xml'!"
}

set fp [open "test_output.xml" r]
set file_data [read $fp]
close $fp

if {![regexp $pattern $file_data]} {
error "Test failed: The file content did not match!\nFile contained:\n$file_data"
}

file delete "test_output.xml"
}}

test skeleton_generate_json {} {
-setup $ly_setup -cleanup $ly_cleanup -body {
set pattern "(?s)^"
append pattern {.*"skeleton:main-box": \{}
append pattern {.*"empty-leaf": \[null\],}
append pattern {.*"bool-leaf": true,}
append pattern {.*"num32-leaf": -100,}
append pattern {.*"num64-leaf": "9999999999",}
append pattern {.*"str-leaf": "hello",}
append pattern {.*"ll-empty": \[\],}
append pattern {.*"ll-numbers": \[}
append pattern {.*10,}
append pattern {.*20}
append pattern {.*],}
append pattern {.*"a-leaf": null,}
append pattern {.*"c2-leaf": "default-choice-val",}
append pattern {.*"server-list": \[}
append pattern {.*\{}
append pattern {.*"id": null,}
append pattern {.*"config": \{}
append pattern {.*"ip": null}
append pattern {.*\}}
append pattern {.*\}}
append pattern {.*\],}
append pattern {.*"custom-data": \{\},}
append pattern {.*"custom-xml": \{\},}
append pattern {.*"skeleton-augment:aug-leaf": "augmented-value",}
append pattern {.*"skeleton-augment:aug-ll": \[}
append pattern {.*1,}
append pattern {.*2}
append pattern {.*\]}
append pattern {.*\}}
append pattern ".*"

ly_cmd "load skeleton"
ly_cmd "load skeleton-augment"

ly_cmd "sample -f json skeleton" $pattern
}}
26 changes: 26 additions & 0 deletions tests/yanglint/modules/bad-ietf-prefix-namespace.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module bad-ietf-prefix-namespace {
yang-version 1.1;
namespace "urn:wrong:namespace";
prefix bpn;

organization "IETF NETMOD Working Group";
contact "WG Web: <https://datatracker.ietf.org/wg/netmod/>";

description
"Copyright (c) 2026 IETF Trust and the persons identified as
authors of the code. All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, is permitted pursuant to, and subject
to the license terms contained in, the Revised BSD License
set forth in Section 4.c of the IETF Trust's Legal Provisions
Relating to IETF Documents
(https://trustee.ietf.org/license-info).

This version of this YANG module is part of RFC XXXX; see
the RFC itself for full legal notices.";

revision 2026-07-08 {
// Triggers 4.8: Missing "reference" and "description" inside the revision block
}
}
19 changes: 19 additions & 0 deletions tests/yanglint/modules/ietf-bad-boilerplate.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module ietf-bad-boilerplate {
yang-version 1.1;
namespace "urn:ietf:params:xml:ns:yang:ietf-bad-boilerplate";
prefix ibb;

organization "IETF NETMOD Working Group";
contact "WG Web: <https://datatracker.ietf.org/wg/netmod/>";

// 1. Missing IETF Trust Copyright (Triggers 3.1)
// 2. Missing "This version of this YANG module is part of RFC..." (Triggers Appendix B)
// 3. Uses the word "MUST", but lacks the RFC 8174 text block (Triggers BCP 14 check)
description
"This module MUST intentionally fail the text boilerplate checks.";

revision 2026-07-08 {
description "Initial revision.";
reference "RFC XXXX: Test Module";
}
}
60 changes: 60 additions & 0 deletions tests/yanglint/modules/ietf-correct.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module ietf-correct {
yang-version 1.1;
namespace "urn:ietf:params:xml:ns:yang:ietf-correct";
prefix isc;

organization
"IETF NETMOD Working Group";

contact
"WG Web: <https://datatracker.ietf.org/wg/netmod/>";

description
"Copyright (c) 2026 IETF Trust and the persons identified as
authors of the code. All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, is permitted pursuant to, and subject
to the license terms contained in, the Revised BSD License
set forth in Section 4.c of the IETF Trust's Legal Provisions
Relating to IETF Documents
(https://trustee.ietf.org/license-info).

This version of this YANG module is part of RFC XXXX; see
the RFC itself for full legal notices.";

revision 2026-07-08 {
description
"Initial revision.";
reference
"RFC XXXX: Test Module";
}

container system-info {
description
"A simple top-level container to hold our data. Notice it is
not mandatory.";

leaf system-name {
type string;
description
"The configured name of the system.";
}

leaf status {
type enumeration {
enum active {
description
"The system is currently active and processing.";
}
enum inactive {
description
"The system is currently inactive.";
}
}
description
"The current operational status of the system. Notice there
is no explicit 'config true' or 'mandatory false' here.";
}
}
}
66 changes: 66 additions & 0 deletions tests/yanglint/modules/ietf-defaults-and-mandatory.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module ietf-defaults-and-mandatory {
yang-version 1.1;
namespace "urn:ietf:params:xml:ns:yang:ietf-defaults-and-mandatory";
prefix idm;

organization "IETF NETMOD Working Group";
contact "WG Web: <https://datatracker.ietf.org/wg/netmod/>";
description
"Copyright (c) 2026 IETF Trust and the persons identified as
authors of the code. All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, is permitted pursuant to, and subject
to the license terms contained in, the Revised BSD License
set forth in Section 4.c of the IETF Trust's Legal Provisions
Relating to IETF Documents
(https://trustee.ietf.org/license-info).

This version of this YANG module is part of RFC XXXX; see
the RFC itself for full legal notices.";

revision 2026-07-08 {
description "Initial revision.";
reference "RFC XXXX: Test Module";
}

extension ext1 {
description "Ext description";
argument arg1 {
// Triggers 4.4: yin-element given with default
yin-element false;
}
}

// Triggers 4.10: Top-level node cannot be mandatory
leaf top-mand-leaf {
type string;
description "Top level mandatory";
mandatory true;
}

leaf bad-defaults-leaf {
type string;
description "Leaf with explicit defaults";
// Triggers 4.4: config true
config true;
// Triggers 4.4: status current
status current;
// Triggers 4.4: mandatory false
mandatory false;
}

list bad-list {
key "k";
description "List with explicit defaults";
ordered-by system;
leaf k {
type string;
description "Key";
}
// Triggers 4.4: min-elements 0
min-elements 0;
// Triggers 4.4: max-elements unbounded
max-elements unbounded;
}
}
62 changes: 62 additions & 0 deletions tests/yanglint/modules/ietf-empty-type.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module ietf-empty-type {
yang-version 1.1;
namespace "urn:ietf:params:xml:ns:yang:ietf-empty-type";
prefix eett;

organization
"IETF NETMOD (Network Modeling) Working Group";

contact
"WG Web: <https://datatracker.ietf.org/wg/netmod/>
WG List: <mailto:netmod@ietf.org>

Author: Test Author
<mailto:test@example.com>";

description
"Copyright (c) 2026 IETF Trust and the persons identified as
authors of the code. All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, is permitted pursuant to, and subject
to the license terms contained in, the Revised BSD License
set forth in Section 4.c of the IETF Trust's Legal Provisions
Relating to IETF Documents
(https://trustee.ietf.org/license-info).

This version of this YANG module is part of RFC XXXX; see
the RFC itself for full legal notices.";

revision 2026-07-10 {
description
"Initial revision. Testing empty types in keys and leaf-lists.";
reference
"RFC XXXX: Guidelines for Authors and Reviewers of YANG Data Models";
}

container top-container {
description
"A top level container to hold our test lists.";

/* TEST 1: Trigger the 'empty' type in list key warning */
list list-with-empty-key {
key "id";
description
"A list to test the empty key warning.";

/* TEST 2: Trigger the 'empty' type in leaf */
leaf id {
type empty;
description
"Key leaf of type empty.";
}
}

/* TEST 3: Trigger the 'empty' type in leaf-list warning */
leaf-list leaf-list-with-empty-type {
type empty;
description
"A leaf-list to test the empty type warning.";
}
}
}
Loading
Loading