From 4cc96d6a486b780d239caf7493008cb0e309f0d4 Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Thu, 6 Apr 2023 21:12:04 +0200 Subject: [PATCH] Alcotezt: automatically add proto tag --- scripts/snapshot_alpha.sh | 9 +++++++- tezt/lib_alcotezt/alcotest.ml | 2 ++ tezt/lib_alcotezt/alcotest_lwt.ml | 2 ++ tezt/lib_alcotezt/alcotezt_utils.ml | 35 +++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tezt/lib_alcotezt/alcotezt_utils.ml diff --git a/scripts/snapshot_alpha.sh b/scripts/snapshot_alpha.sh index ab1b929a617c..def23ebbc4f6 100755 --- a/scripts/snapshot_alpha.sh +++ b/scripts/snapshot_alpha.sh @@ -30,7 +30,6 @@ long_hash= # e.g. Pt8PY9P4 (set below) short_hash= - if ! ( [[ "$label" =~ ^[a-z]+$ ]] && [[ "$version" =~ ^[0-9][0-9][0-9]$ ]] ); then echo "Wrong protocol version." echo "Name should be a lowercase alphabetic word." @@ -177,3 +176,11 @@ cd ../../.. # remove files generated by sed find . -name '*.old' -exec rm {} \; + +# automatically add the new protocol tag to alcotezt + +temp_file=$(mktemp) +head -n -1 tezt/lib_alcotezt/alcotezt_utils.ml > "$temp_file" +echo " | Some \"${version}_${short_hash}\" -> [\"${label}\"]" >> "$temp_file" +echo " | Some _ -> assert false" >> "$temp_file" +mv "$temp_file" tezt/lib_alcotezt/alcotezt_utils.ml diff --git a/tezt/lib_alcotezt/alcotest.ml b/tezt/lib_alcotezt/alcotest.ml index f78238226aff..8c095565955b 100644 --- a/tezt/lib_alcotezt/alcotest.ml +++ b/tezt/lib_alcotezt/alcotest.ml @@ -38,6 +38,7 @@ exception Test_error type 'a test = string * 'a test_case list let run ~__FILE__ library_name tests = + let proto_tags = Alcotezt_utils.is_proto_test __FILE__ in tests |> List.iter @@ fun (test_name, test_cases) -> test_cases @@ -45,6 +46,7 @@ let run ~__FILE__ library_name tests = let tags = "alcotezt" :: (match speed_level with `Quick -> ["quick"] | `Slow -> []) + @ proto_tags in Test.register ~__FILE__ diff --git a/tezt/lib_alcotezt/alcotest_lwt.ml b/tezt/lib_alcotezt/alcotest_lwt.ml index 62ccf6f5a3c4..5aeaab5c2c32 100644 --- a/tezt/lib_alcotezt/alcotest_lwt.ml +++ b/tezt/lib_alcotezt/alcotest_lwt.ml @@ -48,6 +48,7 @@ let test_case_sync name speed_level body = type 'a test = string * 'a test_case list let run ~__FILE__ library_name tests = + let proto_tags = Alcotezt_utils.is_proto_test __FILE__ in (tests |> List.iter @@ fun (test_name, test_cases) -> test_cases @@ -55,6 +56,7 @@ let run ~__FILE__ library_name tests = let tags = "alcotezt" :: (match speed_level with `Quick -> ["quick"] | `Slow -> []) + @ proto_tags in Test.register ~__FILE__ diff --git a/tezt/lib_alcotezt/alcotezt_utils.ml b/tezt/lib_alcotezt/alcotezt_utils.ml new file mode 100644 index 000000000000..5a63942469f0 --- /dev/null +++ b/tezt/lib_alcotezt/alcotezt_utils.ml @@ -0,0 +1,35 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +open Tezt_core.Base + +(* Do not modify: it is automatically updated with [scripts/snapshot_alpha.sh]. *) +let is_proto_test file = + match file =~* rex "^src/proto_(\\w+)/" with + | None -> [] + | Some "alpha" -> ["alpha"] + | Some "016_PtMumbai" -> ["mumbai"] + | Some "017_PtNairob" -> ["nairobi"] + | Some _ -> assert false -- GitLab