diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-08-21 11:00:48 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-08-23 15:33:21 +0200 |
commit | 4c49c81008fc2f22c2eef2e019a11f80cd5464a8 (patch) | |
tree | 09da6796020008e9233716da1a283b30e4ca7ef2 | |
parent | d62cbb609f486becb6603e1712d81ba52788232e (diff) | |
download | rules-cc-4c49c81008fc2f22c2eef2e019a11f80cd5464a8.tar.gz |
Add test verifying lint information is propagated properly
... through all our various rules and forms of libraries.
-rw-r--r-- | tests/test_cases/deps/TARGETS | 13 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/TARGETS | 78 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/bar.cpp | 10 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/bar.hpp | 8 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/bardep.cpp | 9 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/bardep.hpp | 8 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/check-main.sh | 3 | ||||
-rwxr-xr-x | tests/test_cases/deps/lint/expect.py | 24 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/foo.cpp | 10 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/foo.hpp | 8 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/foodep.cpp | 9 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/foodep.hpp | 8 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/main.cpp | 9 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/plain.cpp | 5 | ||||
-rw-r--r-- | tests/test_cases/deps/lint/plain.hpp | 9 | ||||
-rwxr-xr-x | tests/test_cases/deps/lint/pretend_lint.py | 15 | ||||
-rwxr-xr-x | tests/test_cases/deps/lint/summary.py | 27 |
17 files changed, 253 insertions, 0 deletions
diff --git a/tests/test_cases/deps/TARGETS b/tests/test_cases/deps/TARGETS index fb3060a..ece8560 100644 --- a/tests/test_cases/deps/TARGETS +++ b/tests/test_cases/deps/TARGETS @@ -377,6 +377,18 @@ ] , "data": [["TREE", null, "transitive-components"]] } +, "lint": + { "type": ["test_rules", "test_case"] + , "name": ["lint"] + , "targets": ["+test", "+test-shared", "+verifier", "+lint", "+lint-shared"] + , "asserts": + [ "cat lint/report" + , "cat lint-shared/report" + , "./verifier/expect lint/out/invocations.json foo.hpp foo.cpp foodep.hpp foodep.cpp bar.hpp bar.cpp bardep.hpp bardep.cpp plain.hpp plain.cpp main.cpp" + , "./verifier/expect lint-shared/out/invocations.json foo.hpp foo.cpp foodep.hpp foodep.cpp bar.hpp bar.cpp bardep.hpp bardep.cpp plain.hpp plain.cpp main.cpp" + ] + , "data": [["TREE", null, "lint"]] + } , "ALL": { "type": "install" , "deps": @@ -389,6 +401,7 @@ , "install" , "components" , "transitive-components" + , "lint" ] , "tainted": ["test"] } diff --git a/tests/test_cases/deps/lint/TARGETS b/tests/test_cases/deps/lint/TARGETS new file mode 100644 index 0000000..425815b --- /dev/null +++ b/tests/test_cases/deps/lint/TARGETS @@ -0,0 +1,78 @@ +{ "foo": + { "type": ["@", "rules", "CC", "library"] + , "name": ["foo"] + , "hdrs": ["foo.hpp"] + , "srcs": ["foo.cpp"] + , "deps": ["foodep"] + , "components": ["bar"] + } +, "foodep": + { "type": ["@", "rules", "CC", "library"] + , "name": ["foodep"] + , "hdrs": ["foodep.hpp"] + , "srcs": ["foodep.cpp"] + } +, "bar": + { "type": ["@", "rules", "CC", "library"] + , "name": ["bar"] + , "hdrs": ["bar.hpp"] + , "srcs": ["bar.cpp"] + , "deps": ["bardep"] + } +, "bardep": + { "type": ["@", "rules", "CC", "library"] + , "name": ["bardep"] + , "hdrs": ["bardep.hpp"] + , "srcs": ["bardep.cpp"] + } +, "plain": + { "type": ["@", "rules", "CC", "library"] + , "name": ["plain"] + , "arguments_config": ["TEST_SHARED"] + , "shared": + { "type": "if" + , "cond": {"type": "var", "name": "TEST_SHARED"} + , "then": ["yes"] + } + , "hdrs": ["plain.hpp"] + , "srcs": ["plain.cpp"] + , "deps": ["foo"] + } +, "main": + { "type": ["@", "rules", "CC", "binary"] + , "name": ["main"] + , "srcs": ["main.cpp"] + , "private-deps": ["plain"] + } +, "test": + { "type": ["@", "rules", "shell/test", "script"] + , "name": ["test"] + , "test": ["check-main.sh"] + , "deps": ["main"] + } +, "suite": + { "type": ["@", "rules", "test", "suite"] + , "deps": ["test"] + , "stage": ["suite"] + } +, "lint": + { "type": ["@", "rules", "lint", "targets"] + , "targets": ["suite"] + , "tainted": ["test"] + , "linter": ["pretend_lint.py"] + , "summarizer": ["summary.py"] + } +, "lint-shared": + { "type": "configure" + , "target": "lint" + , "tainted": ["lint", "test"] + , "config": {"type": "singleton_map", "key": "TEST_SHARED", "value": true} + } +, "test-shared": + { "type": "configure" + , "target": "test" + , "tainted": ["test"] + , "config": {"type": "singleton_map", "key": "TEST_SHARED", "value": true} + } +, "verifier": {"type": "install", "files": {"expect": "expect.py"}} +} diff --git a/tests/test_cases/deps/lint/bar.cpp b/tests/test_cases/deps/lint/bar.cpp new file mode 100644 index 0000000..437619c --- /dev/null +++ b/tests/test_cases/deps/lint/bar.cpp @@ -0,0 +1,10 @@ +#include "bar.hpp" + +#include "bardep.hpp" +#include <iostream> +#include <ostream> + +int bar(int x) { + std::cout << "bar(" << x << ")" << std::endl; + return bardep(x) * 7; +} diff --git a/tests/test_cases/deps/lint/bar.hpp b/tests/test_cases/deps/lint/bar.hpp new file mode 100644 index 0000000..e29bfd7 --- /dev/null +++ b/tests/test_cases/deps/lint/bar.hpp @@ -0,0 +1,8 @@ +#ifndef BAR_HPP +#define BAR_HPP + +#include "bardep.hpp" + +bar_t bar(bar_t); + +#endif diff --git a/tests/test_cases/deps/lint/bardep.cpp b/tests/test_cases/deps/lint/bardep.cpp new file mode 100644 index 0000000..33931da --- /dev/null +++ b/tests/test_cases/deps/lint/bardep.cpp @@ -0,0 +1,9 @@ +#include "bardep.hpp" + +#include <iostream> +#include <ostream> + +bar_t bardep(bar_t x) { + std::cout << "bardep(" << x << ")" << std::endl; + return x + 5; +} diff --git a/tests/test_cases/deps/lint/bardep.hpp b/tests/test_cases/deps/lint/bardep.hpp new file mode 100644 index 0000000..ebfaef4 --- /dev/null +++ b/tests/test_cases/deps/lint/bardep.hpp @@ -0,0 +1,8 @@ +#ifndef BARDEP_HPP +#define BARDEP_HPP + +typedef int bar_t; + +bar_t bardep(bar_t); + +#endif diff --git a/tests/test_cases/deps/lint/check-main.sh b/tests/test_cases/deps/lint/check-main.sh new file mode 100644 index 0000000..1705968 --- /dev/null +++ b/tests/test_cases/deps/lint/check-main.sh @@ -0,0 +1,3 @@ +set -eu + +./main | grep result: diff --git a/tests/test_cases/deps/lint/expect.py b/tests/test_cases/deps/lint/expect.py new file mode 100755 index 0000000..d26343d --- /dev/null +++ b/tests/test_cases/deps/lint/expect.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +import json +import os +import sys + +with open(sys.argv[1]) as f: + invocations = json.load(f) + +expected = set(sys.argv[2:]) +found = set() + +for name, cmd in invocations.items(): + print("- %s compiled as %r" % (name, cmd)) + found.add(os.path.basename(name)) + +if expected != found: + print() + print("Found: %r" % (found,)) + print("missing:%r" % (expected - found,)) + print("unexpected: %r" % (found - expected,)) + sys.exit(1) +else: + print("OK") diff --git a/tests/test_cases/deps/lint/foo.cpp b/tests/test_cases/deps/lint/foo.cpp new file mode 100644 index 0000000..197e1fb --- /dev/null +++ b/tests/test_cases/deps/lint/foo.cpp @@ -0,0 +1,10 @@ +#include "foo.hpp" + +#include "foodep.hpp" +#include <iostream> +#include <ostream> + +int foo(int x) { + std::cout << "foo(" << x << ")" << std::endl; + return foodep(x) * 3; +} diff --git a/tests/test_cases/deps/lint/foo.hpp b/tests/test_cases/deps/lint/foo.hpp new file mode 100644 index 0000000..45c286c --- /dev/null +++ b/tests/test_cases/deps/lint/foo.hpp @@ -0,0 +1,8 @@ +#ifndef FOO_HPP +#define FOO_HPP + +#include "foodep.hpp" + +foo_t foo(foo_t); + +#endif diff --git a/tests/test_cases/deps/lint/foodep.cpp b/tests/test_cases/deps/lint/foodep.cpp new file mode 100644 index 0000000..e26c335 --- /dev/null +++ b/tests/test_cases/deps/lint/foodep.cpp @@ -0,0 +1,9 @@ +#include "foodep.hpp" + +#include <iostream> +#include <ostream> + +foo_t foodep(foo_t x) { + std::cout << "foodep(" << x << ")" << std::endl; + return x + 2; +} diff --git a/tests/test_cases/deps/lint/foodep.hpp b/tests/test_cases/deps/lint/foodep.hpp new file mode 100644 index 0000000..ea16bb0 --- /dev/null +++ b/tests/test_cases/deps/lint/foodep.hpp @@ -0,0 +1,8 @@ +#ifndef FOODEP_HPP +#define FOODEP_HPP + +typedef int foo_t; + +foo_t foodep(foo_t); + +#endif diff --git a/tests/test_cases/deps/lint/main.cpp b/tests/test_cases/deps/lint/main.cpp new file mode 100644 index 0000000..7453eb9 --- /dev/null +++ b/tests/test_cases/deps/lint/main.cpp @@ -0,0 +1,9 @@ +#include "plain.hpp" + +#include <iostream> +#include <ostream> + +int main(int argc, char **argv) { + std::cout << "result: " << foobar(1) << std::endl; + return 0; +} diff --git a/tests/test_cases/deps/lint/plain.cpp b/tests/test_cases/deps/lint/plain.cpp new file mode 100644 index 0000000..1db123f --- /dev/null +++ b/tests/test_cases/deps/lint/plain.cpp @@ -0,0 +1,5 @@ +#include "plain.hpp" + +bar_t foobar(foo_t x) { + return bar(static_cast<bar_t>(foo(x))); +} diff --git a/tests/test_cases/deps/lint/plain.hpp b/tests/test_cases/deps/lint/plain.hpp new file mode 100644 index 0000000..20b84f5 --- /dev/null +++ b/tests/test_cases/deps/lint/plain.hpp @@ -0,0 +1,9 @@ +#ifndef PLAIN_HPP +#define PLAIN_HPP + +#include "foo.hpp" +#include "bar.hpp" + +bar_t foobar(foo_t); + +#endif diff --git a/tests/test_cases/deps/lint/pretend_lint.py b/tests/test_cases/deps/lint/pretend_lint.py new file mode 100755 index 0000000..c84285b --- /dev/null +++ b/tests/test_cases/deps/lint/pretend_lint.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + +import json +import os +import subprocess +import sys + +# log the invocation +with open(os.path.join(os.environ["OUT"], "invocation.json"), "w") as f: + json.dump(sys.argv[1:], f) + +# verify the given command succeeds +result = subprocess.run(sys.argv[2:]) + +sys.exit(result.returncode) diff --git a/tests/test_cases/deps/lint/summary.py b/tests/test_cases/deps/lint/summary.py new file mode 100755 index 0000000..361f681 --- /dev/null +++ b/tests/test_cases/deps/lint/summary.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import json +import os +import sys + +status = 0 +invocations = {} + +for lint in sorted(os.listdir()): + if os.path.isdir(lint): + with open(os.path.join(lint, "result")) as f: + result = f.read().strip() + if result != "PASS": + status = 1 + with open(os.path.join(lint, "stdout")) as f: + print(f.read()) + with open(os.path.join(lint, "stderr")) as f: + print(f.read()) + with open(os.path.join(lint, "out/invocation.json")) as f: + invocation = json.load(f) + invocations[invocation[0]] = invocation[1:] + +with open(os.path.join(os.environ["OUT"], "invocations.json"), "w") as f: + json.dump(invocations, f) + +sys.exit(status) |