From 79e85d483052d7502d41bd2c1670d25e335c2db3 Mon Sep 17 00:00:00 2001 From: Jon Meow <46229924+jonmeow@users.noreply.github.com> Date: Mon, 24 Jan 2022 11:15:19 -0800 Subject: [PATCH] Use lit_test for driver (#1037) --- toolchain/driver/BUILD | 19 ++++++------ toolchain/driver/carbon_test.carbon | 24 --------------- toolchain/driver/testdata/carbon_test.carbon | 27 +++++++++++++++++ toolchain/driver/testdata/lit.cfg.py | 32 ++++++++++++++++++++ 4 files changed, 69 insertions(+), 33 deletions(-) delete mode 100644 toolchain/driver/carbon_test.carbon create mode 100644 toolchain/driver/testdata/carbon_test.carbon create mode 100644 toolchain/driver/testdata/lit.cfg.py diff --git a/toolchain/driver/BUILD b/toolchain/driver/BUILD index a6b714439680..bf3e5be98603 100644 --- a/toolchain/driver/BUILD +++ b/toolchain/driver/BUILD @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception load("//bazel/fuzzing:rules.bzl", "cc_fuzz_test") +load("//bazel/testing:lit_test.bzl", "lit_test") package(default_visibility = ["//visibility:public"]) @@ -53,12 +54,12 @@ cc_binary( ], ) -# FIXME: No support for LLVM's lit-style command line & FileCheck tests. -# -#lit_test( -# name = "carbon_test.carbon", -# data = [ -# ":carbon", -# "@llvm-project//llvm:FileCheck", -# ], -#) +lit_test( + name = "carbon_lit_test", + data = [ + ":carbon", + "@llvm-project//llvm:FileCheck", + "@llvm-project//llvm:not", + ], + test_dir = "testdata", +) diff --git a/toolchain/driver/carbon_test.carbon b/toolchain/driver/carbon_test.carbon deleted file mode 100644 index 893a07800cd5..000000000000 --- a/toolchain/driver/carbon_test.carbon +++ /dev/null @@ -1,24 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// FIXME: We need to figure out how to integrate this style of integration -// testing with Bazel. -// -// RUN: driver/carbon dump-tokens %s | FileCheck %s --check-prefix=TOKENS - -fn run(String program) { - return True; -} - -// TOKENS: token: { index: 0, kind: 'FnKeyword', line: 4, column: 1, indent: 1, spelling: 'fn' } -// TOKENS: token: { index: 1, kind: 'Identifier', line: 4, column: 4, indent: 1, spelling: 'run', identifier: 0 } -// TOKENS: token: { index: 2, kind: 'OpenParen', line: 4, column: 7, indent: 1, spelling: '(', closing_token: 5 } -// TOKENS: token: { index: 3, kind: 'Identifier', line: 4, column: 8, indent: 1, spelling: 'String', identifier: 1 } -// TOKENS: token: { index: 4, kind: 'Identifier', line: 4, column: 15, indent: 1, spelling: 'program', identifier: 2 } -// TOKENS: token: { index: 5, kind: 'CloseParen', line: 4, column: 22, indent: 1, spelling: ')', opening_token: 2 } -// TOKENS: token: { index: 6, kind: 'OpenCurlyBrace', line: 4, column: 24, indent: 1, spelling: '{', closing_token: 10 } -// TOKENS: token: { index: 7, kind: 'ReturnKeyword', line: 5, column: 3, indent: 3, spelling: 'return' } -// TOKENS: token: { index: 8, kind: 'Identifier', line: 5, column: 10, indent: 3, spelling: 'True', identifier: 3 } -// TOKENS: token: { index: 9, kind: 'Semi', line: 5, column: 14, indent: 3, spelling: ';' } -// TOKENS: token: { index: 10, kind: 'CloseCurlyBrace', line: 6, column: 1, indent: 1, spelling: '}', opening_token: 6 } diff --git a/toolchain/driver/testdata/carbon_test.carbon b/toolchain/driver/testdata/carbon_test.carbon new file mode 100644 index 000000000000..524f7e40e94e --- /dev/null +++ b/toolchain/driver/testdata/carbon_test.carbon @@ -0,0 +1,27 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// FIXME: We need to figure out how to integrate this style of integration +// testing with Bazel. +// +// RUN: %{carbon} dump-tokens %s 2>&1 | \ +// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false \ +// RUN: --check-prefix=TOKENS %s + +fn run(String program) { + return True; +} + +// TOKENS: token: { index: 0, kind: 'FnKeyword', line: 12, column: 1, indent: 1, spelling: 'fn', has_trailing_space: true } +// TOKENS: token: { index: 1, kind: 'Identifier', line: 12, column: 4, indent: 1, spelling: 'run', identifier: 0 } +// TOKENS: token: { index: 2, kind: 'OpenParen', line: 12, column: 7, indent: 1, spelling: '(', closing_token: 5 } +// TOKENS: token: { index: 3, kind: 'Identifier', line: 12, column: 8, indent: 1, spelling: 'String', identifier: 1, has_trailing_space: true } +// TOKENS: token: { index: 4, kind: 'Identifier', line: 12, column: 15, indent: 1, spelling: 'program', identifier: 2 } +// TOKENS: token: { index: 5, kind: 'CloseParen', line: 12, column: 22, indent: 1, spelling: ')', opening_token: 2, has_trailing_space: true } +// TOKENS: token: { index: 6, kind: 'OpenCurlyBrace', line: 12, column: 24, indent: 1, spelling: '{', closing_token: 10, has_trailing_space: true } +// TOKENS: token: { index: 7, kind: 'ReturnKeyword', line: 13, column: 3, indent: 3, spelling: 'return', has_trailing_space: true } +// TOKENS: token: { index: 8, kind: 'Identifier', line: 13, column: 10, indent: 3, spelling: 'True', identifier: 3 } +// TOKENS: token: { index: 9, kind: 'Semi', line: 13, column: 14, indent: 3, spelling: ';', has_trailing_space: true } +// TOKENS: token: { index: 10, kind: 'CloseCurlyBrace', line: 14, column: 1, indent: 1, spelling: '}', opening_token: 6, has_trailing_space: true } +// TOKENS: token: { index: 11, kind: 'EndOfFile', line: 27, column: 105, indent: 1, spelling: '' } diff --git a/toolchain/driver/testdata/lit.cfg.py b/toolchain/driver/testdata/lit.cfg.py new file mode 100644 index 000000000000..47c48bd43242 --- /dev/null +++ b/toolchain/driver/testdata/lit.cfg.py @@ -0,0 +1,32 @@ +__copyright__ = """ +Part of the Carbon Language project, under the Apache License v2.0 with LLVM +Exceptions. See /LICENSE for license information. +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +""" + +import lit.formats +import os + + +# This is a provided variable, ignore the undefined name warning. +config = config # noqa: F821 + + +def fullpath(relative_path): + return os.path.join(os.environ["TEST_SRCDIR"], relative_path) + + +config.name = "lit" +config.suffixes = [".carbon"] +config.test_format = lit.formats.ShTest() + +config.substitutions.append( + ( + "%{carbon}", + fullpath("carbon/toolchain/driver/carbon"), + ) +) +config.substitutions.append(("%{not}", fullpath("llvm-project/llvm/not"))) +config.substitutions.append( + ("%{FileCheck}", fullpath("llvm-project/llvm/FileCheck")) +)