File indexing completed on 2024-05-19 05:41:59

0001 // ct_lvtclp_compilerutil.t.cpp                                            -*-C++-*-
0002 
0003 /*
0004  / / Copyright 2023 Codethink Ltd *<codethink@codethink.co.uk>
0005  // SPDX-License-Identifier: Apache-2.0
0006  //
0007  // Licensed under the Apache License, Version 2.0 (the "License");
0008  // you may not use this file except in compliance with the License.
0009  // You may obtain a copy of the License at
0010  //
0011  //     http://www.apache.org/licenses/LICENSE-2.0
0012  //
0013  // Unless required by applicable law or agreed to in writing, software
0014  // distributed under the License is distributed on an "AS IS" BASIS,
0015  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016  // See the License for the specific language governing permissions and
0017  // limitations under the License.
0018  */
0019 
0020 #include <ct_lvtclp_compilerutil.h>
0021 
0022 #include <catch2-local-includes.h>
0023 #include <sstream>
0024 #include <string>
0025 
0026 using namespace Codethink;
0027 
0028 TEST_CASE("search for stddef")
0029 {
0030 #ifdef __linux__
0031     // TODO: forcing to gcc, but we should test if gcc is installed,
0032     // if clang is installed, and run this for both.
0033     std::optional<std::string> res = Codethink::lvtclp::CompilerUtil::runCompiler("gcc");
0034     REQUIRE(res.has_value());
0035 
0036     int begin_search_idx = 0;
0037     int end_search_idx = 0;
0038     int curr_idx = 0;
0039     std::istringstream f(res.value());
0040     std::string curr;
0041 
0042     // do not change the capitalization of the strings on the search.
0043     while (getline(f, curr, '\n')) {
0044         if (curr.find("search starts here") != curr.npos) {
0045             begin_search_idx = curr_idx;
0046         }
0047         if (curr.find("End of search") != curr.npos) {
0048             end_search_idx = curr_idx;
0049         }
0050         curr_idx += 1;
0051     }
0052 
0053     REQUIRE(begin_search_idx != end_search_idx);
0054     REQUIRE(begin_search_idx < end_search_idx);
0055     REQUIRE((end_search_idx - begin_search_idx) > 1);
0056 #endif
0057 }