[flang][driver] Refine tests for module search directories

This patch refactors include-module.f90:
  * rename the test file as use-module.f90 to better highlight which
  driver feature is being tested
  * move tests for diagnostics to use-module-error.f90 (it tests that
  `-J/-module-dir` can only be used once)
  * make sure that `f18` is tested when `FLANG_BUILD_NEW_DRIVER` is
  set to `Off`
  * add tests for when all module files are successfully discovered and
  loaded

With this patch, there should be a clear separation into 3 scenarios in
use-module.f90:
  * Everything is OK
  * One module file wasn't found (missing include path for
  basictestingmoduletwo.mod)
  * Two module files are found, but the test requires
  `basictestingmoduleone.mod` from both `Inputs` and `Inputs/module-dir`.
  Only the latter is found.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D97197
This commit is contained in:
Andrzej Warzynski 2021-03-09 14:20:43 +00:00
parent 8d632ca436
commit b04fbc1913
5 changed files with 89 additions and 60 deletions

View File

@ -1,5 +1,3 @@
!mod$ v1 sum:449b70509dd4bce3
!mod$ v1 sum:d380ce014c8955d8
module basictestmoduleone
type::t2
end type
end

View File

@ -1,3 +1,5 @@
!mod$ v1 sum:563b9a1f049282d2
!mod$ v1 sum:6c4101164527e745
module basictestmoduletwo
type::t2
end type
end

View File

@ -1,56 +0,0 @@
! Ensure argument -I works as expected with module files.
! REQUIRES: new-flang-driver
!--------------------------
! FLANG DRIVER (flang-new)
!--------------------------
! RUN: not %flang-new -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
! RUN: not %flang-new -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
! RUN: not %flang-new -fsyntax-only -I %S/Inputs -J %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
! RUN: not %flang-new -fsyntax-only -J %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
! RUN: not %flang-new -fsyntax-only -I %S/Inputs -module-dir %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
! RUN: not %flang-new -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
! RUN: not %flang-new -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
!-----------------------------------------
! FRONTEND FLANG DRIVER (flang-new -fc1)
!-----------------------------------------
! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -J %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -module-dir %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED
! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
! RUN: not %flang-new -fc1 -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
! RUN: not %flang-new -fc1 -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
!-----------------------------------------
! EXPECTED OUTPUT FOR MISSING MODULE FILE
!-----------------------------------------
! SINGLEINCLUDE:error: Cannot read module file for module 'basictestmoduletwo'
! SINGLEINCLUDE-NOT:error: Cannot read module file for module 'basictestmoduletwo'
! SINGLEINCLUDE-NOT:error: Derived type 't1' not found
! SINGLEINCLUDE:error: Derived type 't2' not found
!-----------------------------------------
! EXPECTED OUTPUT FOR MISSING MODULE FILE
!-----------------------------------------
! DOUBLEINCLUDE:error: Only one '-module-dir/-J' option allowed
!---------------------------------------
! EXPECTED OUTPUT FOR ALL MODULES FOUND
!---------------------------------------
! INCLUDED-NOT:error: Cannot read module file
! INCLUDED-NOT:error: Derived type 't1' not found
! INCLUDED:error: Derived type 't2' not found
program test_dash_I_with_mod_files
USE basictestmoduleone
USE basictestmoduletwo
type(t1) :: x1 ! t1 defined in Inputs/basictestmoduleone.mod
type(t2) :: x2 ! t2 defined in Inputs/module-dir/basictestmoduleone.mod
end

View File

@ -0,0 +1,25 @@
! Ensure that multiple module directories are not allowed
! REQUIRES: new-flang-driver
!--------------------------
! FLANG DRIVER (flang-new)
!--------------------------
! RUN: not %flang -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
! RUN: not %flang -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
! RUN: not %flang -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
!-----------------------------------------
! FRONTEND FLANG DRIVER (flang-new -fc1)
!-----------------------------------------
! RUN: not %flang_fc1 -fsyntax-only -J %S/Inputs/module-dir -J %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
! RUN: not %flang_fc1 -fsyntax-only -J %S/Inputs/module-dir -module-dir %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
! RUN: not %flang_fc1 -fsyntax-only -module-dir %S/Inputs/module-dir -J%S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=DOUBLEINCLUDE
!-----------------------------------------
! EXPECTED OUTPUT FOR MISSING MODULE FILE
!-----------------------------------------
! DOUBLEINCLUDE:error: Only one '-module-dir/-J' option allowed
program too_many_module_dirs
end

View File

@ -0,0 +1,60 @@
! Checks that module search directories specified with `-J/-module-dir` and `-I` are handled correctly
!--------------------------
! FLANG DRIVER (flang-new)
!--------------------------
! RUN: %flang -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED --allow-empty
! RUN: %flang -fsyntax-only -I %S/Inputs -J %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED --allow-empty
! RUN: %flang -fsyntax-only -I %S/Inputs -module-dir %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED --allow-empty
! RUN: not %flang -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=MISSING_MOD2
! RUN: not %flang -fsyntax-only -J %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=MISSING_MOD2
! RUN: not %flang -fsyntax-only -module-dir %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=MISSING_MOD2
! RUN: not %flang -fsyntax-only -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
! RUN: not %flang -fsyntax-only -J %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
! RUN: not %flang -fsyntax-only -module-dir %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
!-----------------------------------------
! FRONTEND FLANG DRIVER (flang-new -fc1)
!-----------------------------------------
! RUN: %flang_fc1 -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED --allow-empty
! RUN: %flang_fc1 -fsyntax-only -I %S/Inputs -J %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED --allow-empty
! RUN: %flang_fc1 -fsyntax-only -I %S/Inputs -module-dir %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=INCLUDED --allow-empty
! RUN: not %flang_fc1 -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=MISSING_MOD2
! RUN: not %flang_fc1 -fsyntax-only -J %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=MISSING_MOD2
! RUN: not %flang_fc1 -fsyntax-only -module-dir %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=MISSING_MOD2
! RUN: not %flang_fc1 -fsyntax-only -I %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
! RUN: not %flang_fc1 -fsyntax-only -J %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
! RUN: not %flang_fc1 -fsyntax-only -module-dir %S/Inputs/module-dir %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
!------------------------------------
! EXPECTED OUTPUT: all modules found
!------------------------------------
! INCLUDED-NOT: error
!------------------------------------------------------------------
! EXPECTED OUTPUT: include dir for `basictestingmoduletwo` is missing
!------------------------------------------------------------------
! MISSING_MOD2-NOT:error: Cannot read module file for module 'basictestmoduleone''
! MISSING_MOD2-NOT:error: Derived type 't1' not found
! MISSING_MOD2:error: Cannot read module file for module 'basictestmoduletwo'
! MISSING_MOD2:error: Derived type 't2' not found
!----------------------------------------------------------------------
! EXPECTED OUTPUT: `Inputs` is not included, and hence `t1` is undefined
!---------------------------------------------------------------------
! SINGLEINCLUDE-NOT:error: Cannot read module file for module 'basictestmoduleone'
! SINGLEINCLUDE:error: Derived type 't1' not found
! SINGLEINCLUDE-NOT:error: Cannot read module file for module 'basictestmoduletwo'
! SINGLEINCLUDE-NOT:error: Derived type 't2' not found
program test_search_dirs_for_mod_files
USE basictestmoduleone
USE basictestmoduletwo
type(t1) :: x1 ! t1 defined in Inputs/basictestmoduleone.mod
type(t2) :: x2 ! t2 defined in Inputs/module-dir/basictestmoduleone.mod
end