Skip to content

Commit

Permalink
ci: run unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
r-plus committed Apr 21, 2021
1 parent b5cc3b6 commit 3bf8eea
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
29 changes: 24 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions XVim2/Helper/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions XVim2/UnitTest/XVimTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
16 changes: 16 additions & 0 deletions XVim2/UnitTest/XVimTester.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions XVim2/XVim/XVim.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3bf8eea

Please sign in to comment.