[flang-commits] [flang] dc453dc - [Flang] Port test_modfile.sh to Python

Ivan Zhechev via flang-commits flang-commits at lists.llvm.org
Mon Sep 6 06:57:46 PDT 2021


Author: Ivan Zhechev
Date: 2021-09-06T13:57:36Z
New Revision: dc453dcf760e6d558da3a4d7fff301baa5f37aba

URL: https://github.com/llvm/llvm-project/commit/dc453dcf760e6d558da3a4d7fff301baa5f37aba
DIFF: https://github.com/llvm/llvm-project/commit/dc453dcf760e6d558da3a4d7fff301baa5f37aba.diff

LOG: [Flang] Port test_modfile.sh to Python

To enable Flang testing on Windows, shell scripts have
to be ported to Python. The following changes have been made:
"test_modfile.sh" has been ported to Python, and
the relevant tests relying on it.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D107956

Added: 
    flang/test/Semantics/test_modfile.py

Modified: 
    flang/test/Semantics/modfile01.f90
    flang/test/Semantics/modfile02.f90
    flang/test/Semantics/modfile03.f90
    flang/test/Semantics/modfile04.f90
    flang/test/Semantics/modfile05.f90
    flang/test/Semantics/modfile06.f90
    flang/test/Semantics/modfile07.f90
    flang/test/Semantics/modfile08.f90
    flang/test/Semantics/modfile09.f90
    flang/test/Semantics/modfile10.f90
    flang/test/Semantics/modfile11.f90
    flang/test/Semantics/modfile12.f90
    flang/test/Semantics/modfile13.f90
    flang/test/Semantics/modfile14.f90
    flang/test/Semantics/modfile15.f90
    flang/test/Semantics/modfile16.f90
    flang/test/Semantics/modfile17.f90
    flang/test/Semantics/modfile18.f90
    flang/test/Semantics/modfile19.f90
    flang/test/Semantics/modfile20.f90
    flang/test/Semantics/modfile21.f90
    flang/test/Semantics/modfile22.f90
    flang/test/Semantics/modfile23.f90
    flang/test/Semantics/modfile24.f90
    flang/test/Semantics/modfile25.f90
    flang/test/Semantics/modfile26.f90
    flang/test/Semantics/modfile27.f90
    flang/test/Semantics/modfile28.f90
    flang/test/Semantics/modfile29.f90
    flang/test/Semantics/modfile30.f90
    flang/test/Semantics/modfile31.f90
    flang/test/Semantics/modfile32.f90
    flang/test/Semantics/modfile33.f90
    flang/test/Semantics/modfile34.f90
    flang/test/Semantics/modfile35.f90
    flang/test/Semantics/modfile36.f90
    flang/test/Semantics/modfile37.f90
    flang/test/Semantics/modfile38.f90
    flang/test/Semantics/modfile39.f90
    flang/test/Semantics/modfile40.f90

Removed: 
    flang/test/Semantics/test_modfile.sh


################################################################################
diff  --git a/flang/test/Semantics/modfile01.f90 b/flang/test/Semantics/modfile01.f90
index 6316399477d03..fcbc00a098284 100644
--- a/flang/test/Semantics/modfile01.f90
+++ b/flang/test/Semantics/modfile01.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Check correct modfile generation for type with private component.
 module m
   integer :: i

diff  --git a/flang/test/Semantics/modfile02.f90 b/flang/test/Semantics/modfile02.f90
index b48f7e28d7902..bd1acf6ec300a 100644
--- a/flang/test/Semantics/modfile02.f90
+++ b/flang/test/Semantics/modfile02.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Check modfile generation for private type in public API.
 
 module m

diff  --git a/flang/test/Semantics/modfile03.f90 b/flang/test/Semantics/modfile03.f90
index 0d15e09087b1d..8e2eb43e7e549 100644
--- a/flang/test/Semantics/modfile03.f90
+++ b/flang/test/Semantics/modfile03.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Check modfile generation with use-association.
 
 module m1

diff  --git a/flang/test/Semantics/modfile04.f90 b/flang/test/Semantics/modfile04.f90
index 8cd60978b750f..7c94401e08fca 100644
--- a/flang/test/Semantics/modfile04.f90
+++ b/flang/test/Semantics/modfile04.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! modfile with subprograms
 
 module m1

diff  --git a/flang/test/Semantics/modfile05.f90 b/flang/test/Semantics/modfile05.f90
index da81866d4f597..652386849455e 100644
--- a/flang/test/Semantics/modfile05.f90
+++ b/flang/test/Semantics/modfile05.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Use-association with VOLATILE or ASYNCHRONOUS
 
 module m1

diff  --git a/flang/test/Semantics/modfile06.f90 b/flang/test/Semantics/modfile06.f90
index 8a3373afc41cd..3a759e79c235d 100644
--- a/flang/test/Semantics/modfile06.f90
+++ b/flang/test/Semantics/modfile06.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Check modfile generation for external interface
 module m
   interface

diff  --git a/flang/test/Semantics/modfile07.f90 b/flang/test/Semantics/modfile07.f90
index c1100f04f80bb..644c37e3d381d 100644
--- a/flang/test/Semantics/modfile07.f90
+++ b/flang/test/Semantics/modfile07.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Check modfile generation for generic interfaces
 module m1
   interface foo

diff  --git a/flang/test/Semantics/modfile08.f90 b/flang/test/Semantics/modfile08.f90
index d5bd3a20225a9..dc270e0708056 100644
--- a/flang/test/Semantics/modfile08.f90
+++ b/flang/test/Semantics/modfile08.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Check modfile generation for external declarations
 module m
   real, external :: a

diff  --git a/flang/test/Semantics/modfile09.f90 b/flang/test/Semantics/modfile09.f90
index b0893c4c32a27..9e4101772618c 100644
--- a/flang/test/Semantics/modfile09.f90
+++ b/flang/test/Semantics/modfile09.f90
@@ -1,2 +1 @@
-!RUN: %S/test_modfile.sh '%S/Inputs/modfile09-*' %t %flang_fc1
-!REQUIRES: shell
+!RUN: %python %S/test_modfile.py '%S/Inputs/modfile09-*' %flang_fc1

diff  --git a/flang/test/Semantics/modfile10.f90 b/flang/test/Semantics/modfile10.f90
index 857b9c96d8857..b59fd44c985a6 100644
--- a/flang/test/Semantics/modfile10.f90
+++ b/flang/test/Semantics/modfile10.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Test writing procedure bindings in a derived type.
 
 module m

diff  --git a/flang/test/Semantics/modfile11.f90 b/flang/test/Semantics/modfile11.f90
index ecb49e0e38107..d5e10d8127e7c 100644
--- a/flang/test/Semantics/modfile11.f90
+++ b/flang/test/Semantics/modfile11.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 module m
   type t1(a, b, c)
     integer, kind :: a

diff  --git a/flang/test/Semantics/modfile12.f90 b/flang/test/Semantics/modfile12.f90
index 1a662c6e4da4d..17b6e95c4a562 100644
--- a/flang/test/Semantics/modfile12.f90
+++ b/flang/test/Semantics/modfile12.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 module m
   integer(8), parameter :: a = 1, b = 2_8
   parameter(n=3,l=-3,e=1.0/3.0)

diff  --git a/flang/test/Semantics/modfile13.f90 b/flang/test/Semantics/modfile13.f90
index 0d0de2370b11d..d49e3aa9ac166 100644
--- a/flang/test/Semantics/modfile13.f90
+++ b/flang/test/Semantics/modfile13.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 module m
   character(2) :: z
   character(len=3) :: y

diff  --git a/flang/test/Semantics/modfile14.f90 b/flang/test/Semantics/modfile14.f90
index 87c07eab36a1e..6a280c51f3a7b 100644
--- a/flang/test/Semantics/modfile14.f90
+++ b/flang/test/Semantics/modfile14.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 module m
   type t1
   contains

diff  --git a/flang/test/Semantics/modfile15.f90 b/flang/test/Semantics/modfile15.f90
index fdf0e55f855de..5ca2c04a33adc 100644
--- a/flang/test/Semantics/modfile15.f90
+++ b/flang/test/Semantics/modfile15.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 module m
   type :: t
     procedure(a), pointer, pass :: c

diff  --git a/flang/test/Semantics/modfile16.f90 b/flang/test/Semantics/modfile16.f90
index 8acb8a6a7b73b..9599f19a6b7e8 100644
--- a/flang/test/Semantics/modfile16.f90
+++ b/flang/test/Semantics/modfile16.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 module m
   character(2), parameter :: prefix = 'c_'
   integer, bind(c, name='c_a') :: a

diff  --git a/flang/test/Semantics/modfile17.f90 b/flang/test/Semantics/modfile17.f90
index c15765e8aa01a..189d8a83de8c5 100644
--- a/flang/test/Semantics/modfile17.f90
+++ b/flang/test/Semantics/modfile17.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Tests parameterized derived type instantiation with KIND parameters
 
 module m

diff  --git a/flang/test/Semantics/modfile18.f90 b/flang/test/Semantics/modfile18.f90
index 0fcb90d260a13..584840e5f4239 100644
--- a/flang/test/Semantics/modfile18.f90
+++ b/flang/test/Semantics/modfile18.f90
@@ -1,5 +1,5 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
+
 ! Tests folding of array constructors
 
 module m

diff  --git a/flang/test/Semantics/modfile19.f90 b/flang/test/Semantics/modfile19.f90
index 6507b34808fe3..b7a49d262d31d 100644
--- a/flang/test/Semantics/modfile19.f90
+++ b/flang/test/Semantics/modfile19.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 module m
   implicit complex(8)(z)
   real :: x

diff  --git a/flang/test/Semantics/modfile20.f90 b/flang/test/Semantics/modfile20.f90
index 127618a13819e..327ca7675668b 100644
--- a/flang/test/Semantics/modfile20.f90
+++ b/flang/test/Semantics/modfile20.f90
@@ -1,5 +1,5 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
+
 ! Test modfiles for entities with initialization
 module m
   integer, parameter :: k8 = 8

diff  --git a/flang/test/Semantics/modfile21.f90 b/flang/test/Semantics/modfile21.f90
index 886f5bd945a05..513a5bdf3bfaf 100644
--- a/flang/test/Semantics/modfile21.f90
+++ b/flang/test/Semantics/modfile21.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 module m
   logical b
   bind(C) :: /cb2/

diff  --git a/flang/test/Semantics/modfile22.f90 b/flang/test/Semantics/modfile22.f90
index 73efdb65afa3b..ef4063b4674f1 100644
--- a/flang/test/Semantics/modfile22.f90
+++ b/flang/test/Semantics/modfile22.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Test character length conversions in constructors
 
 module m

diff  --git a/flang/test/Semantics/modfile23.f90 b/flang/test/Semantics/modfile23.f90
index 46cec24a77f3f..7c23f734769b4 100644
--- a/flang/test/Semantics/modfile23.f90
+++ b/flang/test/Semantics/modfile23.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Test that subprogram interfaces get all of the symbols that they need.
 
 module m1

diff  --git a/flang/test/Semantics/modfile24.f90 b/flang/test/Semantics/modfile24.f90
index 46b1ced84c8af..db45c94887abb 100644
--- a/flang/test/Semantics/modfile24.f90
+++ b/flang/test/Semantics/modfile24.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Test declarations with coarray-spec
 
 ! Different ways of declaring the same coarray.

diff  --git a/flang/test/Semantics/modfile25.f90 b/flang/test/Semantics/modfile25.f90
index 4a50ff5976551..44012bea5a672 100644
--- a/flang/test/Semantics/modfile25.f90
+++ b/flang/test/Semantics/modfile25.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Test compile-time analysis of shapes.
 
 module m1

diff  --git a/flang/test/Semantics/modfile26.f90 b/flang/test/Semantics/modfile26.f90
index b0b751bf007b7..77bef3104bd89 100644
--- a/flang/test/Semantics/modfile26.f90
+++ b/flang/test/Semantics/modfile26.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Intrinsics SELECTED_INT_KIND, SELECTED_REAL_KIND, PRECISION, RANGE,
 ! RADIX, DIGITS
 

diff  --git a/flang/test/Semantics/modfile27.f90 b/flang/test/Semantics/modfile27.f90
index db3adc1b34e1a..a5365d17723f0 100644
--- a/flang/test/Semantics/modfile27.f90
+++ b/flang/test/Semantics/modfile27.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Test folding of combined array references and structure component
 ! references.
 

diff  --git a/flang/test/Semantics/modfile28.f90 b/flang/test/Semantics/modfile28.f90
index aa6eb36c6adb8..e00bd13f6c75e 100644
--- a/flang/test/Semantics/modfile28.f90
+++ b/flang/test/Semantics/modfile28.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 
 ! Test UTF-8 support in character literals
 ! Note: Module files are encoded in UTF-8.

diff  --git a/flang/test/Semantics/modfile29.f90 b/flang/test/Semantics/modfile29.f90
index c7d8038500dfe..7650fe301b289 100644
--- a/flang/test/Semantics/modfile29.f90
+++ b/flang/test/Semantics/modfile29.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Check that implicitly typed entities get a type in the module file.
 
 module m

diff  --git a/flang/test/Semantics/modfile30.f90 b/flang/test/Semantics/modfile30.f90
index 8681f356087f2..ce40e199af43d 100644
--- a/flang/test/Semantics/modfile30.f90
+++ b/flang/test/Semantics/modfile30.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Verify miscellaneous bugs
 
 ! The function result must be declared after the dummy arguments

diff  --git a/flang/test/Semantics/modfile31.f90 b/flang/test/Semantics/modfile31.f90
index f37f2ffbc95bf..beed3c584fbf2 100644
--- a/flang/test/Semantics/modfile31.f90
+++ b/flang/test/Semantics/modfile31.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Test 7.6 enum values
 
 module m1

diff  --git a/flang/test/Semantics/modfile32.f90 b/flang/test/Semantics/modfile32.f90
index 9586b91bd363c..f85eb0fa26f7f 100644
--- a/flang/test/Semantics/modfile32.f90
+++ b/flang/test/Semantics/modfile32.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Resolution of generic names in expressions.
 ! Test by using generic function in a specification expression that needs
 ! to be written to a .mod file.

diff  --git a/flang/test/Semantics/modfile33.f90 b/flang/test/Semantics/modfile33.f90
index 69145ce0f0c41..a348e2b5db712 100644
--- a/flang/test/Semantics/modfile33.f90
+++ b/flang/test/Semantics/modfile33.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1 -flogical-abbreviations -fxor-operator
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1 -flogical-abbreviations -fxor-operator
 
 ! Resolution of user-defined operators in expressions.
 ! Test by using generic function in a specification expression that needs

diff  --git a/flang/test/Semantics/modfile34.f90 b/flang/test/Semantics/modfile34.f90
index b035662a93d23..2d6adcb89c9b6 100644
--- a/flang/test/Semantics/modfile34.f90
+++ b/flang/test/Semantics/modfile34.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Test resolution of type-bound generics.
 
 module m1

diff  --git a/flang/test/Semantics/modfile35.f90 b/flang/test/Semantics/modfile35.f90
index 207eee002a65f..5f685c07932d0 100644
--- a/flang/test/Semantics/modfile35.f90
+++ b/flang/test/Semantics/modfile35.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 module m1
   type :: t1
   contains

diff  --git a/flang/test/Semantics/modfile36.f90 b/flang/test/Semantics/modfile36.f90
index c4dd89b64a062..b8dff4ce59978 100644
--- a/flang/test/Semantics/modfile36.f90
+++ b/flang/test/Semantics/modfile36.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 
 ! Check modfile that contains import of use-assocation of another use-association.
 

diff  --git a/flang/test/Semantics/modfile37.f90 b/flang/test/Semantics/modfile37.f90
index 6da1ab9f4ac58..d68d4f8ef9d64 100644
--- a/flang/test/Semantics/modfile37.f90
+++ b/flang/test/Semantics/modfile37.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 
 ! Ensure that a dummy procedure's interface's imports
 ! appear in the module file.

diff  --git a/flang/test/Semantics/modfile38.f90 b/flang/test/Semantics/modfile38.f90
index d40074360f6e7..d2646b6ca6154 100644
--- a/flang/test/Semantics/modfile38.f90
+++ b/flang/test/Semantics/modfile38.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 
 ! Ensure that an interface with the same name as a derived type
 ! does not cause that shadowed name to be emitted later than its

diff  --git a/flang/test/Semantics/modfile39.f90 b/flang/test/Semantics/modfile39.f90
index 9638ec535e535..6041d6cc73c6c 100644
--- a/flang/test/Semantics/modfile39.f90
+++ b/flang/test/Semantics/modfile39.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Resolution of specification expression references to generic interfaces
 ! that resolve to private specific functions.
 

diff  --git a/flang/test/Semantics/modfile40.f90 b/flang/test/Semantics/modfile40.f90
index 6f3a4dcf85962..0255c14e0a183 100644
--- a/flang/test/Semantics/modfile40.f90
+++ b/flang/test/Semantics/modfile40.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_modfile.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_modfile.py %s %flang_fc1
 ! Ensure that intrinsics in module files retain their 'private' attribute,
 ! if they are private.
 

diff  --git a/flang/test/Semantics/test_modfile.py b/flang/test/Semantics/test_modfile.py
new file mode 100755
index 0000000000000..4126f9adf8cea
--- /dev/null
+++ b/flang/test/Semantics/test_modfile.py
@@ -0,0 +1,92 @@
+#!/usr/bin/env python3
+
+"""Compiles a source file and compares generated .mod files against expected.
+
+Parameters:
+    sys.argv[1]: a source file with contains the input and expected output
+    sys.argv[2]: the Flang frontend driver
+    sys.argv[3:]: Optional arguments to the Flang frontend driver"""
+
+import sys
+import re
+import os
+import tempfile
+import subprocess
+import glob
+import common as cm
+
+from pathlib import Path
+from 
diff lib import unified_
diff 
+
+cm.check_args_long(sys.argv)
+srcdir = Path(sys.argv[1])
+sources = list(glob.iglob(str(srcdir)))
+sources = sorted(sources)
+
diff s = ""
+
+flang_fc1 = cm.set_executable(sys.argv[2])
+flang_fc_args = sys.argv[3:]
+flang_fc1_options = "-fsyntax-only"
+
+with tempfile.TemporaryDirectory() as tmpdir:
+    for src in sources:
+        src = Path(src).resolve()
+        actual = ""
+        expect = ""
+        expected_files = set()
+        actual_files = set()
+
+        if not src.is_file():
+            cm.die(src)
+
+        prev_files = set(os.listdir(tmpdir))
+        cmd = [flang_fc1, *flang_fc_args, flang_fc1_options, str(src)]
+        proc = subprocess.check_output(cmd, stderr=subprocess.PIPE,
+                                       universal_newlines=True, cwd=tmpdir)
+        actual_files = set(os.listdir(tmpdir)).
diff erence(prev_files)
+
+        # The first 3 bytes of the files are an UTF-8 BOM
+        with open(src, 'r', encoding="utf-8", errors="strict") as f:
+            for line in f:
+                m = re.search(r"^!Expect: (.*)", line)
+                if m:
+                    expected_files.add(m.group(1))
+
+        extra_files = actual_files.
diff erence(expected_files)
+        if extra_files:
+            print(f"Unexpected .mod files produced: {extra_files}")
+            sys.exit(1)
+
+        for mod in expected_files:
+            mod = Path(tmpdir).joinpath(mod)
+            if not mod.is_file():
+                print(f"Compilation did not produce expected mod file: {mod}")
+                sys.exit(1)
+            with open(mod, 'r', encoding="utf-8", errors="strict") as f:
+                for line in f:
+                    if "!mod$" in line:
+                        continue
+                    actual += line
+
+            with open(src, 'r', encoding="utf-8", errors="strict") as f:
+                for line in f:
+                    if f"!Expect: {mod.name}" in line:
+                        for line in f:
+                            if re.match(r"^$", line):
+                                break
+                            m = re.sub(r"^!", "", line.lstrip())
+                            expect += m
+
+            
diff s = "\n".join(unified_
diff (actual.replace(" ", "").split("\n"),
+                                           expect.replace(" ", "").split("\n"),
+                                           fromfile=mod.name, tofile="Expect", n=999999))
+
+            if 
diff s != "":
+                print(
diff s)
+                print()
+                print("FAIL")
+                sys.exit(1)
+
+print()
+print("PASS")
+

diff  --git a/flang/test/Semantics/test_modfile.sh b/flang/test/Semantics/test_modfile.sh
deleted file mode 100755
index f52452030d663..0000000000000
--- a/flang/test/Semantics/test_modfile.sh
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/bin/env bash
-# Compile a source file and compare generated .mod files against expected.
-
-set -e
-FLANG_FC1_OPTIONS="-fsyntax-only"
-srcdir=$(dirname $0)
-source $srcdir/common.sh
-
-actual=$temp/actual.mod
-expect=$temp/expect.mod
-actual_files=$temp/actual_files
-prev_files=$temp/prev_files
-
diff s=$temp/
diff s
-
-set $src
-
-touch $actual
-for src in "$@"; do
-  [[ ! -f $src ]] && echo "File not found: $src" && exit 1
-  path=$(git ls-files --full-name $src 2>/dev/null || echo $src)
-  (
-    cd $temp
-    ls -1 *.mod > prev_files
-    $FLANG_FC1 $FLANG_FC1_OPTIONS $src
-    ls -1 *.mod | comm -13 prev_files -
-  ) > $actual_files
-  expected_files=$(sed -n 's/^!Expect: \(.*\)/\1/p' $src | sort)
-  extra_files=$(echo "$expected_files" | comm -23 $actual_files -)
-  if [[ ! -z "$extra_files" ]]; then
-    echo "Unexpected .mod files produced:" $extra_files
-    die FAIL $path
-  fi
-  for mod in $expected_files; do
-    if [[ ! -f $temp/$mod ]]; then
-      echo "Compilation did not produce expected mod file: $mod"
-      die FAIL $path
-    fi
-    # The first three bytes of the file are a UTF-8 BOM
-    sed '/^[^!]*!mod\$/d' $temp/$mod > $actual
-    sed '1,/^!Expect: '"$mod"'/d' $src | sed -e '/^$/,$d' -e 's/^!//' > $expect
-    if ! 
diff  -w -U999999 $expect $actual > $
diff s; then
-      echo "Module file $mod 
diff ers from expected:"
-      sed '1,2d' $
diff s
-      die FAIL $path
-    fi
-  done
-  rm -f $actual $expect
-done
-echo PASS


        


More information about the flang-commits mailing list