diff --git a/Makefile b/Makefile index 0de5442e..d639d0a6 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,9 @@ test: debug test_plantuml: test plantuml debug/tests/puml/*.puml +document_test_cases: test_plantuml + python3 util/generate_test_cases_docs.py + .PHONY: clang-format clang-format: docker run --rm -v $(CURDIR):/root/sources bkryza/clang-format-check:1.2 diff --git a/README.md b/README.md index 58f8ec79..44eb556f 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,15 @@ To build under Ubuntu follow the following steps: make release # or make debug for debug builds ``` +## Documentation + +### Examples + +#### Test cases + +The build-in test cases used for unit testing of the clang-uml, can be browsed [here](./docs/test_cases.md) + + ## LICENSE Copyright 2021-present Bartek Kryza diff --git a/docs/test_cases.md b/docs/test_cases.md new file mode 100644 index 00000000..7d584581 --- /dev/null +++ b/docs/test_cases.md @@ -0,0 +1,19 @@ +# Test cases index +## Class diagrams + * [t00002](./test_cases/t00002.md) - Basic class inheritance + * [t00003](./test_cases/t00003.md) - Class field and methods + * [t00004](./test_cases/t00004.md) - Nested classes and enums + * [t00005](./test_cases/t00005.md) - Basic class field relationships + * [t00006](./test_cases/t00006.md) - Class field relationships inferred from templates + * [t00007](./test_cases/t00007.md) - Smart pointers + * [t00008](./test_cases/t00008.md) - Template and template template relationships + * [t00009](./test_cases/t00009.md) - Template instantiation + * [t00010](./test_cases/t00010.md) - Basic template instantiation + * [t00011](./test_cases/t00011.md) - Friend relationships + * [t00012](./test_cases/t00012.md) - Advanced template instantiations + * [t00013](./test_cases/t00013.md) - Template instantiation relationships + * [t00014](./test_cases/t00014.md) - Alias template instantiation +## Sequence diagrams + * [t20001](./test_cases/t20001.md) - Basic sequence diagram +## Configuration diagrams + * [t90000](./test_cases/t90000.md) - Basic config test diff --git a/docs/test_cases/t00002.md b/docs/test_cases/t00002.md new file mode 100644 index 00000000..0132702c --- /dev/null +++ b/docs/test_cases/t00002.md @@ -0,0 +1,63 @@ +# t00002 - Basic class inheritance +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00002_class: + type: class + glob: + - ../../tests/t00002/t00002.cc + using_namespace: + - clanguml::t00002 + include: + namespaces: + - clanguml::t00002 + +``` +## Source code +```cpp +#include + +namespace clanguml { +namespace t00002 { + +class A { +public: + virtual void foo_a() = 0; + virtual void foo_c() = 0; +}; + +class B : public A { +public: + virtual void foo_a() override {} +}; + +class C : public A { +public: + virtual void foo_c() override {} +}; + +class D : public B, public C { +public: + void foo_a() override + { + for (auto a : as) + a->foo_a(); + } + + void foo_c() override + { + for (auto a : as) + a->foo_c(); + } + +private: + std::vector as; +}; +} +} + +``` +## Generated UML diagrams +![t00002_class](./t00002_class.png "Basic class inheritance") diff --git a/docs/test_cases/t00002_class.png b/docs/test_cases/t00002_class.png new file mode 100644 index 00000000..0f78640c Binary files /dev/null and b/docs/test_cases/t00002_class.png differ diff --git a/docs/test_cases/t00003.md b/docs/test_cases/t00003.md new file mode 100644 index 00000000..39364e97 --- /dev/null +++ b/docs/test_cases/t00003.md @@ -0,0 +1,79 @@ +# t00003 - Class field and methods +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00003_class: + type: class + glob: + - ../../tests/t00003/t00003.cc + using_namespace: + - clanguml::t00003 + include: + namespaces: + - clanguml::t00003 + +``` +## Source code +```cpp +#include + +namespace clanguml { +namespace t00003 { + +class A { +public: + A() = default; + A(int i) + : private_member{i} + { + } + A(A &&) = default; + A(const A &) = default; + virtual ~A() = default; + + void basic_method() {} + static int static_method() { return 0; } + void const_method() const {} + auto auto_method() { return 1; } + + auto double_int(const int i) { return 2 * i; } + auto sum(const double a, const double b) { return a + b; } + + auto default_int(int i = 12) { return i + 10; } + std::string default_string(int i, std::string s = "abc") + { + return s + std::to_string(i); + } + + static A create_from_int(int i) { return A(i); } + + int public_member; + static int static_int; + static const int static_const_int = 1; + static const auto auto_member{10UL}; + +protected: + void protected_method() {} + + int protected_member; + + std::function compare = [this](const int v) { + return private_member > v; + }; + +private: + void private_method() {} + + int private_member; + int a, b, c; +}; + +int A::static_int = 1; +} +} + +``` +## Generated UML diagrams +![t00003_class](./t00003_class.png "Class field and methods") diff --git a/docs/test_cases/t00003_class.png b/docs/test_cases/t00003_class.png new file mode 100644 index 00000000..5d452823 Binary files /dev/null and b/docs/test_cases/t00003_class.png differ diff --git a/docs/test_cases/t00004.md b/docs/test_cases/t00004.md new file mode 100644 index 00000000..84595dd6 --- /dev/null +++ b/docs/test_cases/t00004.md @@ -0,0 +1,44 @@ +# t00004 - Nested classes and enums +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00004_class: + type: class + glob: + - ../../tests/t00004/t00004.cc + using_namespace: + - clanguml::t00004 + - clanguml::t00004::A + - clanguml::t00004::A::AA + include: + namespaces: + - clanguml::t00004 + +``` +## Source code +```cpp +namespace clanguml { +namespace t00004 { + +class A { +public: + void foo() const {} + + class AA { + public: + enum class Lights { Green, Yellow, Red }; + + class AAA { + }; + }; + + void foo2() const {} +}; +} +} + +``` +## Generated UML diagrams +![t00004_class](./t00004_class.png "Nested classes and enums") diff --git a/docs/test_cases/t00004_class.png b/docs/test_cases/t00004_class.png new file mode 100644 index 00000000..cd496e08 Binary files /dev/null and b/docs/test_cases/t00004_class.png differ diff --git a/docs/test_cases/t00005.md b/docs/test_cases/t00005.md new file mode 100644 index 00000000..a490f9bd --- /dev/null +++ b/docs/test_cases/t00005.md @@ -0,0 +1,78 @@ +# t00005 - Basic class field relationships +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00005_class: + type: class + glob: + - ../../tests/t00005/t00005.cc + using_namespace: + - clanguml::t00005 + include: + namespaces: + - clanguml::t00005 + +``` +## Source code +```cpp +namespace clanguml { +namespace t00005 { +class A { +}; + +class B { +}; + +class C { +}; + +class D { +}; + +class E { +}; + +class F { +}; + +class G { +}; + +class H { +}; + +class I { +}; + +class J { +}; + +class K { +}; + +class R { +public: + int some_int; + int *some_int_pointer; + int **some_int_pointer_pointer; + int &some_int_reference; + A a; + B *b; + C &c; + const D *d; + const E &e{}; + F &&f; + G **g; + H ***h; + I *&i; + volatile J *j; + mutable K *k; +}; +} +} + +``` +## Generated UML diagrams +![t00005_class](./t00005_class.png "Basic class field relationships") diff --git a/docs/test_cases/t00005_class.png b/docs/test_cases/t00005_class.png new file mode 100644 index 00000000..582efef0 Binary files /dev/null and b/docs/test_cases/t00005_class.png differ diff --git a/docs/test_cases/t00006.md b/docs/test_cases/t00006.md new file mode 100644 index 00000000..92aebbe5 --- /dev/null +++ b/docs/test_cases/t00006.md @@ -0,0 +1,106 @@ +# t00006 - Class field relationships inferred from templates +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00006_class: + type: class + glob: + - ../../tests/t00006/t00006.cc + using_namespace: + - clanguml::t00006 + include: + namespaces: + - clanguml::t00006 + +``` +## Source code +```cpp +#include +#include + +namespace clanguml { +namespace t00006 { +class A { +}; + +class B { +}; + +class C { +}; + +class D { +}; + +class E { +}; + +class F { +}; + +class G { +}; + +class H { +}; + +class I { +}; + +class J { +}; + +class K { +}; + +class L { +}; + +class M { +}; + +class N { +}; + +class NN { +}; + +class NNN { +}; + +template class custom_container { +public: + std::vector data; +}; + +class R { +public: + std::vector a; + std::vector b; + + std::map c; + std::map d; + + custom_container e; + + std::vector> f; + std::map> g; + + std::array h; + std::array i; + + J j[10]; + K *k[20]; + + std::vector> lm; + + std::tuple ns; +}; +} +} + +``` +## Generated UML diagrams +![t00006_class](./t00006_class.png "Class field relationships inferred from templates") diff --git a/docs/test_cases/t00006_class.png b/docs/test_cases/t00006_class.png new file mode 100644 index 00000000..52d921f9 Binary files /dev/null and b/docs/test_cases/t00006_class.png differ diff --git a/docs/test_cases/t00007.md b/docs/test_cases/t00007.md new file mode 100644 index 00000000..8655000d --- /dev/null +++ b/docs/test_cases/t00007.md @@ -0,0 +1,44 @@ +# t00007 - Smart pointers +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00007_class: + type: class + glob: + - ../../tests/t00007/t00007.cc + using_namespace: + - clanguml::t00007 + include: + namespaces: + - clanguml::t00007 + +``` +## Source code +```cpp +#include + +namespace clanguml { +namespace t00007 { +class A { +}; + +class B { +}; + +class C { +}; + +class R { +public: + std::unique_ptr a; + std::shared_ptr b; + std::weak_ptr c; +}; +} +} + +``` +## Generated UML diagrams +![t00007_class](./t00007_class.png "Smart pointers") diff --git a/docs/test_cases/t00007_class.png b/docs/test_cases/t00007_class.png new file mode 100644 index 00000000..55aeaa71 Binary files /dev/null and b/docs/test_cases/t00007_class.png differ diff --git a/docs/test_cases/t00008.md b/docs/test_cases/t00008.md new file mode 100644 index 00000000..f0e02eb0 --- /dev/null +++ b/docs/test_cases/t00008.md @@ -0,0 +1,57 @@ +# t00008 - Template and template template relationships +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00008_class: + type: class + glob: + - ../../tests/t00008/t00008.cc + using_namespace: + - clanguml::t00008 + include: + namespaces: + - clanguml::t00008 + +``` +## Source code +```cpp +#include +#include + +namespace clanguml { +namespace t00008 { + +using CMP = bool (*)(const int, const int); + +template class A { +public: + T value; + T *pointer; + T &reference; + std::vector

values; + std::array ints; + + CMP comparator; +}; + +template struct Vector { + std::vector values; +}; + +template typename C> struct B { + C template_template; +}; + +struct D { + B ints; + + void add(int i) { ints.template_template.values.push_back(i); } +}; +} +} + +``` +## Generated UML diagrams +![t00008_class](./t00008_class.png "Template and template template relationships") diff --git a/docs/test_cases/t00008_class.png b/docs/test_cases/t00008_class.png new file mode 100644 index 00000000..c50d183d Binary files /dev/null and b/docs/test_cases/t00008_class.png differ diff --git a/docs/test_cases/t00009.md b/docs/test_cases/t00009.md new file mode 100644 index 00000000..e480f065 --- /dev/null +++ b/docs/test_cases/t00009.md @@ -0,0 +1,42 @@ +# t00009 - Template instantiation +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00009_class: + type: class + glob: + - ../../tests/t00009/t00009.cc + using_namespace: + - clanguml::t00009 + include: + namespaces: + - clanguml::t00009 + +``` +## Source code +```cpp +#include +#include + +namespace clanguml { +namespace t00009 { + +template class A { +public: + T value; +}; + +class B { +public: + A aint; + A *astring; + A> &avector; +}; +} +} + +``` +## Generated UML diagrams +![t00009_class](./t00009_class.png "Template instantiation") diff --git a/docs/test_cases/t00009_class.png b/docs/test_cases/t00009_class.png new file mode 100644 index 00000000..3c5c234f Binary files /dev/null and b/docs/test_cases/t00009_class.png differ diff --git a/docs/test_cases/t00010.md b/docs/test_cases/t00010.md new file mode 100644 index 00000000..4f66111b --- /dev/null +++ b/docs/test_cases/t00010.md @@ -0,0 +1,46 @@ +# t00010 - Basic template instantiation +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00010_class: + type: class + glob: + - ../../tests/t00010/t00010.cc + using_namespace: + - clanguml::t00010 + include: + namespaces: + - clanguml::t00010 + +``` +## Source code +```cpp +#include +#include + +namespace clanguml { +namespace t00010 { + +template class A { +public: + T first; + P second; +}; + +template class B { +public: + A astring; +}; + +class C { +public: + B aintstring; +}; +} +} + +``` +## Generated UML diagrams +![t00010_class](./t00010_class.png "Basic template instantiation") diff --git a/docs/test_cases/t00010_class.png b/docs/test_cases/t00010_class.png new file mode 100644 index 00000000..dab84971 Binary files /dev/null and b/docs/test_cases/t00010_class.png differ diff --git a/docs/test_cases/t00011.md b/docs/test_cases/t00011.md new file mode 100644 index 00000000..c957606f --- /dev/null +++ b/docs/test_cases/t00011.md @@ -0,0 +1,56 @@ +# t00011 - Friend relationships +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00011_class: + type: class + glob: + - ../../tests/t00011/t00011.cc + using_namespace: + - clanguml::t00011 + include: + namespaces: + - clanguml::t00011 + +``` +## Source code +```cpp +namespace external { +class C { +}; +} + +namespace clanguml { +namespace t00011 { + +class B; + +template class D { + T value; +}; + +class A { +private: + void foo() {} + friend class B; + friend class external::C; + // TODO + template friend class D; + // TODO + friend class D; + friend class D; +}; + +class B { +public: + void foo() { m_a->foo(); } + A *m_a; +}; +} +} + +``` +## Generated UML diagrams +![t00011_class](./t00011_class.png "Friend relationships") diff --git a/docs/test_cases/t00011_class.png b/docs/test_cases/t00011_class.png new file mode 100644 index 00000000..7a11028b Binary files /dev/null and b/docs/test_cases/t00011_class.png differ diff --git a/docs/test_cases/t00012.md b/docs/test_cases/t00012.md new file mode 100644 index 00000000..f54b6970 --- /dev/null +++ b/docs/test_cases/t00012.md @@ -0,0 +1,59 @@ +# t00012 - Advanced template instantiations +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00012_class: + type: class + glob: + - ../../tests/t00012/t00012.cc + using_namespace: + - clanguml::t00012 + include: + namespaces: + - clanguml::t00012 + +``` +## Source code +```cpp +#include +#include +#include +#include +#include +#include + +namespace clanguml { +namespace t00012 { + +template class A { + T value; + std::variant values; +}; + +template class B { + std::array ints; +}; + +template class C { + std::array ints; +}; + +class R { + A a1; + A a2; + + B<3, 2, 1> b1; + B<1, 1, 1, 1> b2; + + C>>>, 3, 3, + 3> + c1; +}; +} +} + +``` +## Generated UML diagrams +![t00012_class](./t00012_class.png "Advanced template instantiations") diff --git a/docs/test_cases/t00012_class.png b/docs/test_cases/t00012_class.png new file mode 100644 index 00000000..ff7fde5c Binary files /dev/null and b/docs/test_cases/t00012_class.png differ diff --git a/docs/test_cases/t00013.md b/docs/test_cases/t00013.md new file mode 100644 index 00000000..5e60e973 --- /dev/null +++ b/docs/test_cases/t00013.md @@ -0,0 +1,83 @@ +# t00013 - Template instantiation relationships +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00013_class: + type: class + glob: + - ../../tests/t00013/t00013.cc + using_namespace: + - clanguml::t00013 + include: + namespaces: + - clanguml::t00013 + - ABCD + +``` +## Source code +```cpp +#include +#include +#include +#include + +namespace ABCD { +template struct F { + T f; +}; +} +namespace clanguml { +namespace t00013 { + +struct A { + int a; +}; + +struct B { + int b; +}; + +struct C { + int c; +}; + +class R; + +struct D { + int d; + void print(R *r) {} +}; + +template struct E { + T e; +}; + +using namespace ABCD; +class R { +public: + int get_a(A *a) { return a->a; } + int get_b(B &b) { return b.b; } + int get_const_b(const B &b) { return b.b; } + int get_c(C c) { return c.c; } + int get_d(D &&d) { return d.d; } + // Dependency relationship should be rendered only once + int get_d2(D &&d) { return d.d; } + + template T get_e(E e) { return e.e; } + int get_int_e(const E &e) { return e.e; } + int get_int_e2(E &e) { return e.e; } + + template T get_f(const F &f) { return f.f; } + int get_int_f(const F &f) { return f.f; } + +private: + mutable E estring; +}; +} +} + +``` +## Generated UML diagrams +![t00013_class](./t00013_class.png "Template instantiation relationships") diff --git a/docs/test_cases/t00013_class.png b/docs/test_cases/t00013_class.png new file mode 100644 index 00000000..5cef910d Binary files /dev/null and b/docs/test_cases/t00013_class.png differ diff --git a/docs/test_cases/t00014.md b/docs/test_cases/t00014.md new file mode 100644 index 00000000..fccaaeda --- /dev/null +++ b/docs/test_cases/t00014.md @@ -0,0 +1,74 @@ +# t00014 - Alias template instantiation +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t00014_class: + type: class + glob: + - ../../tests/t00014/t00014.cc + using_namespace: + - clanguml::t00014 + include: + namespaces: + - clanguml::t00014 + +``` +## Source code +```cpp +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * These should not be include as they are not + * in ns clanguml::t00014 + */ +template struct clanguml_t00014_A { + T value; +}; + +using clanguml_t00014_AString = clanguml_t00014_A; + +namespace clanguml { +namespace t00014 { + +template struct A { + T t; + P p; +}; + +template using AString = A; + +struct B { + std::string value; +}; + +using BVector = std::vector; +using BVector2 = BVector; + +using AIntString = AString; +using AStringString = AString; +using BStringString = AStringString; + +class R { + //clang-uml: tinst A + A boolstring; + AString floatstring; + AIntString intstring; + AStringString stringstring; + BVector bs; + BVector2 bs2; +}; +} +} + +``` +## Generated UML diagrams +![t00014_class](./t00014_class.png "Alias template instantiation") diff --git a/docs/test_cases/t00014_class.png b/docs/test_cases/t00014_class.png new file mode 100644 index 00000000..1b062b2c Binary files /dev/null and b/docs/test_cases/t00014_class.png differ diff --git a/docs/test_cases/t20001.md b/docs/test_cases/t20001.md new file mode 100644 index 00000000..58146e8d --- /dev/null +++ b/docs/test_cases/t20001.md @@ -0,0 +1,103 @@ +# t20001 - Basic sequence diagram +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t20001_sequence: + type: sequence + glob: + - ../../tests/t20001/t20001.cc + include: + namespaces: + - clanguml::t20001 + exclude: + namespaces: + - clanguml::t20001::detail + using_namespace: + - clanguml::t20001 + start_from: + - usr: "c:@N@clanguml@N@t20001@F@tmain#" + plantuml: + before: + - "' t20001 test sequence diagram" + after: + - 'note over "tmain()": Main test function' + +``` +## Source code +```cpp +#include +#include +#include + +namespace clanguml { +namespace t20001 { + +namespace detail { +struct C { + auto add(int x, int y) { return x + y; } +}; +} + +class A { +public: + A() {} + + int add(int x, int y) { return m_c.add(x, y); } + + int add3(int x, int y, int z) + { + std::vector v; + v.push_back(x); + v.push_back(y); + v.push_back(z); + auto res = add(v[0], v[1]) + v[2]; + log_result(res); + return res; + } + + void log_result(int r) {} + +private: + detail::C m_c{}; +}; + +class B { +public: + B(A &a) + : m_a{a} + { + } + + int wrap_add(int x, int y) + { + auto res = m_a.add(x, y); + m_a.log_result(res); + return res; + } + + int wrap_add3(int x, int y, int z) + { + auto res = m_a.add3(x, y, z); + m_a.log_result(res); + return res; + } + +private: + A &m_a; +}; + +int tmain() +{ + A a; + B b(a); + + return b.wrap_add3(1, 2, 3); +} +} +} + +``` +## Generated UML diagrams +![t20001_sequence](./t20001_sequence.png "Basic sequence diagram") diff --git a/docs/test_cases/t20001_sequence.png b/docs/test_cases/t20001_sequence.png new file mode 100644 index 00000000..7f9f6cc0 Binary files /dev/null and b/docs/test_cases/t20001_sequence.png differ diff --git a/docs/test_cases/t90000.md b/docs/test_cases/t90000.md new file mode 100644 index 00000000..09064c3b --- /dev/null +++ b/docs/test_cases/t90000.md @@ -0,0 +1,31 @@ +# t90000 - Basic config test +## Config +```yaml +compilation_database_dir: .. +output_directory: puml +diagrams: + t90000_class: + type: class + plantuml: + before: + - 'class "Foo" as C_001' + - 'class C_001 {' + - ' +int value' + - '}' + - 'C_001 <|-- ArrayList' + - 'note top of C_001: This is a very important class.' + - 'note "This is a\nfloating note" as N1' + - 'note "This note is connected\nto several objects." as N2' + - 'C_001 .. N2' + - 'N2 .. ArrayList' + - 'class "Boo" as C_002' + - 'class C_002 {' + - '}' + +``` +## Source code +```cpp + +``` +## Generated UML diagrams +![t90000_class](./t90000_class.png "Basic config test") diff --git a/docs/test_cases/t90000_class.png b/docs/test_cases/t90000_class.png new file mode 100644 index 00000000..bf1266fe Binary files /dev/null and b/docs/test_cases/t90000_class.png differ diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml new file mode 100644 index 00000000..56893373 --- /dev/null +++ b/tests/test_cases.yaml @@ -0,0 +1,49 @@ +test_cases: + Class diagrams: + - name: t00002 + title: Basic class inheritance + description: + - name: t00003 + title: Class field and methods + description: + - name: t00004 + title: Nested classes and enums + description: + - name: t00005 + title: Basic class field relationships + description: + - name: t00006 + title: Class field relationships inferred from templates + description: + - name: t00007 + title: Smart pointers + description: + - name: t00008 + title: Template and template template relationships + description: + - name: t00009 + title: Template instantiation + description: + - name: t00010 + title: Basic template instantiation + description: + - name: t00011 + title: Friend relationships + description: + - name: t00012 + title: Advanced template instantiations + description: + - name: t00013 + title: Template instantiation relationships + description: + - name: t00014 + title: Alias template instantiation + description: + Sequence diagrams: + - name: t20001 + title: Basic sequence diagram + description: + Configuration diagrams: + - name: t90000 + title: Basic config test + description: diff --git a/util/generate_test_cases_docs.py b/util/generate_test_cases_docs.py new file mode 100755 index 00000000..faf47675 --- /dev/null +++ b/util/generate_test_cases_docs.py @@ -0,0 +1,66 @@ +#!/usr/bin/python3 + +## +## util/generate_test_cases_docs.py +## +## Copyright (c) 2021 Bartek Kryza +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + + +import yaml +from shutil import copyfile + +with open(r'tests/test_cases.yaml') as f: + test_groups = yaml.full_load(f)['test_cases'] + + # Generate test_cases.md index + with open(r'docs/test_cases.md', 'w') as tc_index: + tc_index.write("# Test cases index\n") + for test_group, test_cases in test_groups.items(): + tc_index.write("## {}\n".format(test_group)) + for test_case in test_cases: + tc_index.write(" * [{0}](./test_cases/{0}.md) - {1}\n".format( + test_case['name'], test_case['title'])) + + # Generate invididual documentation docs + for test_group, test_cases in test_groups.items(): + for test_case in test_cases: + name = test_case['name'] + with open(r'docs/test_cases/{}.md'.format(name), 'w') as tc: + tc.write("# {} - {}\n".format(name, test_case['title'])) + + # Write out test description + if test_case['description']: + tc.write("{}\n".format(test_case['description'])) + + # Write test config file + config = open('tests/{0}/.clanguml'.format(name), 'r').read() + tc.write("## Config\n") + tc.write("```yaml\n") + tc.write(config) + tc.write("\n```\n") + tc.write("## Source code\n") + tc.write("```cpp\n") + tc.write(open('tests/{0}/{0}.cc'.format(name), 'r').read()) + tc.write("\n```\n") + + # Copy and link the diagram image + config_dict = yaml.full_load(config) + tc.write("## Generated UML diagrams\n") + for diagram_name, _ in config_dict['diagrams'].items(): + copyfile('debug/tests/puml/{}.png'.format(diagram_name), + 'docs/test_cases/{}.png'.format(diagram_name)) + tc.write("![{0}](./{0}.png \"{1}\")\n".format( + diagram_name, test_case["title"]))