Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 3 | # Exceptions. See /LICENSE for license information. |
| 4 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | |
| 6 | |
| 7 | source gbash.sh || exit |
| 8 | source module gbash_unit.sh |
| 9 | |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 10 | readonly RS_BINDINGS_FROM_CC="${RUNFILES}/rs_bindings_from_cc/rs_bindings_from_cc" |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 11 | readonly DEFAULT_CLANG_FORMAT_EXE_PATH="${RUNFILES}/google3/third_party/crosstool/google3_users/clang-format" |
Googler | 83b6d7f | 2023-02-14 05:18:49 -0800 | [diff] [blame^] | 12 | readonly DEFAULT_RUSTFMT_EXE_PATH="nowhere/llvm/rust/rustfmt_for_crubit_aspects" |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 13 | |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 14 | function quote_escape() { |
| 15 | sed 's/"/\\"/g' |
| 16 | } |
| 17 | |
Marcel Hlopko | 19f2ebf | 2021-08-18 09:35:05 +0000 | [diff] [blame] | 18 | function test::cmd_line_api() { |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 19 | EXPECT_FAIL "${RS_BINDINGS_FROM_CC}" "generator should return non-zero with no arguments" |
| 20 | EXPECT_SUCCEED \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 21 | "${RS_BINDINGS_FROM_CC} 2>&1 | grep 'please specify --target' > /dev/null" \ |
| 22 | "generator should show help message for --target" |
| 23 | EXPECT_SUCCEED \ |
| 24 | "${RS_BINDINGS_FROM_CC} --target=//:target 2>&1 | grep 'please specify --rs_out' > /dev/null" \ |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 25 | "generator should show help message for --rs_out" |
| 26 | EXPECT_SUCCEED \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 27 | "${RS_BINDINGS_FROM_CC} --target=//:target --rs_out=/foo 2>&1 | \ |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 28 | grep 'please specify --cc_out' > /dev/null" \ |
| 29 | "generator should show help message for --cc_out" |
| 30 | |
| 31 | local rs_out="${TEST_TMPDIR}/rs_api.rs" |
| 32 | local cc_out="${TEST_TMPDIR}/rs_api_impl.cc" |
Marcel Hlopko | 45b60ef | 2021-08-13 13:37:43 +0000 | [diff] [blame] | 33 | |
| 34 | EXPECT_SUCCEED \ |
| 35 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 36 | --target=//:target \ |
Marcel Hlopko | 45b60ef | 2021-08-13 13:37:43 +0000 | [diff] [blame] | 37 | --rs_out=\"${rs_out}\" \ |
| 38 | --cc_out=\"${cc_out}\" 2>&1 | \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 39 | grep 'please specify --crubit_support_path' > /dev/null" \ |
| 40 | "generator should show help message for --crubit_support_path" |
| 41 | |
| 42 | EXPECT_SUCCEED \ |
| 43 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 44 | --target=//:target \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 45 | --rs_out=\"${rs_out}\" \ |
| 46 | --cc_out=\"${cc_out}\" 2>&1 \ |
| 47 | --crubit_support_path=test/crubit/support/path | \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 48 | grep 'please specify --clang_format_exe_path' > /dev/null" \ |
| 49 | "generator should show help message for --clang_format_exe_path" |
| 50 | |
| 51 | EXPECT_SUCCEED \ |
| 52 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 53 | --target=//:target \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 54 | --rs_out=\"${rs_out}\" \ |
| 55 | --cc_out=\"${cc_out}\" 2>&1 \ |
| 56 | --crubit_support_path=test/crubit/support/path \ |
| 57 | --clang_format_exe_path=\"${DEFAULT_CLANG_FORMAT_EXE_PATH}\" | \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 58 | grep 'please specify --rustfmt_exe_path' > /dev/null" \ |
| 59 | "generator should show help message for --rustfmt_exe_path" |
| 60 | |
| 61 | EXPECT_SUCCEED \ |
| 62 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 63 | --target=//:target \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 64 | --rs_out=\"${rs_out}\" \ |
| 65 | --cc_out=\"${cc_out}\" 2>&1 \ |
| 66 | --crubit_support_path=test/crubit/support/path \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 67 | --clang_format_exe_path=\"${DEFAULT_CLANG_FORMAT_EXE_PATH}\" \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 68 | --rustfmt_exe_path=\"${DEFAULT_RUSTFMT_EXE_PATH}\" | \ |
Lukasz Anforowicz | 016eb36 | 2022-03-02 18:37:03 +0000 | [diff] [blame] | 69 | grep 'please specify --public_headers' > /dev/null" \ |
Marcel Hlopko | 45b60ef | 2021-08-13 13:37:43 +0000 | [diff] [blame] | 70 | "generator should show help message for --public_headers" |
| 71 | |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 72 | local hdr="${TEST_TMPDIR}/hello_world.h" |
| 73 | echo "int foo();" > "${hdr}" |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 74 | |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 75 | EXPECT_SUCCEED \ |
| 76 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 77 | --target=//:target \ |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 78 | --rs_out=\"${rs_out}\" \ |
| 79 | --cc_out=\"${cc_out}\" \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 80 | --crubit_support_path=test/crubit/support/path \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 81 | --clang_format_exe_path=\"${DEFAULT_CLANG_FORMAT_EXE_PATH}\" \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 82 | --rustfmt_exe_path=\"${DEFAULT_RUSTFMT_EXE_PATH}\" \ |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 83 | --public_headers=\"${hdr}\" 2>&1 | \ |
| 84 | grep 'please specify --targets_and_headers' > /dev/null" \ |
| 85 | "generator should show help message for --targets_and_headers" |
| 86 | |
| 87 | local json |
| 88 | json="$(cat <<-EOT |
| 89 | [{"t": "//foo/bar:baz", "h": ["${hdr}"]}] |
| 90 | EOT |
| 91 | )" |
| 92 | |
| 93 | EXPECT_SUCCEED \ |
| 94 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 95 | --target=//:target \ |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 96 | --rs_out=\"${rs_out}\" \ |
| 97 | --cc_out=\"${cc_out}\" \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 98 | --crubit_support_path=test/crubit/support/path \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 99 | --clang_format_exe_path=\"${DEFAULT_CLANG_FORMAT_EXE_PATH}\" \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 100 | --rustfmt_exe_path=\"${DEFAULT_RUSTFMT_EXE_PATH}\" \ |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 101 | --public_headers=\"${hdr}\" \ |
| 102 | --targets_and_headers=\"$(echo "${json}" | quote_escape)\"" |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 103 | |
| 104 | EXPECT_FILE_NOT_EMPTY "${rs_out}" |
| 105 | EXPECT_FILE_NOT_EMPTY "${cc_out}" |
| 106 | } |
| 107 | |
Marcel Hlopko | 42d9e26 | 2021-11-26 16:09:20 +0000 | [diff] [blame] | 108 | function test::do_nothing() { |
| 109 | local rs_out="${TEST_TMPDIR}/rs_api.rs" |
| 110 | local cc_out="${TEST_TMPDIR}/rs_api_impl.cc" |
Lukasz Anforowicz | 016eb36 | 2022-03-02 18:37:03 +0000 | [diff] [blame] | 111 | local hdr="no_such_file.h" |
| 112 | local json |
| 113 | json="$(cat <<-EOT |
| 114 | [{"t": "//foo/bar:baz", "h": ["${hdr}"]}] |
| 115 | EOT |
| 116 | )" |
Marcel Hlopko | 42d9e26 | 2021-11-26 16:09:20 +0000 | [diff] [blame] | 117 | |
| 118 | EXPECT_SUCCEED \ |
| 119 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 120 | --target=//:target \ |
Marcel Hlopko | 42d9e26 | 2021-11-26 16:09:20 +0000 | [diff] [blame] | 121 | --rs_out=\"${rs_out}\" \ |
| 122 | --cc_out=\"${cc_out}\" \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 123 | --crubit_support_path=test/crubit/support/path \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 124 | --clang_format_exe_path=\"${DEFAULT_CLANG_FORMAT_EXE_PATH}\" \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 125 | --rustfmt_exe_path=\"${DEFAULT_RUSTFMT_EXE_PATH}\" \ |
Lukasz Anforowicz | 016eb36 | 2022-03-02 18:37:03 +0000 | [diff] [blame] | 126 | --public_headers=\"${hdr}\" \ |
| 127 | --targets_and_headers=\"$(echo "${json}" | quote_escape)\" \ |
Marcel Hlopko | 42d9e26 | 2021-11-26 16:09:20 +0000 | [diff] [blame] | 128 | --do_nothing" |
| 129 | |
| 130 | EXPECT_FILE_NOT_EMPTY "${rs_out}" |
| 131 | EXPECT_FILE_NOT_EMPTY "${cc_out}" |
| 132 | |
| 133 | EXPECT_SUCCEED "cat \"${rs_out}\" | grep '// intentionally left empty because --do_nothing was passed.'" |
| 134 | EXPECT_SUCCEED "cat \"${cc_out}\" | grep '// intentionally left empty because --do_nothing was passed.'" |
| 135 | } |
| 136 | |
Marcel Hlopko | 19f2ebf | 2021-08-18 09:35:05 +0000 | [diff] [blame] | 137 | function test::tool_returns_nonzero_on_invalid_input() { |
| 138 | local rs_out="${TEST_TMPDIR}/rs_api.rs" |
| 139 | local cc_out="${TEST_TMPDIR}/rs_api_impl.cc" |
Lukasz Anforowicz | 016eb36 | 2022-03-02 18:37:03 +0000 | [diff] [blame] | 140 | rm -rf "$rs_out" |
| 141 | rm -rf "$cc_out" |
Marcel Hlopko | 19f2ebf | 2021-08-18 09:35:05 +0000 | [diff] [blame] | 142 | |
| 143 | local hdr="${TEST_TMPDIR}/hello_world.h" |
| 144 | echo "int foo(); But this is not C++;" > "${hdr}" |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 145 | local json |
| 146 | json="$(cat <<-EOT |
| 147 | [{"t": "//foo/bar:baz", "h": ["${hdr}"]}] |
| 148 | EOT |
| 149 | )" |
| 150 | |
Marcel Hlopko | 19f2ebf | 2021-08-18 09:35:05 +0000 | [diff] [blame] | 151 | EXPECT_FAIL \ |
| 152 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 153 | --target=//:target \ |
Marcel Hlopko | 19f2ebf | 2021-08-18 09:35:05 +0000 | [diff] [blame] | 154 | --rs_out=\"${rs_out}\" \ |
| 155 | --cc_out=\"${cc_out}\" \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 156 | --crubit_support_path=test/crubit/support/path \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 157 | --clang_format_exe_path=\"${DEFAULT_CLANG_FORMAT_EXE_PATH}\" \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 158 | --rustfmt_exe_path=\"${DEFAULT_RUSTFMT_EXE_PATH}\" \ |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 159 | --public_headers=\"${hdr}\" \ |
| 160 | --targets_and_headers=\"$(echo "${json}" | quote_escape)\" 2>&1" |
Marcel Hlopko | 19f2ebf | 2021-08-18 09:35:05 +0000 | [diff] [blame] | 161 | |
Lukasz Anforowicz | 016eb36 | 2022-03-02 18:37:03 +0000 | [diff] [blame] | 162 | # No output files should be created if the C++ input was invalid. |
Marcel Hlopko | 19f2ebf | 2021-08-18 09:35:05 +0000 | [diff] [blame] | 163 | CHECK_FILE_NOT_EXISTS "${rs_out}" |
| 164 | CHECK_FILE_NOT_EXISTS "${cc_out}" |
| 165 | } |
| 166 | |
Marcel Hlopko | aca042a | 2021-10-26 15:12:36 +0000 | [diff] [blame] | 167 | function test::public_headers() { |
| 168 | local rs_out="${TEST_TMPDIR}/rs_api.rs" |
| 169 | local cc_out="${TEST_TMPDIR}/rs_api_impl.cc" |
| 170 | |
| 171 | local header_1="${TEST_TMPDIR}/header_1.h" |
| 172 | local header_2="${TEST_TMPDIR}/header_2.h" |
| 173 | echo "int function_1();" > "${header_1}" |
| 174 | echo "int function_2();" > "${header_2}" |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 175 | |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 176 | local json |
| 177 | json="$(cat <<-EOT |
| 178 | [{"t": "//foo/bar:baz", "h": ["${header_1}", "${header_2}"]}] |
| 179 | EOT |
| 180 | )" |
| 181 | |
Marcel Hlopko | aca042a | 2021-10-26 15:12:36 +0000 | [diff] [blame] | 182 | EXPECT_SUCCEED \ |
| 183 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 184 | --target=//foo/bar:baz \ |
Marcel Hlopko | aca042a | 2021-10-26 15:12:36 +0000 | [diff] [blame] | 185 | --rs_out=\"${rs_out}\" \ |
| 186 | --cc_out=\"${cc_out}\" \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 187 | --crubit_support_path=test/crubit/support/path \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 188 | --clang_format_exe_path=\"${DEFAULT_CLANG_FORMAT_EXE_PATH}\" \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 189 | --rustfmt_exe_path=\"${DEFAULT_RUSTFMT_EXE_PATH}\" \ |
Marcel Hlopko | aca042a | 2021-10-26 15:12:36 +0000 | [diff] [blame] | 190 | --public_headers=\"${header_1},${header_2}\" \ |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 191 | --targets_and_headers=\"$(echo "${json}" | quote_escape)\" 2>&1" |
| 192 | |
Marcel Hlopko | aca042a | 2021-10-26 15:12:36 +0000 | [diff] [blame] | 193 | EXPECT_SUCCEED "grep function_1 \"${rs_out}\"" "function_1 was not imported" |
| 194 | EXPECT_SUCCEED "grep function_2 \"${rs_out}\"" "function_2 was not imported" |
| 195 | } |
| 196 | |
Lukasz Anforowicz | 54ff318 | 2022-05-06 07:17:58 -0700 | [diff] [blame] | 197 | function test::rustfmt_config_path() { |
| 198 | local rs_out="${TEST_TMPDIR}/rs_api.rs" |
| 199 | local cc_out="${TEST_TMPDIR}/rs_api_impl.cc" |
| 200 | |
| 201 | local hdr="${TEST_TMPDIR}/hello_world.h" |
| 202 | echo "int MyFunction(int arg1, int arg2);" > "${hdr}" |
| 203 | |
| 204 | local json |
| 205 | json="$(cat <<-EOT |
| 206 | [{"t": "//foo/bar:baz", "h": ["${hdr}"]}] |
| 207 | EOT |
| 208 | )" |
| 209 | |
| 210 | ######################################################### |
| 211 | # Testing the default `rustfmt` config. |
| 212 | EXPECT_SUCCEED \ |
| 213 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 214 | --target=//foo/bar:baz \ |
Lukasz Anforowicz | 54ff318 | 2022-05-06 07:17:58 -0700 | [diff] [blame] | 215 | --rs_out=\"${rs_out}\" \ |
| 216 | --cc_out=\"${cc_out}\" \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 217 | --crubit_support_path=test/crubit/support/path \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 218 | --clang_format_exe_path=\"${DEFAULT_CLANG_FORMAT_EXE_PATH}\" \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 219 | --rustfmt_exe_path=\"${DEFAULT_RUSTFMT_EXE_PATH}\" \ |
Lukasz Anforowicz | 54ff318 | 2022-05-06 07:17:58 -0700 | [diff] [blame] | 220 | --public_headers=\"${hdr}\" \ |
| 221 | --targets_and_headers=\"$(echo "${json}" | quote_escape)\"" |
| 222 | |
| 223 | EXPECT_FILE_NOT_EMPTY "${rs_out}" |
| 224 | |
| 225 | # Expecting: |
| 226 | # pub fn MyFunction(arg1: i32, arg2: i32) -> i32 |
| 227 | EXPECT_SUCCEED \ |
| 228 | "grep \"MyFunction.*arg1:.*i32,.*arg2:.*i32.*)\" \"${rs_out}\"" \ |
| 229 | "Verify function args are on single line when using default rustfmt config (1)" |
| 230 | EXPECT_FAIL \ |
| 231 | "grep \"^[^a-z]*arg1:[^a-z]*i32,[^a-z]*\\\$\" \"${rs_out}\"" \ |
| 232 | "Verify function args are *not on single line when using default rustfmt config (2)" |
| 233 | |
| 234 | ######################################################### |
| 235 | # Testing a custom `rustfmt` config. |
| 236 | local rustfmt_config_path="${TEST_TMPDIR}/rustfmt.toml" |
| 237 | cat >"${rustfmt_config_path}" <<EOF |
| 238 | edition = "2021" |
| 239 | version = "Two" |
| 240 | fn_args_layout="Vertical" |
| 241 | EOF |
| 242 | EXPECT_SUCCEED \ |
| 243 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 244 | --target=//foo/bar:baz\ |
Lukasz Anforowicz | 54ff318 | 2022-05-06 07:17:58 -0700 | [diff] [blame] | 245 | --rs_out=\"${rs_out}\" \ |
| 246 | --cc_out=\"${cc_out}\" \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 247 | --crubit_support_path=test/crubit/support/path \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 248 | --clang_format_exe_path=\"${DEFAULT_CLANG_FORMAT_EXE_PATH}\" \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 249 | --rustfmt_exe_path=\"${DEFAULT_RUSTFMT_EXE_PATH}\" \ |
Lukasz Anforowicz | 54ff318 | 2022-05-06 07:17:58 -0700 | [diff] [blame] | 250 | --rustfmt_config_path=\"${rustfmt_config_path}\" \ |
| 251 | --public_headers=\"${hdr}\" \ |
| 252 | --targets_and_headers=\"$(echo "${json}" | quote_escape)\"" |
| 253 | |
| 254 | EXPECT_FILE_NOT_EMPTY "${rs_out}" |
| 255 | |
| 256 | # Expecting: |
| 257 | # pub fn MyFunction( |
| 258 | # arg1: i32, |
| 259 | # arg2: i32, |
| 260 | # ) -> i32 |
| 261 | EXPECT_FAIL \ |
| 262 | "grep \"MyFunction.*arg1:.*i32,.*arg2:.*i32.*)\" \"${rs_out}\"" \ |
| 263 | "Verify function args are *not* on single line when using default rustfmt config (1)" |
| 264 | EXPECT_SUCCEED \ |
| 265 | "grep \"^[^a-z]*arg1:[^a-z]*i32,[^a-z]*\\\$\" \"${rs_out}\"" \ |
| 266 | "Verify function args are *not on single line when using default rustfmt config (2)" |
| 267 | } |
| 268 | |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 269 | function test::crubit_support_path() { |
| 270 | local rs_out="${TEST_TMPDIR}/rs_api.rs" |
| 271 | local cc_out="${TEST_TMPDIR}/rs_api_impl.cc" |
| 272 | |
| 273 | local hdr="${TEST_TMPDIR}/hello_world.h" |
| 274 | echo "int MyFunction();" > "${hdr}" |
| 275 | |
| 276 | local json |
| 277 | json="$(cat <<-EOT |
| 278 | [{"t": "//foo/bar:baz", "h": ["${hdr}"]}] |
| 279 | EOT |
| 280 | )" |
| 281 | |
| 282 | EXPECT_SUCCEED \ |
| 283 | "\"${RS_BINDINGS_FROM_CC}\" \ |
Devin Jeanpierre | e87ae2a | 2023-01-20 12:15:36 -0800 | [diff] [blame] | 284 | --target=//foo/bar:baz \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 285 | --rs_out=\"${rs_out}\" \ |
| 286 | --cc_out=\"${cc_out}\" \ |
| 287 | --crubit_support_path=test/specific/crubit/support/path \ |
Lukasz Anforowicz | 5bf4943 | 2022-12-12 12:17:24 -0800 | [diff] [blame] | 288 | --clang_format_exe_path=\"${DEFAULT_CLANG_FORMAT_EXE_PATH}\" \ |
Lukasz Anforowicz | d7d68f0 | 2022-05-26 07:41:02 -0700 | [diff] [blame] | 289 | --rustfmt_exe_path=\"${DEFAULT_RUSTFMT_EXE_PATH}\" \ |
Lukasz Anforowicz | dd90770 | 2022-05-06 09:24:07 -0700 | [diff] [blame] | 290 | --public_headers=\"${hdr}\" \ |
| 291 | --targets_and_headers=\"$(echo "${json}" | quote_escape)\"" |
| 292 | |
| 293 | EXPECT_FILE_NOT_EMPTY "${cc_out}" |
| 294 | EXPECT_SUCCEED \ |
| 295 | "grep \"#include.*test/specific/crubit/support/path/[a-z]\" \"${cc_out}\"" \ |
| 296 | "Verify #include paths are based on the argument of --crubit_support_path" |
| 297 | } |
| 298 | |
Lukasz Anforowicz | 54ff318 | 2022-05-06 07:17:58 -0700 | [diff] [blame] | 299 | gbash::unit::main "$@" |