From 1720cccb17a4ac68c3ce66aee85ea443e960eacb Mon Sep 17 00:00:00 2001 From: r-plus Date: Tue, 20 Apr 2021 07:20:11 +0900 Subject: [PATCH 1/5] ci: xcode preference phase --- .github/workflows/main.yml | 3 +++ Tools/add_plugin_filed_to_preference.sh | 4 ++++ 2 files changed, 7 insertions(+) create mode 100755 Tools/add_plugin_filed_to_preference.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 08c8f630..605d0d56 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,4 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 + - run: | + ./Tools/add_plugin_filed_to_preference.sh + defaults read com.apple.dt.Xcode - run: make diff --git a/Tools/add_plugin_filed_to_preference.sh b/Tools/add_plugin_filed_to_preference.sh new file mode 100755 index 00000000..1876d55f --- /dev/null +++ b/Tools/add_plugin_filed_to_preference.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +XCODE_VERSION=$(xcodebuild -version | head -1 | cut -f2 -d" ") +defaults write com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-${XCODE_VERSION} '{ allowed = { "net.JugglerShu.XVim2" = { version = 1; }; }; skipped = {}; }' From b5cc3b68f6c8a634fd08bfd5d45b77f337022427 Mon Sep 17 00:00:00 2001 From: r-plus Date: Tue, 20 Apr 2021 07:34:59 +0900 Subject: [PATCH 2/5] ci: codesign phase --- .github/workflows/main.yml | 7 +++++++ Tools/cert.config | 27 +++++++++++++++++++++++++++ Tools/create_cert.sh | 5 +++++ 3 files changed, 39 insertions(+) create mode 100644 Tools/cert.config create mode 100755 Tools/create_cert.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 605d0d56..639bcd33 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,6 +9,13 @@ jobs: steps: - uses: actions/checkout@v2 + - run: | + #./Tools/create_cert.sh + XCODE_PATH=$(xcode-select -p) + codesign -dvvv ${XCODE_PATH%%/Contents*} + #sudo codesign -f -s XcodeSigner ${XCODE_PATH%%/Contents*} & + sudo codesign --remove-signature ${XCODE_PATH%%/Contents*} + codesign -dvvv ${XCODE_PATH%%/Contents*} || true - run: | ./Tools/add_plugin_filed_to_preference.sh defaults read com.apple.dt.Xcode diff --git a/Tools/cert.config b/Tools/cert.config new file mode 100644 index 00000000..c5abf97f --- /dev/null +++ b/Tools/cert.config @@ -0,0 +1,27 @@ +[ ca ] + +default_ca = CA_default + +[ req ] + +distinguished_name = req_distinguished_name + +x509_extensions = v3_ca + +#req_extensions = v3_req + +[req_distinguished_name ] + +CN = XcodeSigner + +[ CA_default ] + +x509_extensions = usr_cert + +[ usr_cert ] + +[ v3_ca ] + +keyUsage = critical, digitalSignature + +extendedKeyUsage = critical, codeSigning diff --git a/Tools/create_cert.sh b/Tools/create_cert.sh new file mode 100755 index 00000000..261e13de --- /dev/null +++ b/Tools/create_cert.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +openssl req -subj '/CN=XcodeSigner' -config ./Tools/cert.config -x509 -newkey rsa:2046 -keyout selfSignedKey.pem -out selfSigned.pem -days 365 -passout pass:"foobar" +openssl pkcs12 -export -out XcodeSigner.p12 -inkey selfSignedKey.pem -in selfSigned.pem -passin pass:"foobar" -passout pass:"foobar" +security import XcodeSigner.p12 -P foobar From 3bf8eea8cc9033b10a40579f4cbc5802c3c6823d Mon Sep 17 00:00:00 2001 From: r-plus Date: Wed, 21 Apr 2021 01:12:56 +0900 Subject: [PATCH 3/5] ci: run unit test --- .github/workflows/main.yml | 29 ++++++++++++++++++++++++----- Makefile | 2 ++ XVim2/Helper/Logger.h | 7 +++++++ XVim2/UnitTest/XVimTestCase.m | 1 + XVim2/UnitTest/XVimTester.m | 16 ++++++++++++++++ XVim2/XVim/XVim.m | 7 +++++++ 6 files changed, 57 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 639bcd33..fbfbba2c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,14 +9,33 @@ jobs: steps: - uses: actions/checkout@v2 - - run: | - #./Tools/create_cert.sh + - name: Build XVim with UNIT_TEST flag + run: make unit-test + - name: Remove codesign + run: | XCODE_PATH=$(xcode-select -p) codesign -dvvv ${XCODE_PATH%%/Contents*} - #sudo codesign -f -s XcodeSigner ${XCODE_PATH%%/Contents*} & sudo codesign --remove-signature ${XCODE_PATH%%/Contents*} codesign -dvvv ${XCODE_PATH%%/Contents*} || true - - run: | + - name: Register XVim as lodable plugin + run: | ./Tools/add_plugin_filed_to_preference.sh defaults read com.apple.dt.Xcode - - run: make + - name: Run unit test + timeout-minutes: 5 + run: | + echo "set debug" > ~/.xvimrc + touch ~/.xvimlog + XCODE_PATH=$(xcode-select -p) + open -a ${XCODE_PATH%%/Contents*} XVim2.xcodeproj + tail -f ~/.xvimlog & + while : + do + result=$(grep "unit test finished" ~/.xvimlog || true) + if [ -n "${result}" ]; then + # automatically exit non-zero if grep exit code is non-zero by -e option of running shell + grep "^0 Failing Tests$" ~/.xvimlog > /dev/null 2>&1 + exit 0 + fi + sleep 1 + done diff --git a/Makefile b/Makefile index 6ec9bf81..0bea83e6 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,8 @@ release: uuid debug: uuid $(xcodebuild) Debug $(REDIRECT) +unit-test: + $(xcodebuild) Release GCC_PREPROCESSOR_DEFINITIONS=UNIT_TEST=1 $(REDIRECT) clean: clean-release clean-debug diff --git a/XVim2/Helper/Logger.h b/XVim2/Helper/Logger.h index 6ba89101..a05a347d 100644 --- a/XVim2/Helper/Logger.h +++ b/XVim2/Helper/Logger.h @@ -23,6 +23,13 @@ #define ERROR_LOG(fmt, ...) #endif +#if defined UNIT_TEST +#define UNIT_TEST_LOG(fmt, ...) \ +[Logger logWithLevel:LogDebug format:@"%s:%d " fmt, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__] +#else +#define UNIT_TEST_LOG(fmt, ...) +#endif + typedef NS_ENUM(NSInteger, LogLevel) { LogDebug, LogError, diff --git a/XVim2/UnitTest/XVimTestCase.m b/XVim2/UnitTest/XVimTestCase.m index a5b1af09..298f8e01 100644 --- a/XVim2/UnitTest/XVimTestCase.m +++ b/XVim2/UnitTest/XVimTestCase.m @@ -178,6 +178,7 @@ - (void)waitForCompletionWithConinuation:(void(^)(void))continuation - (void)runInWindow:(NSWindow*)window withContinuation:(void(^)(void))continuation { + UNIT_TEST_LOG(@"testing case: %@", self.desc); self.window = window; [self setUp]; diff --git a/XVim2/UnitTest/XVimTester.m b/XVim2/UnitTest/XVimTester.m index 91728f3c..86aac688 100644 --- a/XVim2/UnitTest/XVimTester.m +++ b/XVim2/UnitTest/XVimTester.m @@ -156,6 +156,7 @@ - (void)runTest id lastActiveWorkspace = [(IDEWorkspaceTabController*)XVimLastActiveWorkspaceTabController() workspace]; if (lastActiveWorkspace == nil) { NSBeep(); + UNIT_TEST_LOG(@"Fail to open xvimtest.cpp"); return; } IDEEditorOpenSpecifier* spec = @@ -190,6 +191,21 @@ -(void)runNextTest [self.testWindow performClose:self]; [self showResultsTable]; [self dump]; +#if defined UNIT_TEST + for (XVimTestCase *tc in self.testCases) { + if (!tc.success) { + UNIT_TEST_LOG(@"[Description] %@, [Pass/Fail] %@, [Message] %@, [Expected] %@, [Actual] %@", + tc.desc, + tc.resultDescription, + tc.message, + [NSString stringWithFormat:@"'%@'", [tc.expectedText escapedString]], + [NSString stringWithFormat:@"'%@'", [tc.actualText escapedString]] + ); + } + } + UNIT_TEST_LOG(@"%@", [resultsString stringValue]); + UNIT_TEST_LOG(@"unit test finished"); +#endif return; } diff --git a/XVim2/XVim/XVim.m b/XVim2/XVim/XVim.m index 0a37a920..0c1e72c0 100644 --- a/XVim2/XVim/XVim.m +++ b/XVim2/XVim/XVim.m @@ -354,6 +354,13 @@ - (NSMenuItem*)xvimMenuItem } [m addItem:subm]; [subm setSubmenu:cat_menu]; + +#if defined UNIT_TEST + NSMenuItem *testItem = [[NSMenuItem alloc] init]; + testItem.title = @"All"; + [XVim.instance performSelector:@selector(runTest:) withObject:testItem afterDelay:10.0]; + UNIT_TEST_LOG(@"did performSelector."); +#endif } return item; From a7e010851a3a9217ffb516d5d5e6ea22902e1772 Mon Sep 17 00:00:00 2001 From: r-plus Date: Wed, 21 Apr 2021 12:37:07 +0900 Subject: [PATCH 4/5] ci: try to fail unit test --- XVim2/UnitTest/XVimTester+Operator.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XVim2/UnitTest/XVimTester+Operator.m b/XVim2/UnitTest/XVimTester+Operator.m index a93a2c18..5f7f8630 100644 --- a/XVim2/UnitTest/XVimTester+Operator.m +++ b/XVim2/UnitTest/XVimTester+Operator.m @@ -406,7 +406,7 @@ - (NSArray*)operator_testcases @" ccc\n" // 16 @" ddd\n" // 28 @" eee\n" // 38 - @" fff"; // 46 + @" ffftest"; // 46 static NSString* lshift_result5_2 = @"\taaa\n" @"\tbbb\n"; From 60206efee67e0345e19902b756c159ea6c6d2dc3 Mon Sep 17 00:00:00 2001 From: r-plus Date: Wed, 21 Apr 2021 12:42:04 +0900 Subject: [PATCH 5/5] Revert "ci: try to fail unit test" This reverts commit a7e010851a3a9217ffb516d5d5e6ea22902e1772. --- XVim2/UnitTest/XVimTester+Operator.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XVim2/UnitTest/XVimTester+Operator.m b/XVim2/UnitTest/XVimTester+Operator.m index 5f7f8630..a93a2c18 100644 --- a/XVim2/UnitTest/XVimTester+Operator.m +++ b/XVim2/UnitTest/XVimTester+Operator.m @@ -406,7 +406,7 @@ - (NSArray*)operator_testcases @" ccc\n" // 16 @" ddd\n" // 28 @" eee\n" // 38 - @" ffftest"; // 46 + @" fff"; // 46 static NSString* lshift_result5_2 = @"\taaa\n" @"\tbbb\n";