Skip to content

Commit

Permalink
[swift] Infrastructure for frontend tests
Browse files Browse the repository at this point in the history
Summary: Setting up the framework for frontend tests for Swift

Reviewed By: ngorogiannis

Differential Revision: D68568005

fbshipit-source-id: f37ff00b045b6d13d0fd108bd038eb44bebe1675
  • Loading branch information
dulmarod authored and facebook-github-bot committed Jan 28, 2025
1 parent 7355d12 commit 5c9d100
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ _build_infer
*.exp.test*
*.dot.test
*.test.dot
*.test.sil
*.test.txt
duplicates.txt
*.ast.sh
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ endif
endif # HAS_OBJC
endif # BUILD_C_ANALYZERS

ifneq ($(BUILD_SWIFT_ANALYZERS),no)
DIRECT_TESTS += \
swift_frontend \

endif

ifeq ($(BUILD_ERLANG_ANALYZERS),yes)
ifneq ($(ERLC),no)
ifneq ($(ESCRIPT),no)
Expand Down
2 changes: 2 additions & 0 deletions Makefile.config
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ CLANG_DEPS_NO_MODELS := $(INFER_BIN)

CLANG_DEPS := $(CLANG_DEPS_NO_MODELS) $(MODELS_RESULTS_FILE)

SWIFT_DEPS := $(INFER_BIN)

XCODE_ISYSROOT_SUFFIX := Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
ifeq ($(wildcard $(XCODE_BASE)/$(XCODE_ISYSROOT_SUFFIX)),)
XCODE_ISYSROOT_SUFFIX := SDKs/MacOSX.sdk
Expand Down
12 changes: 6 additions & 6 deletions infer/src/integration/Driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type mode =
| Python of {prog: string; args: string list}
| PythonBytecode of {files: string list}
| Rebar3 of {args: string list}
| Swiftc of {args: string list}
| Swiftc of {prog: string; args: string list}
| Textual of {textualfiles: string list}
| XcodeBuild of {prog: string; args: string list}
| XcodeXcpretty of {prog: string; args: string list}
Expand Down Expand Up @@ -94,8 +94,8 @@ let pp_mode fmt = function
F.fprintf fmt "Python driver mode:@\nfiles = '%a'" Pp.cli_args files
| Rebar3 {args} ->
F.fprintf fmt "Rebar3 driver mode:@\nargs = %a" Pp.cli_args args
| Swiftc {args} ->
F.fprintf fmt "Swift driver mode:@\nargs = %a" Pp.cli_args args
| Swiftc {prog; args} ->
F.fprintf fmt "Swift driver mode:@\nprog = '%s' args = %a" prog Pp.cli_args args
| Erlc {args} ->
F.fprintf fmt "Erlc driver mode:@\nargs = %a" Pp.cli_args args
| Hackc {prog; args} ->
Expand Down Expand Up @@ -218,9 +218,9 @@ let capture ~changed_files mode =
| Rebar3 {args} ->
L.progress "Capturing in rebar3 mode...@." ;
Erlang.capture ~command:"rebar3" ~args
| Swiftc {args} ->
| Swiftc {prog; args} ->
L.progress "Capturing in swift mode...@." ;
Swift.capture ~command:"swiftc" ~args
Swift.capture ~command:prog ~args
| Erlc {args} ->
L.progress "Capturing in erlc mode...@." ;
Erlang.capture ~command:"erlc" ~args
Expand Down Expand Up @@ -560,7 +560,7 @@ let mode_of_build_command build_cmd (buck_mode : BuckMode.t option) =
| BRebar3 ->
Rebar3 {args}
| BSwiftc ->
Swiftc {args}
Swiftc {prog; args}
| BErlc ->
Erlc {args}
| BHackc ->
Expand Down
2 changes: 1 addition & 1 deletion infer/src/integration/Driver.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type mode =
| Python of {prog: string; args: string list}
| PythonBytecode of {files: string list}
| Rebar3 of {args: string list}
| Swiftc of {args: string list}
| Swiftc of {prog: string; args: string list}
| Textual of {textualfiles: string list}
| XcodeBuild of {prog: string; args: string list}
| XcodeXcpretty of {prog: string; args: string list}
Expand Down
4 changes: 2 additions & 2 deletions infer/src/textual/TextualSil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1310,10 +1310,10 @@ let module_to_sil lang module_ decls_env =
let pp_copyright fmt =
F.fprintf fmt "// \n" ;
F.fprintf fmt "// Copyright (c) Facebook, Inc. and its affiliates.\n" ;
F.fprintf fmt "// \n" ;
F.fprintf fmt "//\n" ;
F.fprintf fmt "// This source code is licensed under the MIT license found in the\n" ;
F.fprintf fmt "// LICENSE file in the root directory of this source tree.\n" ;
F.fprintf fmt "//\n\n"
F.fprintf fmt "\n"


let from_java ~filename tenv cfg =
Expand Down
2 changes: 1 addition & 1 deletion infer/tests/codetoanalyze/java/sil/issues.exp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Array.sil, line 36, column 6: textual type error: expression n4 has type *int[][], while a subtype of *(*int[])[] was expected
Array.sil, line 35, column 6: textual type error: expression n4 has type *int[][], while a subtype of *(*int[])[] was expected
45 changes: 45 additions & 0 deletions infer/tests/codetoanalyze/swift/frontend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

TESTS_DIR=../../..

SWIFT_OPTIONS =
INFER_OPTIONS =

SOURCES = $(wildcard *.swift)

CLEAN_EXTRA = $(foreach source,$(SOURCES),$(basename $(notdir $(source))).o)

include $(TESTS_DIR)/base.make
include $(TESTS_DIR)/swift-base.make

default: test

%.test.sil: %.swift $(SWIFT_DEPS) $(HEADERS)
$(QUIET)$(call silent_on_success,Testing the infer/swift frontend in $(TEST_REL_DIR),\
$(INFER_BIN) capture --frontend-tests --dump-textual --project-root $(TESTS_DIR) $(INFER_OPTIONS) -- \
$(SWIFTC) $(SWIFT_OPTIONS) $<)

capture: $(SOURCES:.swift=.test.sil)

.PHONY: print
print: capture

.PHONY: test
test: capture
$(QUIET)error=0; for file in $(SOURCES) ; do \
diff -u "$$file.sil" "$$file.test.sil" || error=1 ; \
done ; \
if [ $$error = 1 ]; then exit 1; fi

.PHONY: replace
replace: capture
$(QUIET)for file in $(SOURCES) ; do \
mv $$file.test.sil $$file.sil ; \
done

.PHONY: clean
clean:
$(REMOVE_DIR) infer-out */*.test.sil */*/*.test.sil $(CLEAN_EXTRA)
4 changes: 4 additions & 0 deletions infer/tests/codetoanalyze/swift/frontend/hello.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
func main() {
print("Hello, World!")
}

6 changes: 6 additions & 0 deletions infer/tests/codetoanalyze/swift/frontend/hello.swift.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

7 changes: 7 additions & 0 deletions infer/tests/swift-base.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

%.o: %.swift
$(SWIFTC) $(SWIFT_OPTIONS) -o $@ $<

0 comments on commit 5c9d100

Please sign in to comment.