@@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
5
5
use std:: { env, fs} ;
6
6
7
7
use build_helper:: ci:: CiEnv ;
8
+ use build_helper:: git:: PathFreshness ;
8
9
use clap:: CommandFactory ;
9
10
use serde:: Deserialize ;
10
11
@@ -15,6 +16,7 @@ use crate::core::build_steps::clippy::{LintConfig, get_clippy_rules_in_order};
15
16
use crate :: core:: build_steps:: llvm;
16
17
use crate :: core:: build_steps:: llvm:: LLVM_INVALIDATION_PATHS ;
17
18
use crate :: core:: config:: { LldMode , Target , TargetSelection , TomlConfig } ;
19
+ use crate :: utils:: tests:: git:: git_test;
18
20
19
21
pub ( crate ) fn parse ( config : & str ) -> Config {
20
22
Config :: parse_inner (
@@ -744,3 +746,171 @@ fn test_include_precedence_over_profile() {
744
746
// override profile settings, so we expect this to be "dev" here.
745
747
assert_eq ! ( config. channel, "dev" ) ;
746
748
}
749
+
750
+ #[ test]
751
+ fn test_pr_ci_unchanged_anywhere ( ) {
752
+ git_test ( |ctx| {
753
+ let sha = ctx. create_upstream_merge ( & [ "a" ] ) ;
754
+ ctx. create_nonupstream_merge ( & [ "b" ] ) ;
755
+ let src = ctx. check_modifications ( & [ "c" ] , CiEnv :: GitHubActions ) ;
756
+ assert_eq ! ( src, PathFreshness :: LastModifiedUpstream { upstream: sha } ) ;
757
+ } ) ;
758
+ }
759
+
760
+ #[ test]
761
+ fn test_pr_ci_changed_in_pr ( ) {
762
+ git_test ( |ctx| {
763
+ let sha = ctx. create_upstream_merge ( & [ "a" ] ) ;
764
+ ctx. create_nonupstream_merge ( & [ "b" ] ) ;
765
+ let src = ctx. check_modifications ( & [ "b" ] , CiEnv :: GitHubActions ) ;
766
+ assert_eq ! ( src, PathFreshness :: HasLocalModifications { upstream: sha } ) ;
767
+ } ) ;
768
+ }
769
+
770
+ #[ test]
771
+ fn test_auto_ci_unchanged_anywhere_select_parent ( ) {
772
+ git_test ( |ctx| {
773
+ let sha = ctx. create_upstream_merge ( & [ "a" ] ) ;
774
+ ctx. create_upstream_merge ( & [ "b" ] ) ;
775
+ let src = ctx. check_modifications ( & [ "c" ] , CiEnv :: GitHubActions ) ;
776
+ assert_eq ! ( src, PathFreshness :: LastModifiedUpstream { upstream: sha } ) ;
777
+ } ) ;
778
+ }
779
+
780
+ #[ test]
781
+ fn test_auto_ci_changed_in_pr ( ) {
782
+ git_test ( |ctx| {
783
+ let sha = ctx. create_upstream_merge ( & [ "a" ] ) ;
784
+ ctx. create_upstream_merge ( & [ "b" , "c" ] ) ;
785
+ let src = ctx. check_modifications ( & [ "c" , "d" ] , CiEnv :: GitHubActions ) ;
786
+ assert_eq ! ( src, PathFreshness :: HasLocalModifications { upstream: sha } ) ;
787
+ } ) ;
788
+ }
789
+
790
+ #[ test]
791
+ fn test_local_uncommitted_modifications ( ) {
792
+ git_test ( |ctx| {
793
+ let sha = ctx. create_upstream_merge ( & [ "a" ] ) ;
794
+ ctx. create_branch ( "feature" ) ;
795
+ ctx. modify ( "a" ) ;
796
+
797
+ assert_eq ! (
798
+ ctx. check_modifications( & [ "a" , "d" ] , CiEnv :: None ) ,
799
+ PathFreshness :: HasLocalModifications { upstream: sha }
800
+ ) ;
801
+ } ) ;
802
+ }
803
+
804
+ #[ test]
805
+ fn test_local_committed_modifications ( ) {
806
+ git_test ( |ctx| {
807
+ let sha = ctx. create_upstream_merge ( & [ "a" ] ) ;
808
+ ctx. create_upstream_merge ( & [ "b" , "c" ] ) ;
809
+ ctx. create_branch ( "feature" ) ;
810
+ ctx. modify ( "x" ) ;
811
+ ctx. commit ( ) ;
812
+ ctx. modify ( "a" ) ;
813
+ ctx. commit ( ) ;
814
+
815
+ assert_eq ! (
816
+ ctx. check_modifications( & [ "a" , "d" ] , CiEnv :: None ) ,
817
+ PathFreshness :: HasLocalModifications { upstream: sha }
818
+ ) ;
819
+ } ) ;
820
+ }
821
+
822
+ #[ test]
823
+ fn test_local_committed_modifications_subdirectory ( ) {
824
+ git_test ( |ctx| {
825
+ let sha = ctx. create_upstream_merge ( & [ "a/b/c" ] ) ;
826
+ ctx. create_upstream_merge ( & [ "b" , "c" ] ) ;
827
+ ctx. create_branch ( "feature" ) ;
828
+ ctx. modify ( "a/b/d" ) ;
829
+ ctx. commit ( ) ;
830
+
831
+ assert_eq ! (
832
+ ctx. check_modifications( & [ "a/b" ] , CiEnv :: None ) ,
833
+ PathFreshness :: HasLocalModifications { upstream: sha }
834
+ ) ;
835
+ } ) ;
836
+ }
837
+
838
+ #[ test]
839
+ fn test_local_changes_in_head_upstream ( ) {
840
+ git_test ( |ctx| {
841
+ // We want to resolve to the upstream commit that made modifications to a,
842
+ // even if it is currently HEAD
843
+ let sha = ctx. create_upstream_merge ( & [ "a" ] ) ;
844
+ assert_eq ! (
845
+ ctx. check_modifications( & [ "a" , "d" ] , CiEnv :: None ) ,
846
+ PathFreshness :: LastModifiedUpstream { upstream: sha }
847
+ ) ;
848
+ } ) ;
849
+ }
850
+
851
+ #[ test]
852
+ fn test_local_changes_in_previous_upstream ( ) {
853
+ git_test ( |ctx| {
854
+ // We want to resolve to this commit, which modified a
855
+ let sha = ctx. create_upstream_merge ( & [ "a" , "e" ] ) ;
856
+ // Not to this commit, which is the latest upstream commit
857
+ ctx. create_upstream_merge ( & [ "b" , "c" ] ) ;
858
+ ctx. create_branch ( "feature" ) ;
859
+ ctx. modify ( "d" ) ;
860
+ ctx. commit ( ) ;
861
+ assert_eq ! (
862
+ ctx. check_modifications( & [ "a" ] , CiEnv :: None ) ,
863
+ PathFreshness :: LastModifiedUpstream { upstream: sha }
864
+ ) ;
865
+ } ) ;
866
+ }
867
+
868
+ #[ test]
869
+ fn test_local_no_upstream_commit_with_changes ( ) {
870
+ git_test ( |ctx| {
871
+ ctx. create_upstream_merge ( & [ "a" , "e" ] ) ;
872
+ ctx. create_upstream_merge ( & [ "a" , "e" ] ) ;
873
+ // We want to fall back to this commit, because there are no commits
874
+ // that modified `x`.
875
+ let sha = ctx. create_upstream_merge ( & [ "a" , "e" ] ) ;
876
+ ctx. create_branch ( "feature" ) ;
877
+ ctx. modify ( "d" ) ;
878
+ ctx. commit ( ) ;
879
+ assert_eq ! (
880
+ ctx. check_modifications( & [ "x" ] , CiEnv :: None ) ,
881
+ PathFreshness :: LastModifiedUpstream { upstream: sha }
882
+ ) ;
883
+ } ) ;
884
+ }
885
+
886
+ #[ test]
887
+ fn test_local_no_upstream_commit ( ) {
888
+ git_test ( |ctx| {
889
+ let src = ctx. check_modifications ( & [ "c" , "d" ] , CiEnv :: None ) ;
890
+ assert_eq ! ( src, PathFreshness :: MissingUpstream ) ;
891
+ } ) ;
892
+ }
893
+
894
+ #[ test]
895
+ fn test_local_changes_negative_path ( ) {
896
+ git_test ( |ctx| {
897
+ let upstream = ctx. create_upstream_merge ( & [ "a" ] ) ;
898
+ ctx. create_branch ( "feature" ) ;
899
+ ctx. modify ( "b" ) ;
900
+ ctx. modify ( "d" ) ;
901
+ ctx. commit ( ) ;
902
+
903
+ assert_eq ! (
904
+ ctx. check_modifications( & [ ":!b" , ":!d" ] , CiEnv :: None ) ,
905
+ PathFreshness :: LastModifiedUpstream { upstream: upstream. clone( ) }
906
+ ) ;
907
+ assert_eq ! (
908
+ ctx. check_modifications( & [ ":!c" ] , CiEnv :: None ) ,
909
+ PathFreshness :: HasLocalModifications { upstream: upstream. clone( ) }
910
+ ) ;
911
+ assert_eq ! (
912
+ ctx. check_modifications( & [ ":!d" , ":!x" ] , CiEnv :: None ) ,
913
+ PathFreshness :: HasLocalModifications { upstream }
914
+ ) ;
915
+ } ) ;
916
+ }
0 commit comments