mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 07:36:15 +00:00
Add tint::Command
Command is a helper used by tests for executing a process with a number of arguments and an optional stdin string, and then collecting and returning the process's stdout and stderr output as strings. Will be used to invoke HLSL and MSL shader compilers to verify our test generated code actually compiles. Change-Id: I5cd4ca63af9aaa29be7448bb4fa8422e6d42a8ce Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41942 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
a87fda9225
commit
ce7e18e87c
92
src/utils/command_test.cc
Normal file
92
src/utils/command_test.cc
Normal file
@@ -0,0 +1,92 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/utils/command.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace tint {
|
||||
namespace utils {
|
||||
namespace {
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
TEST(CommandTest, Echo) {
|
||||
auto cmd = Command::LookPath("cmd");
|
||||
if (!cmd.Found()) {
|
||||
GTEST_SKIP() << "cmd not found on PATH";
|
||||
}
|
||||
|
||||
auto res = cmd("/C", "echo", "hello world");
|
||||
EXPECT_EQ(res.error_code, 0);
|
||||
EXPECT_EQ(res.out, "hello world\r\n");
|
||||
EXPECT_EQ(res.err, "");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
TEST(CommandTest, Echo) {
|
||||
auto cmd = Command::LookPath("echo");
|
||||
if (!cmd.Found()) {
|
||||
GTEST_SKIP() << "echo not found on PATH";
|
||||
}
|
||||
|
||||
auto res = cmd("hello world");
|
||||
EXPECT_EQ(res.error_code, 0);
|
||||
EXPECT_EQ(res.out, "hello world\n");
|
||||
EXPECT_EQ(res.err, "");
|
||||
}
|
||||
|
||||
TEST(CommandTest, Cat) {
|
||||
auto cmd = Command::LookPath("cat");
|
||||
if (!cmd.Found()) {
|
||||
GTEST_SKIP() << "cat not found on PATH";
|
||||
}
|
||||
|
||||
cmd.SetInput("hello world");
|
||||
auto res = cmd();
|
||||
EXPECT_EQ(res.error_code, 0);
|
||||
EXPECT_EQ(res.out, "hello world");
|
||||
EXPECT_EQ(res.err, "");
|
||||
}
|
||||
|
||||
TEST(CommandTest, True) {
|
||||
auto cmd = Command::LookPath("true");
|
||||
if (!cmd.Found()) {
|
||||
GTEST_SKIP() << "true not found on PATH";
|
||||
}
|
||||
|
||||
auto res = cmd();
|
||||
EXPECT_EQ(res.error_code, 0);
|
||||
EXPECT_EQ(res.out, "");
|
||||
EXPECT_EQ(res.err, "");
|
||||
}
|
||||
|
||||
TEST(CommandTest, False) {
|
||||
auto cmd = Command::LookPath("false");
|
||||
if (!cmd.Found()) {
|
||||
GTEST_SKIP() << "false not found on PATH";
|
||||
}
|
||||
|
||||
auto res = cmd();
|
||||
EXPECT_NE(res.error_code, 0);
|
||||
EXPECT_EQ(res.out, "");
|
||||
EXPECT_EQ(res.err, "");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
} // namespace utils
|
||||
} // namespace tint
|
||||
Reference in New Issue
Block a user