-
Notifications
You must be signed in to change notification settings - Fork 1
Start Data Connect Tools from Xcode #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c56c578
Start Data Connect Tools from Xcode
aashishpatil-g 9c22608
Style fixes
aashishpatil-g 28f4dac
Update Readme
aashishpatil-g 1af25f4
Fix whitespace
aashishpatil-g d32bb57
Readme fixes
aashishpatil-g 4b1e1d8
Readme fixes
aashishpatil-g d59c2cd
Restrict Test to macos
aashishpatil-g ab9dfa5
whitespace fix
aashishpatil-g 59e0baa
Conditional compilation for macOS specific targets
aashishpatil-g e7d5b0d
Nick feedback.
aashishpatil-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // 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. | ||
|
|
||
| import XCTest | ||
|
|
||
| #if os(macOS) | ||
| @testable import ShellExecutor | ||
|
|
||
| @available(macOS 12.0, *) | ||
| final class ShellExecutorTests: XCTestCase { | ||
| var executor: ShellExecutor! | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
| // This is run before each test | ||
| executor = ShellExecutor() | ||
| } | ||
|
|
||
| /// Tests that a simple, successful command completes without throwing a Swift error. | ||
| func testSuccessfulCommand() { | ||
| // The `true` command does nothing and exits with status 0. | ||
| XCTAssertNoThrow( | ||
| try executor.run("true"), | ||
| "A successful command should not throw an error." | ||
| ) | ||
| } | ||
|
|
||
| /// Tests that a failing command completes without throwing a Swift error, | ||
| /// as our function handles the non-zero exit code internally. | ||
| func testFailingCommand() { | ||
| // The `false` command does nothing and exits with status 1. | ||
| XCTAssertNoThrow( | ||
| try executor.run("false"), | ||
| "A failing command should be handled gracefully, not throw." | ||
| ) | ||
| } | ||
|
|
||
| /// Tests if the standard output from the command is correctly captured and printed. | ||
| func testStandardOutputCapture() throws { | ||
| let testString = "Hello from XCTest!" | ||
| let command = "echo '\(testString)'" | ||
|
|
||
| // We need to capture the process's stdout to verify it. | ||
| // This is a common pattern for testing command-line output. | ||
| let outputPipe = Pipe() | ||
|
|
||
| // Save the original standard output file handle | ||
| let originalStdout = dup(STDOUT_FILENO) | ||
|
|
||
| // Redirect stdout to our pipe's write end | ||
| dup2(outputPipe.fileHandleForWriting.fileDescriptor, STDOUT_FILENO) | ||
|
|
||
| // Run the command. Its output will go into the pipe. | ||
| try executor.run(command) | ||
|
|
||
| // Close the write end of the pipe to signal end-of-file | ||
| try outputPipe.fileHandleForWriting.close() | ||
|
|
||
| // Restore the original standard output | ||
| dup2(originalStdout, STDOUT_FILENO) | ||
| close(originalStdout) | ||
|
|
||
| // Read all data from the pipe | ||
| let capturedData = outputPipe.fileHandleForReading.readDataToEndOfFile() | ||
| let capturedOutput = String(data: capturedData, encoding: .utf8) ?? "" | ||
|
|
||
| XCTAssertTrue( | ||
| capturedOutput.contains(testString), | ||
| "The captured output should contain the test string '\(testString)'" | ||
| ) | ||
|
|
||
| XCTAssertTrue( | ||
| capturedOutput.contains("✅ ShellExecutor: Command finished successfully."), | ||
| "The output should contain the success message." | ||
| ) | ||
| } | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // 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. | ||
|
|
||
| import Foundation | ||
|
|
||
| import ShellExecutor | ||
|
|
||
| // port on which FDC tools (code-server) listen | ||
| let FDC_TOOLS_PORT: UInt = 9394 | ||
|
|
||
| @available(macOS 12.0, *) | ||
| @main | ||
| struct SetupDevEnv { | ||
| static func main() { | ||
| #if os(macOS) | ||
| let currentDirectoryPath = FileManager.default.currentDirectoryPath | ||
| print("Attempting to start Data Connect Tools in Directory: \(currentDirectoryPath)") | ||
|
|
||
| let executor = ShellExecutor() | ||
|
|
||
| do { | ||
| // When the `Start FDC Tools` process is stopped from Xcode, | ||
| // it still leaves an orphaned code-server process since SIGKILL isn't received by the | ||
| // command line utility | ||
| try executor.killProcessOnPort(FDC_TOOLS_PORT) | ||
| } catch { | ||
| print("❌ Error killing process \(error)") | ||
| } | ||
|
|
||
| do { | ||
| let commandToRun = "curl -sL https://firebase.tools/dataconnect | bash" | ||
| try executor.run(commandToRun) | ||
| } catch { | ||
| print("❌ Error running command: \(error)") | ||
| } | ||
| #endif // if macos | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.