summaryrefslogtreecommitdiff
path: root/unittest/test_compopt.cpp
blob: 508284e7bddf6d4e4df3d92a93b7f56077ec66ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (C) 2010-2020 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 51
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#include "../src/compopt.hpp"

#include "third_party/doctest.h"

bool compopt_verify_sortedness_and_flags();

TEST_SUITE_BEGIN("compopt");

TEST_CASE("option_table_should_be_sorted")
{
  CHECK(compopt_verify_sortedness_and_flags());
}

TEST_CASE("affects_cpp_output")
{
  CHECK(compopt_affects_cpp_output("-I"));
  CHECK(!compopt_affects_cpp_output("-Ifoo"));
  CHECK(!compopt_affects_cpp_output("-V"));
  CHECK(!compopt_affects_cpp_output("-doesntexist"));
}

TEST_CASE("affects_compiler_output")
{
  CHECK(compopt_affects_compiler_output("-Xlinker"));
  CHECK(compopt_affects_compiler_output("-all_load"));
  CHECK(!compopt_affects_compiler_output("-U"));
}

TEST_CASE("too_hard")
{
  CHECK(compopt_too_hard("-MM"));
  CHECK(compopt_too_hard("-save-temps"));
  CHECK(compopt_too_hard("-save-temps=cwd"));
  CHECK(compopt_too_hard("-save-temps=obj"));
  CHECK(compopt_too_hard("-analyze"));
  CHECK(compopt_too_hard("--analyze"));
  CHECK(!compopt_too_hard("-MD"));
  CHECK(!compopt_too_hard("-fprofile-arcs"));
  CHECK(!compopt_too_hard("-ftest-coverage"));
  CHECK(!compopt_too_hard("-fstack-usage"));
  CHECK(!compopt_too_hard("-doesntexist"));
}

TEST_CASE("too_hard_for_direct_mode")
{
  CHECK(compopt_too_hard_for_direct_mode("-Xpreprocessor"));
  CHECK(!compopt_too_hard_for_direct_mode("-nostdinc"));
}

TEST_CASE("compopt_takes_path")
{
  CHECK(compopt_takes_path("-I"));
  CHECK(!compopt_takes_path("-L"));
}

TEST_CASE("compopt_takes_arg")
{
  CHECK(compopt_takes_arg("-Xlinker"));
  CHECK(!compopt_takes_arg("-xxx"));
}

TEST_CASE("prefix_affects_cpp_output")
{
  CHECK(compopt_prefix_affects_cpp_output("-iframework"));
  CHECK(compopt_prefix_affects_cpp_output("-iframework42"));
  CHECK(!compopt_prefix_affects_cpp_output("-iframewor"));
}

TEST_CASE("prefix_affects_compiler_output")
{
  CHECK(compopt_prefix_affects_compiler_output("-Wa,"));
  CHECK(compopt_prefix_affects_compiler_output("-Wa,something"));
  CHECK(!compopt_prefix_affects_compiler_output("-Wa"));
}

TEST_SUITE_END();