Skip to content

Commit

Permalink
Add a proper negative test
Browse files Browse the repository at this point in the history
  • Loading branch information
plietar committed Sep 17, 2020
1 parent 4eccd01 commit d96a4c2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
4 changes: 4 additions & 0 deletions src/mlir/driver.cc
Expand Up @@ -31,6 +31,10 @@ namespace mlir::verona
diagnosticHandler =
std::make_unique<SourceMgrDiagnosticHandler>(sourceManager, &context);

// In verify-diagnostics mode, don't print the associated operation.
// It would just be adding noise to the test files
context.printOpOnDiagnostic(!verifyDiagnostics);

context.getOrLoadDialect<mlir::StandardOpsDialect>();
context.getOrLoadDialect<mlir::verona::VeronaDialect>();

Expand Down
15 changes: 5 additions & 10 deletions testsuite/mlir-fail.cmake
@@ -1,14 +1,9 @@
include(${CMAKE_CURRENT_LIST_DIR}/common.cmake)

PrepareTest(VERONAM_FLAGS EXPECTED_DUMP ACTUAL_DUMP)
PrepareTest(VERONAC_FLAGS EXPECTED_DUMP ACTUAL_DUMP)

CheckStatus(
COMMAND ${MLIRGEN} ${TEST_FILE} -o -
EXPECTED_STATUS 1
ERROR_FILE ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.out)

FileCheck(${TEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.out)

if(EXPECTED_DUMP)
CheckDump(${EXPECTED_DUMP} ${ACTUAL_DUMP})
endif()
COMMAND
${MLIRGEN} --verify-diagnostics --split-input-file
${TEST_FILE} -o -
EXPECTED_STATUS 0)
17 changes: 4 additions & 13 deletions testsuite/mlir-parse.cmake
@@ -1,19 +1,10 @@
include(${CMAKE_CURRENT_LIST_DIR}/common.cmake)

set(ACTUAL_DUMP ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME})
PrepareTest(VERONAC_FLAGS EXPECTED_DUMP ACTUAL_DUMP)

PrepareTest(VERONAM_FLAGS EXPECTED_DUMP ACTUAL_DUMP)

execute_process(
COMMAND ${MLIRGEN} ${TEST_FILE} -o -
OUTPUT_FILE ${ACTUAL_DUMP}/mlir.txt
RESULT_VARIABLE EXIT_CODE)

if(NOT ${EXIT_CODE} EQUAL 0)
file(READ ${ACTUAL_DUMP}/mlir.txt ERROR_MESSAGES)
message(STATUS "OUTPUT:\n${ERROR_MESSAGES}")
message(FATAL_ERROR " ${MLIRGEN} exited with error code ${EXIT_CODE}")
endif()
CheckStatus(
COMMAND ${MLIRGEN} ${TEST_FILE} -o ${ACTUAL_DUMP}/mlir.txt
EXPECTED_STATUS 0)

if(EXPECTED_DUMP)
CheckDump(${EXPECTED_DUMP} ${ACTUAL_DUMP})
Expand Down
20 changes: 20 additions & 0 deletions testsuite/mlir/mlir-fail/subtyping.mlir
@@ -0,0 +1,20 @@
// Copyright Microsoft and Project Verona Contributors.
// SPDX-License-Identifier: MIT

module {
func @test(%x: !verona.meet<U64, iso>) {
// expected-error@+1 {{'!verona.meet<U64, iso>' is not a subtype of '!verona.meet<U64, mut>'}}
%y = verona.copy %x : !verona.meet<U64, iso> -> !verona.meet<U64, mut>
return
}
}

// -----

module {
func @test(%x: !verona.meet<class<"C">, mut>) {
// expected-error@+1 {{'!verona.meet<class<"C">, mut>' is not a subtype of '!verona.meet<class<"D">, mut>'}}
%y = verona.copy %x : !verona.meet<class<"C">, mut> -> !verona.meet<class<"D">, mut>
return
}
}
5 changes: 1 addition & 4 deletions testsuite/mlir/mlir-parse/dialect.mlir
Expand Up @@ -41,11 +41,8 @@ module {
}
}

// -----

module {
func @bar(%x: !verona.meet<U64, imm>, %y: !verona.meet<U64, imm>) {
// expected-note@+1 {{prior use here}}
%a = verona.new_region @C [ ] : !verona.meet<!C, iso>
%b = verona.view %a : !verona.meet<!C, iso> -> !verona.meet<!C, mut>

Expand All @@ -67,7 +64,7 @@ module {
-> !verona.meet<U64, imm>

// expected-error@+1 {{use of value '%a' expects different type than prior uses}}
verona.tidy %a : !verona.meet<!C, mut>
verona.tidy %a : !verona.meet<!C, iso>
verona.drop %a : !verona.meet<!C, iso>

return
Expand Down

0 comments on commit d96a4c2

Please sign in to comment.